internal/ethapi: refactor func ToMessage for CallArgs

This commit is contained in:
Daniel Liu 2024-06-19 13:06:19 +08:00 committed by Daniel Liu
parent 1b2d023da2
commit 45e57e41b4
2 changed files with 7 additions and 6 deletions

View file

@ -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 = new(big.Int).SetUint64(m.gasLimit)
m.balanceTokenFee.Mul(m.balanceTokenFee, m.gasPrice)
}

View file

@ -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.