mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-22 19:40:36 +00:00
xeth, rpc: implement eth_estimateGas. Closes #930
This commit is contained in:
parent
96d4a7d087
commit
66de3f0aa8
@ -127,7 +127,7 @@ func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
|
||||
)
|
||||
}
|
||||
|
||||
func (self *UiLib) Call(params map[string]interface{}) (string, error) {
|
||||
func (self *UiLib) Call(params map[string]interface{}) (string, string, error) {
|
||||
object := mapToTxParams(params)
|
||||
|
||||
return self.XEth.Call(
|
||||
|
31
rpc/api.go
31
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
|
||||
case "eth_estimateGas":
|
||||
_, gas, err := api.doCall(req.Params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ func (self *XEth) PushTx(encodedTx string) (string, error) {
|
||||
return tx.Hash().Hex(), nil
|
||||
}
|
||||
|
||||
func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
|
||||
func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, string, error) {
|
||||
statedb := self.State().State() //self.eth.ChainManager().TransState()
|
||||
var from *state.StateObject
|
||||
if len(fromStr) == 0 {
|
||||
@ -807,8 +807,10 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
|
||||
block := self.CurrentBlock()
|
||||
vmenv := core.NewEnv(statedb, self.backend.ChainManager(), msg, block)
|
||||
|
||||
initialGas := new(big.Int).Set(msg.gas)
|
||||
res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value)
|
||||
return common.ToHex(res), err
|
||||
|
||||
return common.ToHex(res), initialGas.Sub(initialGas, msg.gas).String(), err
|
||||
}
|
||||
|
||||
func (self *XEth) ConfirmTransaction(tx string) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user