aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-12 20:14:08 +0800
committerobscuren <geffobscura@gmail.com>2015-05-12 20:21:43 +0800
commit66de3f0aa849849c5cf5ad84265f3f3ce8ca5282 (patch)
treebef9ea4c2ff86fd1be3285812dcb9c02d19cde23 /rpc/api.go
parent96d4a7d0870ee019098cf1991b00f6959843e6fd (diff)
downloaddexon-66de3f0aa849849c5cf5ad84265f3f3ce8ca5282.tar.gz
dexon-66de3f0aa849849c5cf5ad84265f3f3ce8ca5282.tar.zst
dexon-66de3f0aa849849c5cf5ad84265f3f3ce8ca5282.zip
xeth, rpc: implement eth_estimateGas. Closes #930
Diffstat (limited to 'rpc/api.go')
-rw-r--r--rpc/api.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/rpc/api.go b/rpc/api.go
index d53a9917d..774d26ea2 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -186,16 +186,24 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
*reply = v
- case "eth_call":
- args := new(CallArgs)
- if err := json.Unmarshal(req.Params, &args); err != nil {
+ case "eth_estimateGas":
+ _, gas, err := api.doCall(req.Params)
+ if err != nil {
return err
}
- v, err := api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+ // TODO unwrap the parent method's ToHex call
+ if len(gas) == 0 {
+ *reply = newHexData([]byte{})
+ } else {
+ *reply = newHexData(gas)
+ }
+ case "eth_call":
+ v, _, err := api.doCall(req.Params)
if err != nil {
return err
}
+
// TODO unwrap the parent method's ToHex call
if v == "0x0" {
*reply = newHexData([]byte{})
@@ -571,3 +579,12 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
glog.V(logger.Detail).Infof("Reply: %T %s\n", reply, reply)
return nil
}
+
+func (api *EthereumApi) doCall(params json.RawMessage) (string, string, error) {
+ args := new(CallArgs)
+ if err := json.Unmarshal(params, &args); err != nil {
+ return "", "", err
+ }
+
+ return api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+}