ethclient: add maxUsedGas to simulate call results

This commit is contained in:
RekCuy63 2026-04-24 23:30:41 +08:00
parent 8091994e7b
commit a740a1f716
3 changed files with 14 additions and 0 deletions

View file

@ -914,6 +914,7 @@ type SimulateCallResult struct {
ReturnValue []byte `json:"returnData"` ReturnValue []byte `json:"returnData"`
Logs []*types.Log `json:"logs"` Logs []*types.Log `json:"logs"`
GasUsed uint64 `json:"gasUsed"` GasUsed uint64 `json:"gasUsed"`
MaxUsedGas uint64 `json:"maxUsedGas"`
Status uint64 `json:"status"` Status uint64 `json:"status"`
Error *CallError `json:"error,omitempty"` Error *CallError `json:"error,omitempty"`
} }
@ -921,6 +922,7 @@ type SimulateCallResult struct {
type simulateCallResultMarshaling struct { type simulateCallResultMarshaling struct {
ReturnValue hexutil.Bytes ReturnValue hexutil.Bytes
GasUsed hexutil.Uint64 GasUsed hexutil.Uint64
MaxUsedGas hexutil.Uint64
Status hexutil.Uint64 Status hexutil.Uint64
} }

View file

@ -861,6 +861,12 @@ func TestSimulateV1(t *testing.T) {
if results[0].Calls[0].Error != nil { if results[0].Calls[0].Error != nil {
t.Errorf("expected no error, got %v", results[0].Calls[0].Error) t.Errorf("expected no error, got %v", results[0].Calls[0].Error)
} }
if results[0].Calls[0].MaxUsedGas == 0 {
t.Error("expected maxUsedGas to be set")
}
if results[0].Calls[0].MaxUsedGas < results[0].Calls[0].GasUsed {
t.Errorf("expected maxUsedGas >= gasUsed, got %d < %d", results[0].Calls[0].MaxUsedGas, results[0].Calls[0].GasUsed)
}
} }
func TestSimulateV1WithBlockOverrides(t *testing.T) { func TestSimulateV1WithBlockOverrides(t *testing.T) {

View file

@ -17,6 +17,7 @@ func (s SimulateCallResult) MarshalJSON() ([]byte, error) {
ReturnValue hexutil.Bytes `json:"returnData"` ReturnValue hexutil.Bytes `json:"returnData"`
Logs []*types.Log `json:"logs"` Logs []*types.Log `json:"logs"`
GasUsed hexutil.Uint64 `json:"gasUsed"` GasUsed hexutil.Uint64 `json:"gasUsed"`
MaxUsedGas hexutil.Uint64 `json:"maxUsedGas"`
Status hexutil.Uint64 `json:"status"` Status hexutil.Uint64 `json:"status"`
Error *CallError `json:"error,omitempty"` Error *CallError `json:"error,omitempty"`
} }
@ -24,6 +25,7 @@ func (s SimulateCallResult) MarshalJSON() ([]byte, error) {
enc.ReturnValue = s.ReturnValue enc.ReturnValue = s.ReturnValue
enc.Logs = s.Logs enc.Logs = s.Logs
enc.GasUsed = hexutil.Uint64(s.GasUsed) enc.GasUsed = hexutil.Uint64(s.GasUsed)
enc.MaxUsedGas = hexutil.Uint64(s.MaxUsedGas)
enc.Status = hexutil.Uint64(s.Status) enc.Status = hexutil.Uint64(s.Status)
enc.Error = s.Error enc.Error = s.Error
return json.Marshal(&enc) return json.Marshal(&enc)
@ -35,6 +37,7 @@ func (s *SimulateCallResult) UnmarshalJSON(input []byte) error {
ReturnValue *hexutil.Bytes `json:"returnData"` ReturnValue *hexutil.Bytes `json:"returnData"`
Logs []*types.Log `json:"logs"` Logs []*types.Log `json:"logs"`
GasUsed *hexutil.Uint64 `json:"gasUsed"` GasUsed *hexutil.Uint64 `json:"gasUsed"`
MaxUsedGas *hexutil.Uint64 `json:"maxUsedGas"`
Status *hexutil.Uint64 `json:"status"` Status *hexutil.Uint64 `json:"status"`
Error *CallError `json:"error,omitempty"` Error *CallError `json:"error,omitempty"`
} }
@ -51,6 +54,9 @@ func (s *SimulateCallResult) UnmarshalJSON(input []byte) error {
if dec.GasUsed != nil { if dec.GasUsed != nil {
s.GasUsed = uint64(*dec.GasUsed) s.GasUsed = uint64(*dec.GasUsed)
} }
if dec.MaxUsedGas != nil {
s.MaxUsedGas = uint64(*dec.MaxUsedGas)
}
if dec.Status != nil { if dec.Status != nil {
s.Status = uint64(*dec.Status) s.Status = uint64(*dec.Status)
} }