forked from cerc-io/plugeth
Add setMining RPC method
This commit is contained in:
parent
605dd3a982
commit
a59cd94625
@ -201,6 +201,21 @@ func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
|
|||||||
return args, nil
|
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) {
|
func (req *RpcRequest) ToCompileArgs() (string, error) {
|
||||||
if len(req.Params) < 1 {
|
if len(req.Params) < 1 {
|
||||||
return "", NewErrorResponse(ErrorArguments)
|
return "", NewErrorResponse(ErrorArguments)
|
||||||
|
@ -267,6 +267,11 @@ func (p *EthereumApi) GetIsMining(reply *interface{}) error {
|
|||||||
return nil
|
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 {
|
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
|
||||||
*reply = p.xeth.Backend().ChainManager().CurrentBlock().Number()
|
*reply = p.xeth.Backend().ChainManager().CurrentBlock().Number()
|
||||||
return nil
|
return nil
|
||||||
@ -400,6 +405,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
return p.GetIsListening(reply)
|
return p.GetIsListening(reply)
|
||||||
case "eth_mining":
|
case "eth_mining":
|
||||||
return p.GetIsMining(reply)
|
return p.GetIsMining(reply)
|
||||||
|
case "eth_setMining":
|
||||||
|
args, err := req.ToBoolArgs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return p.SetMining(args, reply)
|
||||||
case "eth_peerCount":
|
case "eth_peerCount":
|
||||||
return p.GetPeerCount(reply)
|
return p.GetPeerCount(reply)
|
||||||
case "eth_number":
|
case "eth_number":
|
||||||
|
11
xeth/xeth.go
11
xeth/xeth.go
@ -102,6 +102,17 @@ func (self *XEth) IsMining() bool {
|
|||||||
return self.miner.Mining()
|
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 {
|
func (self *XEth) IsListening() bool {
|
||||||
return self.eth.IsListening()
|
return self.eth.IsListening()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user