mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
parent
0662224c31
commit
47520a1316
1 changed files with 17 additions and 0 deletions
|
|
@ -638,6 +638,23 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
|
||||||
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
|
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RevertErrorData returns the 'revert reason' data of a contract call.
|
||||||
|
//
|
||||||
|
// This can be used with CallContract and EstimateGas, and only when the server is Geth.
|
||||||
|
func RevertErrorData(err error) ([]byte, bool) {
|
||||||
|
var ec rpc.Error
|
||||||
|
var ed rpc.DataError
|
||||||
|
if errors.As(err, &ec) && errors.As(err, &ed) && ec.ErrorCode() == 3 {
|
||||||
|
if eds, ok := ed.ErrorData().(string); ok {
|
||||||
|
revertData, err := hexutil.Decode(eds)
|
||||||
|
if err == nil {
|
||||||
|
return revertData, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
func toBlockNumArg(number *big.Int) string {
|
func toBlockNumArg(number *big.Int) string {
|
||||||
if number == nil {
|
if number == nil {
|
||||||
return "latest"
|
return "latest"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue