-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core/chains/evm/client: eth_call: include duplicate legacy field for compatability #12140
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
|
||
"github.com/ethereum/go-ethereum" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
|
@@ -775,21 +776,24 @@ func (r *rpcClient) CallContract(ctx context.Context, msg interface{}, blockNumb | |
|
||
lggr.Debug("RPC call: evmclient.Client#CallContract") | ||
start := time.Now() | ||
var hex hexutil.Bytes | ||
if http != nil { | ||
val, err = http.geth.CallContract(ctx, message, blockNumber) | ||
err = http.rpc.CallContext(ctx, &hex, "eth_call", toCallArg(message), toBlockNumArg(blockNumber)) | ||
err = r.wrapHTTP(err) | ||
} else { | ||
val, err = ws.geth.CallContract(ctx, message, blockNumber) | ||
err = ws.rpc.CallContext(ctx, &hex, "eth_call", toCallArg(message), toBlockNumArg(blockNumber)) | ||
err = r.wrapWS(err) | ||
} | ||
if err == nil { | ||
val = hex | ||
} | ||
duration := time.Since(start) | ||
|
||
r.logResult(lggr, err, duration, r.getRPCDomain(), "CallContract", | ||
"val", val, | ||
) | ||
|
||
return | ||
|
||
} | ||
|
||
func (r *rpcClient) PendingCallContract(ctx context.Context, msg interface{}) (val []byte, err error) { | ||
|
@@ -803,21 +807,69 @@ func (r *rpcClient) PendingCallContract(ctx context.Context, msg interface{}) (v | |
|
||
lggr.Debug("RPC call: evmclient.Client#PendingCallContract") | ||
start := time.Now() | ||
var hex hexutil.Bytes | ||
if http != nil { | ||
val, err = http.geth.PendingCallContract(ctx, message) | ||
err = http.rpc.CallContext(ctx, &hex, "eth_call", toCallArg(message), "pending") | ||
err = r.wrapHTTP(err) | ||
} else { | ||
val, err = ws.geth.PendingCallContract(ctx, message) | ||
err = ws.rpc.CallContext(ctx, &hex, "eth_call", toCallArg(message), "pending") | ||
err = r.wrapWS(err) | ||
} | ||
if err == nil { | ||
val = hex | ||
} | ||
duration := time.Since(start) | ||
|
||
r.logResult(lggr, err, duration, r.getRPCDomain(), "PendingCallContract", | ||
"val", val, | ||
) | ||
|
||
return | ||
} | ||
|
||
// COPIED FROM go-ethereum/ethclient/gethclient - must be kept up to date! | ||
func toBlockNumArg(number *big.Int) string { | ||
if number == nil { | ||
return "latest" | ||
} | ||
if number.Sign() >= 0 { | ||
return hexutil.EncodeBig(number) | ||
} | ||
// It's negative. | ||
if number.IsInt64() { | ||
return rpc.BlockNumber(number.Int64()).String() | ||
} | ||
// It's negative and large, which is invalid. | ||
return fmt.Sprintf("<invalid %d>", number) | ||
} | ||
|
||
// COPIED FROM go-ethereum/ethclient/gethclient - must be kept up to date! | ||
// Modified to include legacy 'data' as well as 'input' in order to support non-compliant servers. | ||
func toCallArg(msg ethereum.CallMsg) interface{} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jmank88 ethereum recently updated this function to and added extra fields, should we reflect those changes? https://github.com/ethereum/go-ethereum/blob/master/ethclient/ethclient.go#L642 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm 1.13.8 doesnot use it, just need to ensure we update this function if we do modify to new geth version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied from the version we import to minimize changes |
||
arg := map[string]interface{}{ | ||
"from": msg.From, | ||
"to": msg.To, | ||
} | ||
if len(msg.Data) > 0 { | ||
arg["input"] = hexutil.Bytes(msg.Data) | ||
arg["data"] = hexutil.Bytes(msg.Data) // duplicate legacy field for compatibility | ||
} | ||
if msg.Value != nil { | ||
arg["value"] = (*hexutil.Big)(msg.Value) | ||
} | ||
if msg.Gas != 0 { | ||
arg["gas"] = hexutil.Uint64(msg.Gas) | ||
} | ||
if msg.GasPrice != nil { | ||
arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice) | ||
} | ||
if msg.GasFeeCap != nil { | ||
arg["maxFeePerGas"] = (*hexutil.Big)(msg.GasFeeCap) | ||
} | ||
if msg.GasTipCap != nil { | ||
arg["maxPriorityFeePerGas"] = (*hexutil.Big)(msg.GasTipCap) | ||
} | ||
return arg | ||
} | ||
|
||
func (r *rpcClient) LatestBlockHeight(ctx context.Context) (*big.Int, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What commit sha of go-ethereum was this copied from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one that is imported in the go.mod