Skip to content

Commit

Permalink
internal/ethapi: refactor func ToMessage for CallArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan authored and JukLee0ira committed Aug 12, 2024
1 parent e3df8e5 commit 51cabb9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
8 changes: 2 additions & 6 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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.
Expand Down

0 comments on commit 51cabb9

Please sign in to comment.