From 70797ef4de4b8a1fd39de0ad3853d870e2d61d2f Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 19 Jun 2024 13:06:19 +0800 Subject: [PATCH] internal/ethapi: refactor func ToMessage for CallArgs --- core/types/transaction.go | 5 +++++ internal/ethapi/api.go | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index b26c0fc2064d8..a85dbbe4dd4b1 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -778,3 +778,8 @@ func (m Message) CheckNonce() bool { return m.checkNonce } func (m Message) AccessList() AccessList { return m.accessList } func (m *Message) SetNonce(nonce uint64) { m.nonce = nonce } + +func (m *Message) SetBalanceTokenFeeForCall() { + m.balanceTokenFee = big.NewInt(0).SetUint64(m.gasLimit) + m.balanceTokenFee.Mul(m.balanceTokenFee, m.gasPrice) +} diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c02be7cc59fac..655ac11f67ce0 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1249,7 +1249,6 @@ type CallArgs struct { } // ToMessage converts CallArgs to the Message type used by the core evm -// TODO: set balanceTokenFee func (args *CallArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64) types.Message { // Set sender address or use a default if none specified var addr common.Address @@ -1298,11 +1297,7 @@ func (args *CallArgs) ToMessage(b Backend, number *big.Int, globalGasCap uint64) accessList = *args.AccessList } - balanceTokenFee := big.NewInt(0).SetUint64(gas) - balanceTokenFee = balanceTokenFee.Mul(balanceTokenFee, gasPrice) - - // Create new call message - msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, accessList, false, balanceTokenFee, number) + msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, accessList, false, nil, number) return msg } @@ -1321,6 +1316,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo } msg := args.ToMessage(b, header.Number, globalGasCap) + msg.SetBalanceTokenFeeForCall() // Setup context so it may be cancelled the call has completed // or, in case of unmetered gas, setup a context with a timeout.