From a4a4e9fcf824189d8d06940492a01effe6e6cf92 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 17 Jun 2015 16:22:35 +0200 Subject: removed old rpc structure and added new inproc api client --- rpc/comms/inproc.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 rpc/comms/inproc.go (limited to 'rpc/comms/inproc.go') diff --git a/rpc/comms/inproc.go b/rpc/comms/inproc.go new file mode 100644 index 000000000..89cb93cdc --- /dev/null +++ b/rpc/comms/inproc.go @@ -0,0 +1,53 @@ +package comms + +import ( + "github.com/ethereum/go-ethereum/rpc/api" + "github.com/ethereum/go-ethereum/rpc/shared" + "fmt" + "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/xeth" + "github.com/ethereum/go-ethereum/eth" +) + +type InProcClient struct { + api api.EthereumApi + codec codec.Codec + lastId interface{} + lastJsonrpc string + lastErr error + lastRes interface{} +} + +// Create a new in process client +func NewInProcClient(codec codec.Codec) *InProcClient { + return &InProcClient{ + codec: codec, + } +} + +func (self *InProcClient) Close() { + // do nothing +} + +// Need to setup api support +func (self *InProcClient) Initialize(xeth *xeth.XEth, eth *eth.Ethereum) { + if apis, err := api.ParseApiString(api.AllApis, self.codec, xeth, eth); err == nil { + self.api = api.Merge(apis...) + } +} + +func (self *InProcClient) Send(req interface{}) error { + if r, ok := req.(*shared.Request); ok { + self.lastId = r.Id + self.lastJsonrpc = r.Jsonrpc + self.lastRes, self.lastErr = self.api.Execute(r) + return self.lastErr + } + + return fmt.Errorf("Invalid request (%T)", req) +} + +func (self *InProcClient) Recv() (interface{}, error) { + return self.lastRes, self.lastErr + //return *shared.NewRpcResponse(self.lastId, self.lastJsonrpc, self.lastRes, self.lastErr), nil +} -- cgit v1.2.3 From 603192cfa7eb081d9504170677045794cff3b7ab Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Wed, 17 Jun 2015 16:33:34 +0200 Subject: cleanup comments/code --- rpc/comms/inproc.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'rpc/comms/inproc.go') diff --git a/rpc/comms/inproc.go b/rpc/comms/inproc.go index 89cb93cdc..1fdbf8ace 100644 --- a/rpc/comms/inproc.go +++ b/rpc/comms/inproc.go @@ -1,21 +1,22 @@ package comms import ( - "github.com/ethereum/go-ethereum/rpc/api" - "github.com/ethereum/go-ethereum/rpc/shared" "fmt" + + "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/rpc/shared" "github.com/ethereum/go-ethereum/xeth" - "github.com/ethereum/go-ethereum/eth" ) type InProcClient struct { - api api.EthereumApi - codec codec.Codec - lastId interface{} + api api.EthereumApi + codec codec.Codec + lastId interface{} lastJsonrpc string - lastErr error - lastRes interface{} + lastErr error + lastRes interface{} } // Create a new in process client @@ -49,5 +50,4 @@ func (self *InProcClient) Send(req interface{}) error { func (self *InProcClient) Recv() (interface{}, error) { return self.lastRes, self.lastErr - //return *shared.NewRpcResponse(self.lastId, self.lastJsonrpc, self.lastRes, self.lastErr), nil } -- cgit v1.2.3 From f20256377731097c9478ede750efffd46d83b494 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Thu, 18 Jun 2015 18:23:13 +0200 Subject: added attach over ipc command --- rpc/comms/inproc.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'rpc/comms/inproc.go') diff --git a/rpc/comms/inproc.go b/rpc/comms/inproc.go index 1fdbf8ace..b9c4e93d9 100644 --- a/rpc/comms/inproc.go +++ b/rpc/comms/inproc.go @@ -51,3 +51,21 @@ func (self *InProcClient) Send(req interface{}) error { func (self *InProcClient) Recv() (interface{}, error) { return self.lastRes, self.lastErr } + +func (self *InProcClient) SupportedModules() (map[string]string, error) { + req := shared.Request{ + Id: 1, + Jsonrpc: "2.0", + Method: "modules", + } + + if res, err := self.api.Execute(&req); err == nil { + if result, ok := res.(map[string]string); ok { + return result, nil + } + } else { + return nil, err + } + + return nil, fmt.Errorf("Invalid response") +} -- cgit v1.2.3 From 2e0b56a72b3eafc89938003da29c06496ac9ad4e Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 22 Jun 2015 12:47:32 +0200 Subject: added RPC start/stop support --- rpc/comms/inproc.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'rpc/comms/inproc.go') diff --git a/rpc/comms/inproc.go b/rpc/comms/inproc.go index b9c4e93d9..5c84b8fd8 100644 --- a/rpc/comms/inproc.go +++ b/rpc/comms/inproc.go @@ -3,15 +3,12 @@ package comms import ( "fmt" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/rpc/api" "github.com/ethereum/go-ethereum/rpc/codec" "github.com/ethereum/go-ethereum/rpc/shared" - "github.com/ethereum/go-ethereum/xeth" ) type InProcClient struct { - api api.EthereumApi + api shared.EthereumApi codec codec.Codec lastId interface{} lastJsonrpc string @@ -31,10 +28,8 @@ func (self *InProcClient) Close() { } // Need to setup api support -func (self *InProcClient) Initialize(xeth *xeth.XEth, eth *eth.Ethereum) { - if apis, err := api.ParseApiString(api.AllApis, self.codec, xeth, eth); err == nil { - self.api = api.Merge(apis...) - } +func (self *InProcClient) Initialize(offeredApi shared.EthereumApi) { + self.api = offeredApi } func (self *InProcClient) Send(req interface{}) error { -- cgit v1.2.3