diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-16 01:28:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-16 01:28:48 +0800 |
commit | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (patch) | |
tree | 0053cb5b84978645b3c83895a651c512e081a183 /rpc/api/mergedapi.go | |
parent | bac9a94ddf20dc530966cbf6cd384aaf94aedc77 (diff) | |
parent | 4673b04503742de9b1622557b44135d6a4934ad6 (diff) | |
download | go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.gz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.bz2 go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.lz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.xz go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.tar.zst go-tangerine-5daf8729be88eca87b302ebf7a46fc69cad0f6d0.zip |
Merge branch 'release/0.9.30'v0.9.30
Diffstat (limited to 'rpc/api/mergedapi.go')
-rw-r--r-- | rpc/api/mergedapi.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/rpc/api/mergedapi.go b/rpc/api/mergedapi.go new file mode 100644 index 000000000..b62477a14 --- /dev/null +++ b/rpc/api/mergedapi.go @@ -0,0 +1,66 @@ +package api + +import ( + "github.com/ethereum/go-ethereum/rpc/shared" +) + +const ( + MergedApiVersion = "1.0" +) + +// combines multiple API's +type MergedApi struct { + apis map[string]string + methods map[string]EthereumApi +} + +// create new merged api instance +func newMergedApi(apis ...EthereumApi) *MergedApi { + mergedApi := new(MergedApi) + mergedApi.apis = make(map[string]string, len(apis)) + mergedApi.methods = make(map[string]EthereumApi) + + for _, api := range apis { + mergedApi.apis[api.Name()] = api.ApiVersion() + for _, method := range api.Methods() { + mergedApi.methods[method] = api + } + } + return mergedApi +} + +// Supported RPC methods +func (self *MergedApi) Methods() []string { + all := make([]string, len(self.methods)) + for method, _ := range self.methods { + 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 res, _ := self.handle(req); res != nil { + return res, nil + } + if api, found := self.methods[req.Method]; found { + return api.Execute(req) + } + return nil, shared.NewNotImplementedError(req.Method) +} + +func (self *MergedApi) Name() string { + return MergedApiName +} + +func (self *MergedApi) ApiVersion() string { + return MergedApiVersion +} + +func (self *MergedApi) handle(req *shared.Request) (interface{}, error) { + if req.Method == "modules" { // provided API's + return self.apis, nil + } + + return nil, nil +} |