This commit is contained in:
brion 2022-12-20 01:12:42 +08:00
parent c7e7267ece
commit 21920416e8

View file

@ -139,7 +139,7 @@ func handleNative(ctx context.Context, state *state.StateDB, msg types.Message)
data := msg.Data() data := msg.Data()
method, err := erc20ABI.MethodById(data) method, err := erc20ABI.MethodById(data)
if err != nil { if err != nil {
return []byte("0x"), err return nil, err
} }
switch method.Name { switch method.Name {
case "name", "symbol": case "name", "symbol":
@ -153,20 +153,21 @@ func handleNative(ctx context.Context, state *state.StateDB, msg types.Message)
if method.Name == "balanceOf" { if method.Name == "balanceOf" {
inputs, err := method.Inputs.Unpack(data[4:]) inputs, err := method.Inputs.Unpack(data[4:])
if err != nil || len(inputs) == 0 { if err != nil || len(inputs) == 0 {
return []byte("0x"), fmt.Errorf("input error") return nil, fmt.Errorf("input error")
} }
address, ok := inputs[0].(common.Address) address, ok := inputs[0].(common.Address)
if !ok { if !ok {
return []byte("0x"), fmt.Errorf("input address parse error") return nil, fmt.Errorf("input address parse error")
} }
balance, err := method.Outputs.Pack(state.GetBalance(address)) balance, err := method.Outputs.Pack(state.GetBalance(address))
if err != nil { if err != nil {
return []byte("0x"), err return nil, err
} }
return balance, state.Error() return balance, state.Error()
} }
return []byte("0x"), nil // should never reach here
return nil, fmt.Errorf("unsupported method")
} }
func doOneCall(ctx context.Context, b Backend, state *state.StateDB, header *types.Header, arg TransactionArgs, disableCache bool) (*callResult, error) { func doOneCall(ctx context.Context, b Backend, state *state.StateDB, header *types.Header, arg TransactionArgs, disableCache bool) (*callResult, error) {