aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/jeth.go
diff options
context:
space:
mode:
authorBas van Kervel <basvankervel@ziggo.nl>2015-06-08 18:43:58 +0800
committerBas van Kervel <basvankervel@gmail.com>2015-06-11 20:17:27 +0800
commit1b59f890955c3658516daa958d0e4732004a78b7 (patch)
tree0c9e4feb630f89e07cd1b2fe2be0c26c4894ba16 /rpc/jeth.go
parentbbfa0a3dcb82e704828d1438261ff26c50c4ccc3 (diff)
downloadgo-tangerine-1b59f890955c3658516daa958d0e4732004a78b7.tar.gz
go-tangerine-1b59f890955c3658516daa958d0e4732004a78b7.tar.zst
go-tangerine-1b59f890955c3658516daa958d0e4732004a78b7.zip
added console command
Diffstat (limited to 'rpc/jeth.go')
-rw-r--r--rpc/jeth.go54
1 files changed, 43 insertions, 11 deletions
diff --git a/rpc/jeth.go b/rpc/jeth.go
index e578775bb..d1b36906f 100644
--- a/rpc/jeth.go
+++ b/rpc/jeth.go
@@ -11,6 +11,10 @@ import (
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/robertkrimen/otto"
+ "github.com/ethereum/go-ethereum/rpc/comms"
+ "github.com/ethereum/go-ethereum/rpc/codec"
+ "github.com/ethereum/go-ethereum/rpc/shared"
+ "reflect"
)
type Jeth struct {
@@ -40,6 +44,13 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
return self.err(call, -32700, err.Error(), nil)
}
+ client, err := comms.NewIpcClient(comms.IpcConfig{self.ipcpath}, codec.JSON)
+ if err != nil {
+ fmt.Println("Unable to connect to geth.")
+ return self.err(call, -32603, err.Error(), -1)
+ }
+ defer client.Close()
+
jsonreq, err := json.Marshal(reqif)
var reqs []RpcRequest
batch := true
@@ -54,22 +65,43 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
call.Otto.Run("var ret_response = new Array(response_len);")
for i, req := range reqs {
- var respif interface{}
- err = self.ethApi.GetRequestReply(&req, &respif)
+ err := client.Send(&req)
if err != nil {
- fmt.Println("Error response:", err)
+ fmt.Println("Error send request:", err)
return self.err(call, -32603, err.Error(), req.Id)
}
- call.Otto.Set("ret_jsonrpc", jsonrpcver)
- call.Otto.Set("ret_id", req.Id)
- res, _ := json.Marshal(respif)
+ respif, err := client.Recv()
+ if err != nil {
+ fmt.Println("Error recv response:", err)
+ return self.err(call, -32603, err.Error(), req.Id)
+ }
- call.Otto.Set("ret_result", string(res))
- call.Otto.Set("response_idx", i)
- response, err = call.Otto.Run(`
- ret_response[response_idx] = { jsonrpc: ret_jsonrpc, id: ret_id, result: JSON.parse(ret_result) };
- `)
+ if res, ok := respif.(shared.SuccessResponse); ok {
+ call.Otto.Set("ret_id", res.Id)
+ call.Otto.Set("ret_jsonrpc", res.Jsonrpc)
+ resObj, _ := json.Marshal(res.Result)
+ call.Otto.Set("ret_result", string(resObj))
+ call.Otto.Set("response_idx", i)
+
+ response, err = call.Otto.Run(`
+ ret_response[response_idx] = { jsonrpc: ret_jsonrpc, id: ret_id, result: JSON.parse(ret_result) };
+ `)
+ } else if res, ok := respif.(shared.ErrorResponse); ok {
+ fmt.Printf("Error: %s (%d)\n", res.Error.Message, res.Error.Code)
+
+ call.Otto.Set("ret_id", res.Id)
+ call.Otto.Set("ret_jsonrpc", res.Jsonrpc)
+ call.Otto.Set("ret_error", res.Error)
+ call.Otto.Set("response_idx", i)
+
+ response, _ = call.Otto.Run(`
+ ret_response = { jsonrpc: ret_jsonrpc, id: ret_id, error: ret_error };
+ `)
+ return
+ } else {
+ fmt.Printf("unexpected response\n", reflect.TypeOf(respif))
+ }
}
if !batch {
> * Remove teTeX supportbapt2014-07-231-32/+11 * Switch to texlive by defaultbapt2014-07-231-2/+2 * Handle gbklatex componentbapt2014-07-221-0/+4 * Fix stage violation for ports using USE_TEX=updmapantoine2014-07-211-0/+2 * Support stage for texlive, given it is impossible to rebuild the fmt files intobapt2014-07-051-30/+42 * Use modern LIB_DEPENDSbapt2014-07-031-2/+2 * still more stagingbapt2014-06-281-2/+7 * Use proper TEXMFVARDIRbapt2014-06-281-1/+1 * Yet more stage support for bsd.tex.mkbapt2014-06-281-0/+8 * First bit of staging support for bsd.tex.mkbapt2014-06-281-23/+27 * Convert all :U to :tu and :L to :tlbapt2014-05-051-15/+15 * - Update ls-R after fmtutil.hrs2013-06-081-1/+2 * Eliminate ${SITE_PERL}.hrs2013-06-071-1/+1 * Fix build.hrs2013-06-021-0/+2 * Fix pkg-plist.hrs2013-06-011-4/+1 * - Fix duplicated pkg-plist entries.hrs2013-05-221-6/+11 * Eliminate duplicated entries in PLIST_FILES and PLIST_DIRSTRY.hrs2013-05-221-3/+5 * Add USE_TEX=texhash-bootstrap to fix initial ls-R file catalog generation.hrs2013-05-211-1/+14 * - Fix LIB_DEPENDS when USE_TEX=full.hrs2013-05-151-25/+39 * Rectify USE_TEX to support both of teTeX and TeXLive.hrs2013-05-121-111/+90 * Add dvips dependency to teTeX to fix some broken ports. tetex-dvipsk andhrs2013-05-101-3/+8 * Split off print/tex-dvipsk from print/texlive-base. libpaper supporthrs2013-05-101-4/+3 * Allow USE_TEX=yes.hrs2013-05-101-0/+9 * - Separate print/tex-dvipdfmx from print/texlive-base and add libpaperhrs2013-05-071-10/+9 * - Fix DIST_SUBDIR.hrs2013-05-061-1/+11 * Remove *_DEPENDS from ports which depend on teTeX and add USE_TEX=tetexhrs2013-05-061-1/+2