From 8324b683b4e557e6c5c9d572d01f933b3e074185 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 20 Mar 2015 13:22:01 +0100 Subject: using robertkrimen/otto, godeps updated --- rpc/jeth.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'rpc') diff --git a/rpc/jeth.go b/rpc/jeth.go index 11d4599c9..4e83be8a6 100644 --- a/rpc/jeth.go +++ b/rpc/jeth.go @@ -3,22 +3,29 @@ package rpc import ( "encoding/json" // "fmt" - "github.com/obscuren/otto" + "github.com/ethereum/go-ethereum/jsre" + "github.com/robertkrimen/otto" ) type Jeth struct { ethApi *EthereumApi toVal func(interface{}) otto.Value + re *jsre.JSRE } -func NewJeth(ethApi *EthereumApi, toVal func(interface{}) otto.Value) *Jeth { - return &Jeth{ethApi, toVal} +func NewJeth(ethApi *EthereumApi, toVal func(interface{}) otto.Value, re *jsre.JSRE) *Jeth { + return &Jeth{ethApi, toVal, re} } -func (self *Jeth) err(code int, msg string, id interface{}) otto.Value { +func (self *Jeth) err(code int, msg string, id interface{}) (response otto.Value) { rpcerr := &RpcErrorObject{code, msg} - rpcresponse := &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: rpcerr} - return self.toVal(rpcresponse) + self.re.Set("ret_jsonrpc", jsonrpcver) + self.re.Set("ret_id", id) + self.re.Set("ret_error", rpcerr) + response, _ = self.re.Run(` + ret_response = { jsonrpc: ret_jsonrpc, id: ret_id, error: ret_error }; + `) + return } func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) { @@ -37,7 +44,11 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) { if err != nil { return self.err(-32603, err.Error(), req.Id) } - rpcresponse := &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: req.Id, Result: respif} - response = self.toVal(rpcresponse) + self.re.Set("ret_jsonrpc", jsonrpcver) + self.re.Set("ret_id", req.Id) + self.re.Set("ret_result", respif) + response, err = self.re.Run(` + ret_response = { jsonrpc: ret_jsonrpc, id: ret_id, result: ret_result }; + `) return } -- cgit v1.2.3