aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-05-12 22:26:38 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-05-12 22:26:38 +0800
commitf87094b660c95b547486e7439620e68f3d59c45f (patch)
tree870c82c7c67c683d1339c1a081c20d87f8f261b8 /rpc/api.go
parentd82caa5ce38705d2dcdc2ba15c93df9325504e34 (diff)
parentdca290d5252f23435f48f6b15c332422b2c39b72 (diff)
downloadgo-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar.gz
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar.bz2
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar.lz
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar.xz
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.tar.zst
go-tangerine-f87094b660c95b547486e7439620e68f3d59c45f.zip
Merge pull request #932 from obscuren/develop
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..066c81222 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 = newHexNum(0)
+ } else {
+ *reply = newHexNum(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)
+}