diff options
Diffstat (limited to 'rpc/api.go')
-rw-r--r-- | rpc/api.go | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/rpc/api.go b/rpc/api.go index 8bbe80bd8..af9f10530 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -167,13 +167,16 @@ func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) erro } func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error { - delete(self.logs, id) + if _, ok := self.logs[id]; ok { + delete(self.logs, id) + } + self.filterManager.UninstallFilter(id) *reply = true return nil } -func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error { +func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interface{}) error { var id int filter := core.NewFilter(self.xeth().Backend()) @@ -183,10 +186,14 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error self.logs[id].add(&state.StateLog{}) } - if args == "pending" { + + switch args.Word { + case "pending": filter.PendingCallback = callback - } else if args == "chain" { + case "latest": filter.BlockCallback = callback + default: + return NewValidationError("Word", "Must be `latest` or `pending`") } id = self.filterManager.InstallFilter(filter) @@ -377,7 +384,13 @@ func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface } id = p.xeth().Whisper().Watch(opts) p.messages[id] = &whisperFilter{timeout: time.Now()} - *reply = id + *reply = toHex(big.NewInt(int64(id)).Bytes()) + return nil +} + +func (p *EthereumApi) UninstallWhisperFilter(id int, reply *interface{}) error { + delete(p.messages, id) + *reply = true return nil } @@ -412,6 +425,14 @@ func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error { return nil } +func (p *EthereumApi) GetTransactionByHash(hash string, reply *interface{}) error { + tx := p.xeth().EthTransactionByHash(hash) + if tx != nil { + *reply = NewTransactionRes(tx) + } + return nil +} + func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) { block := p.xeth().EthBlockByHash(blockhash) br := NewBlockRes(block) @@ -460,6 +481,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } *reply = toHex(crypto.Sha3(fromHex(args.Data))) + case "web3_clientVersion": + *reply = p.xeth().Backend().Version() + case "net_version": + return NewNotImplementedError(req.Method) case "net_listening": *reply = p.xeth().IsListening() case "net_peerCount": @@ -561,7 +586,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } return p.Call(args, reply) case "eth_flush": - return errNotImplemented + return NewNotImplementedError(req.Method) case "eth_getBlockByHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -585,19 +610,23 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } *reply = v case "eth_getTransactionByHash": - return errNotImplemented + // HashIndexArgs used, but only the "Hash" part we need. + args := new(HashIndexArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + } + return p.GetTransactionByHash(args.Hash, reply) case "eth_getTransactionByBlockHashAndIndex": args := new(HashIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } - v, err := p.GetBlockByHash(args.BlockHash, true) + v, err := p.GetBlockByHash(args.Hash, true) if err != nil { return err } if args.Index > int64(len(v.Transactions)) || args.Index < 0 { - return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist") + return NewValidationError("Index", "does not exist") } *reply = v.Transactions[args.Index] case "eth_getTransactionByBlockNumberAndIndex": @@ -611,7 +640,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } if args.Index > int64(len(v.Transactions)) || args.Index < 0 { - return NewErrorWithMessage(errDecodeArgs, "Transaction index does not exist") + return NewValidationError("Index", "does not exist") } *reply = v.Transactions[args.Index] case "eth_getUncleByBlockHashAndIndex": @@ -620,12 +649,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByHash(args.BlockHash, false) + v, err := p.GetBlockByHash(args.Hash, false) if err != nil { return err } if args.Index > int64(len(v.Uncles)) || args.Index < 0 { - return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist") + return NewValidationError("Index", "does not exist") } uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) @@ -644,7 +673,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } if args.Index > int64(len(v.Uncles)) || args.Index < 0 { - return NewErrorWithMessage(errDecodeArgs, "Uncle index does not exist") + return NewValidationError("Index", "does not exist") } uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) @@ -654,10 +683,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error *reply = uncle case "eth_getCompilers": return p.GetCompilers(reply) - case "eth_compileSolidity": - case "eth_compileLLL": - case "eth_compileSerpent": - return errNotImplemented + case "eth_compileSolidity", "eth_compileLLL", "eth_compileSerpent": + return NewNotImplementedError(req.Method) case "eth_newFilter": args := new(FilterOptions) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -669,7 +696,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.NewFilterString(args.Word, reply) + return p.NewFilterString(args, reply) case "eth_uninstallFilter": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -694,21 +721,22 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } return p.AllLogs(args, reply) - case "eth_getWork": - case "eth_submitWork": - return errNotImplemented - case "db_put": + case "eth_getWork", "eth_submitWork": + return NewNotImplementedError(req.Method) + case "db_putString": args := new(DbArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } return p.DbPut(args, reply) - case "db_get": + case "db_getString": args := new(DbArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } return p.DbGet(args, reply) + case "db_putHex", "db_getHex": + return NewNotImplementedError(req.Method) case "shh_post": args := new(WhisperMessageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -723,9 +751,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } return p.HasWhisperIdentity(args.Identity, reply) - case "shh_newGroup": - case "shh_addToGroup": - return errNotImplemented + case "shh_newGroup", "shh_addToGroup": + return NewNotImplementedError(req.Method) case "shh_newFilter": args := new(WhisperFilterArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -733,7 +760,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } return p.NewWhisperFilter(args, reply) case "shh_uninstallFilter": - return errNotImplemented + args := new(FilterIdArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + return p.UninstallWhisperFilter(args.Id, reply) case "shh_getFilterChanges": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -765,7 +796,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error // } // return p.WatchTx(args, reply) default: - return NewErrorWithMessage(errNotImplemented, req.Method) + return NewNotImplementedError(req.Method) } rpclogger.DebugDetailf("Reply: %T %s", reply, reply) |