diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-20 01:58:15 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-20 01:58:15 +0800 |
commit | a59cd94625f589bb167be7a9c4588ff959dcfc00 (patch) | |
tree | fb7a4c697b6814da60f8cae29d0d497951e741f6 | |
parent | 605dd3a9820bb74be883afe3cb0e462aca40b32d (diff) | |
download | go-tangerine-a59cd94625f589bb167be7a9c4588ff959dcfc00.tar.gz go-tangerine-a59cd94625f589bb167be7a9c4588ff959dcfc00.tar.zst go-tangerine-a59cd94625f589bb167be7a9c4588ff959dcfc00.zip |
Add setMining RPC method
-rw-r--r-- | rpc/message.go | 15 | ||||
-rw-r--r-- | rpc/packages.go | 11 | ||||
-rw-r--r-- | xeth/xeth.go | 11 |
3 files changed, 37 insertions, 0 deletions
diff --git a/rpc/message.go b/rpc/message.go index 1935bf1e2..d02acef0e 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -201,6 +201,21 @@ func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) { return args, nil } +func (req *RpcRequest) ToBoolArgs() (bool, error) { + if len(req.Params) < 1 { + return false, NewErrorResponse(ErrorArguments) + } + + var args bool + err := json.Unmarshal(req.Params[0], &args) + if err != nil { + return false, NewErrorResponse(ErrorDecodeArgs) + } + + rpclogger.DebugDetailf("%T %v", args, args) + return args, nil +} + func (req *RpcRequest) ToCompileArgs() (string, error) { if len(req.Params) < 1 { return "", NewErrorResponse(ErrorArguments) diff --git a/rpc/packages.go b/rpc/packages.go index c969f58cc..d82538c92 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -267,6 +267,11 @@ func (p *EthereumApi) GetIsMining(reply *interface{}) error { return nil } +func (p *EthereumApi) SetMining(shouldmine bool, reply *interface{}) error { + *reply = p.xeth.SetMining(shouldmine) + return nil +} + func (p *EthereumApi) BlockNumber(reply *interface{}) error { *reply = p.xeth.Backend().ChainManager().CurrentBlock().Number() return nil @@ -400,6 +405,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return p.GetIsListening(reply) case "eth_mining": return p.GetIsMining(reply) + case "eth_setMining": + args, err := req.ToBoolArgs() + if err != nil { + return err + } + return p.SetMining(args, reply) case "eth_peerCount": return p.GetPeerCount(reply) case "eth_number": diff --git a/xeth/xeth.go b/xeth/xeth.go index f005105bb..06915c5e0 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -102,6 +102,17 @@ func (self *XEth) IsMining() bool { return self.miner.Mining() } +func (self *XEth) SetMining(shouldmine bool) bool { + ismining := self.miner.Mining() + if shouldmine && !ismining { + self.miner.Start() + } + if ismining && !shouldmine { + self.miner.Stop() + } + return self.miner.Mining() +} + func (self *XEth) IsListening() bool { return self.eth.IsListening() } |