mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +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"`
|
||||
Transfers []transfer `json:"transfers,omitempty"`
|
||||
GasUsed hexutil.Uint64 `json:"gasUsed"`
|
||||
Status hexutil.Uint64 `json:"status"`
|
||||
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)
|
||||
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
|
||||
}
|
||||
// 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()
|
||||
}
|
||||
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()
|
||||
} else {
|
||||
callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful)
|
||||
}
|
||||
results[bi].Calls[i] = callRes
|
||||
gasUsed += result.UsedGas
|
||||
|
|
|
|||
|
|
@ -647,6 +647,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
Error string
|
||||
Logs []types.Log
|
||||
GasUsed string
|
||||
Status string
|
||||
Transfers []transfer
|
||||
}
|
||||
type blockRes struct {
|
||||
|
|
@ -695,10 +696,12 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}, {
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
}, {
|
||||
|
|
@ -745,10 +748,12 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}, {
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}, {
|
||||
Number: "0xa",
|
||||
|
|
@ -760,10 +765,12 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x",
|
||||
GasUsed: "0x5208",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}, {
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0x0",
|
||||
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()),
|
||||
}},
|
||||
}},
|
||||
|
|
@ -807,6 +814,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000b",
|
||||
GasUsed: "0xe891",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}, {
|
||||
Number: "0xc",
|
||||
|
|
@ -818,6 +826,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000c",
|
||||
GasUsed: "0xe891",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
@ -884,10 +893,12 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x",
|
||||
GasUsed: "0xaacc",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}, {
|
||||
ReturnValue: "0x0000000000000000000000000000000000000000000000000000000000000005",
|
||||
GasUsed: "0x5bb7",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
@ -928,6 +939,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
Data: []byte{},
|
||||
}},
|
||||
GasUsed: "0x5508",
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
@ -990,6 +1002,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: strings.ToLower(randomAccounts[2].addr.String()),
|
||||
GasUsed: "0x52f6",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
@ -1043,6 +1056,7 @@ func TestMulticallV1(t *testing.T) {
|
|||
},
|
||||
},
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
@ -1084,10 +1098,12 @@ func TestMulticallV1(t *testing.T) {
|
|||
ReturnValue: "0x",
|
||||
GasUsed: "0xd166",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}, {
|
||||
ReturnValue: "0x",
|
||||
GasUsed: "0xe6d9",
|
||||
Logs: []types.Log{},
|
||||
Status: "0x1",
|
||||
}},
|
||||
}},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue