aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api
diff options
context:
space:
mode:
authorBas van Kervel <basvankervel@ziggo.nl>2015-06-08 16:41:04 +0800
committerBas van Kervel <basvankervel@gmail.com>2015-06-11 20:01:39 +0800
commit8ebf2d8fad729a8261f237bb05b6073e6c1b652f (patch)
treedd941d95eb9efdfb348caa94618d62b4523a02e8 /rpc/api
parent2f55a1d79853c1348fb1a4332fff98110167da80 (diff)
downloadgo-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.gz
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.bz2
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.lz
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.xz
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.tar.zst
go-tangerine-8ebf2d8fad729a8261f237bb05b6073e6c1b652f.zip
added RPC/IPC support
Diffstat (limited to 'rpc/api')
-rw-r--r--rpc/api/utils.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/rpc/api/utils.go b/rpc/api/utils.go
index 76f00c251..a62058140 100644
--- a/rpc/api/utils.go
+++ b/rpc/api/utils.go
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/xeth"
+ "github.com/ethereum/go-ethereum/rpc/shared"
)
const (
@@ -34,3 +35,43 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
return apis, nil
}
+
+// combines multiple API's
+type mergedApi struct {
+ apis map[string]EthereumApi
+}
+
+// create new merged api instance
+func newMergedApi(apis ...EthereumApi) *mergedApi {
+ mergedApi := new(mergedApi)
+ mergedApi.apis = make(map[string]EthereumApi)
+
+ for _, api := range apis {
+ for _, method := range api.Methods() {
+ mergedApi.apis[method] = api
+ }
+ }
+ return mergedApi
+}
+
+// Supported RPC methods
+func (self *mergedApi) Methods() []string {
+ all := make([]string, len(self.apis))
+ for method, _ := range self.apis {
+ all = append(all, method)
+ }
+ return all
+}
+
+// Call the correct API's Execute method for the given request
+func (self *mergedApi) Execute(req *shared.Request) (interface{}, error) {
+ if api, found := self.apis[req.Method]; found {
+ return api.Execute(req)
+ }
+ return nil, shared.NewNotImplementedError(req.Method)
+}
+
+// Merge multiple API's to a single API instance
+func Merge(apis ...EthereumApi) EthereumApi {
+ return newMergedApi(apis...)
+}