mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Add status field to call result
This commit is contained in:
parent
637acc5fa1
commit
d23eb894d6
2 changed files with 23 additions and 3 deletions
|
|
@ -1119,6 +1119,7 @@ type callResult struct {
|
||||||
Logs []*types.Log `json:"logs"`
|
Logs []*types.Log `json:"logs"`
|
||||||
Transfers []transfer `json:"transfers,omitempty"`
|
Transfers []transfer `json:"transfers,omitempty"`
|
||||||
GasUsed hexutil.Uint64 `json:"gasUsed"`
|
GasUsed hexutil.Uint64 `json:"gasUsed"`
|
||||||
|
Status hexutil.Uint64 `json:"status"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1205,7 +1206,7 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, blocks []CallBatch, blo
|
||||||
}
|
}
|
||||||
result, err := doCall(ctx, s.b, call, state, header, timeout, gp, &blockContext, vmConfig)
|
result, err := doCall(ctx, s.b, call, state, header, timeout, gp, &blockContext, vmConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
results[bi].Calls[i] = callResult{Error: err.Error()}
|
results[bi].Calls[i] = callResult{Error: err.Error(), Status: hexutil.Uint64(types.ReceiptStatusFailed)}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// If the result contains a revert reason, try to unpack it.
|
// If the result contains a revert reason, try to unpack it.
|
||||||
|
|
@ -1222,8 +1223,11 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, blocks []CallBatch, blo
|
||||||
transfers = vmConfig.Tracer.(*tracer).Transfers()
|
transfers = vmConfig.Tracer.(*tracer).Transfers()
|
||||||
}
|
}
|
||||||
callRes := callResult{ReturnValue: result.Return(), Logs: logs, Transfers: transfers, GasUsed: hexutil.Uint64(result.UsedGas)}
|
callRes := callResult{ReturnValue: result.Return(), Logs: logs, Transfers: transfers, GasUsed: hexutil.Uint64(result.UsedGas)}
|
||||||
if result.Err != nil {
|
if result.Failed() {
|
||||||
|
callRes.Status = hexutil.Uint64(types.ReceiptStatusFailed)
|
||||||
callRes.Error = result.Err.Error()
|
callRes.Error = result.Err.Error()
|
||||||
|
} else {
|
||||||
|
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
|
||||||
}
|
}
|
||||||
results[bi].Calls[i] = callRes
|
results[bi].Calls[i] = callRes
|
||||||
gasUsed += result.UsedGas
|
gasUsed += result.UsedGas
|
||||||
|
|
|
||||||
|
|
@ -647,6 +647,7 @@ func TestMulticallV1(t *testing.T) {
|
||||||
Error string
|
Error string
|
||||||
Logs []types.Log
|
Logs []types.Log
|
||||||
GasUsed string
|
GasUsed string
|
||||||
|
Status string
|
||||||
Transfers []transfer
|
Transfers []transfer
|
||||||
}
|
}
|
||||||
type blockRes struct {
|
type blockRes struct {
|
||||||
|
|
@ -695,10 +696,12 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x5208",
|
GasUsed: "0x5208",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}, {
|
}, {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x5208",
|
GasUsed: "0x5208",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -745,10 +748,12 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x5208",
|
GasUsed: "0x5208",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}, {
|
}, {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x5208",
|
GasUsed: "0x5208",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Number: "0xa",
|
Number: "0xa",
|
||||||
|
|
@ -760,10 +765,12 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x5208",
|
GasUsed: "0x5208",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}, {
|
}, {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0x0",
|
GasUsed: "0x0",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x0",
|
||||||
Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 9937000)", randomAccounts[3].addr.String()),
|
Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 9937000)", randomAccounts[3].addr.String()),
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
|
|
@ -807,6 +814,7 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
||||||
GasUsed: "0xe891",
|
GasUsed: "0xe891",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Number: "0xc",
|
Number: "0xc",
|
||||||
|
|
@ -818,6 +826,7 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000c",
|
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000c",
|
||||||
GasUsed: "0xe891",
|
GasUsed: "0xe891",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
@ -884,10 +893,12 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0xaacc",
|
GasUsed: "0xaacc",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}, {
|
}, {
|
||||||
ReturnValue: "0x0000000000000000000000000000000000000000000000000000000000000005",
|
ReturnValue: "0x0000000000000000000000000000000000000000000000000000000000000005",
|
||||||
GasUsed: "0x5bb7",
|
GasUsed: "0x5bb7",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
@ -928,6 +939,7 @@ func TestMulticallV1(t *testing.T) {
|
||||||
Data: []byte{},
|
Data: []byte{},
|
||||||
}},
|
}},
|
||||||
GasUsed: "0x5508",
|
GasUsed: "0x5508",
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
@ -990,6 +1002,7 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: strings.ToLower(randomAccounts[2].addr.String()),
|
ReturnValue: strings.ToLower(randomAccounts[2].addr.String()),
|
||||||
GasUsed: "0x52f6",
|
GasUsed: "0x52f6",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
@ -1042,7 +1055,8 @@ func TestMulticallV1(t *testing.T) {
|
||||||
Value: big.NewInt(100),
|
Value: big.NewInt(100),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
@ -1084,10 +1098,12 @@ func TestMulticallV1(t *testing.T) {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0xd166",
|
GasUsed: "0xd166",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}, {
|
}, {
|
||||||
ReturnValue: "0x",
|
ReturnValue: "0x",
|
||||||
GasUsed: "0xe6d9",
|
GasUsed: "0xe6d9",
|
||||||
Logs: []types.Log{},
|
Logs: []types.Log{},
|
||||||
|
Status: "0x1",
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue