Skip to content

Commit ffdea9e

Browse files
committed
Define ToCeloFn type
The declaration is repeated multiple times and I am about to change it, so it is nice to pull it into a typedef.
1 parent 9ec64bb commit ffdea9e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

core/types/transaction.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,12 @@ type TxWithMinerFee struct {
549549
tx *Transaction
550550
minerFee *big.Int // in CELO
551551
}
552+
type ToCELOFn func(amount *big.Int, feeCurrency *common.Address) *big.Int
552553

553554
// NewTxWithMinerFee creates a wrapped transaction, calculating the effective
554555
// miner gasTipCap if a base fee is provided. The MinerFee is converted to CELO.
555556
// Returns error in case of a negative effective miner gasTipCap.
556-
func NewTxWithMinerFee(tx *Transaction, baseFeeFn func(feeCurrency *common.Address) *big.Int, toCELO func(amount *big.Int, feeCurrency *common.Address) *big.Int) (*TxWithMinerFee, error) {
557+
func NewTxWithMinerFee(tx *Transaction, baseFeeFn func(feeCurrency *common.Address) *big.Int, toCELO ToCELOFn) (*TxWithMinerFee, error) {
557558
minerFee, err := tx.EffectiveGasTip(baseFeeFn(tx.FeeCurrency()))
558559
if err != nil {
559560
return nil, err
@@ -596,11 +597,11 @@ func (s *TxByPriceAndTime) Pop() interface{} {
596597
// transactions in a profit-maximizing sorted order, while supporting removing
597598
// entire batches of transactions for non-executable accounts.
598599
type TransactionsByPriceAndNonce struct {
599-
txs map[common.Address]Transactions // Per account nonce-sorted list of transactions
600-
heads TxByPriceAndTime // Next transaction for each unique account (price heap)
601-
signer Signer // Signer for the set of transactions
602-
baseFeeFn func(feeCurrency *common.Address) *big.Int // Function to get the basefee for the specified feecurrency.
603-
toCELO func(amount *big.Int, feeCurrency *common.Address) *big.Int // Current exchange rate to CELO
600+
txs map[common.Address]Transactions // Per account nonce-sorted list of transactions
601+
heads TxByPriceAndTime // Next transaction for each unique account (price heap)
602+
signer Signer // Signer for the set of transactions
603+
baseFeeFn func(feeCurrency *common.Address) *big.Int // Function to get the basefee for the specified feecurrency.
604+
toCELO ToCELOFn // Current exchange rate to CELO
604605
}
605606

606607
// NewTransactionsByPriceAndNonce creates a transaction set that can retrieve
@@ -609,7 +610,7 @@ type TransactionsByPriceAndNonce struct {
609610
// Note, the input map is reowned so the caller should not interact any more with
610611
// if after providing it to the constructor.
611612
// Note: txCmpFunc should handle the basefee
612-
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFeeFn func(feeCurrency *common.Address) *big.Int, toCELO func(amount *big.Int, feeCurrency *common.Address) *big.Int) *TransactionsByPriceAndNonce {
613+
func NewTransactionsByPriceAndNonce(signer Signer, txs map[common.Address]Transactions, baseFeeFn func(feeCurrency *common.Address) *big.Int, toCELO ToCELOFn) *TransactionsByPriceAndNonce {
613614
// Initialize a price and received time based heap with the head transactions
614615
heads := make(TxByPriceAndTime, 0, len(txs))
615616
for from, accTxs := range txs {

miner/block.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func (b *blockState) finalizeAndAssemble(w *worker) (*types.Block, error) {
387387
}
388388

389389
// totalFees computes total consumed fees in CELO. Block transactions and receipts have to have the same order.
390-
func totalFees(block *types.Block, receipts []*types.Receipt, baseFeeFn func(*common.Address) *big.Int, toCELO func(*big.Int, *common.Address) *big.Int, espresso bool) *big.Float {
390+
func totalFees(block *types.Block, receipts []*types.Receipt, baseFeeFn func(*common.Address) *big.Int, toCELO types.ToCELOFn, espresso bool) *big.Float {
391391
feesWei := new(big.Int)
392392
for i, tx := range block.Transactions() {
393393
var basefee *big.Int
@@ -402,7 +402,7 @@ func totalFees(block *types.Block, receipts []*types.Receipt, baseFeeFn func(*co
402402

403403
// createConversionFunctions creates a function to convert any currency to Celo and a function to get the gas price minimum for that currency.
404404
// Both functions internally cache their results.
405-
func createConversionFunctions(sysCtx *core.SysContractCallCtx, chain *core.BlockChain, header *types.Header, state *state.StateDB) (func(feeCurrency *common.Address) *big.Int, func(amount *big.Int, feeCurrency *common.Address) *big.Int) {
405+
func createConversionFunctions(sysCtx *core.SysContractCallCtx, chain *core.BlockChain, header *types.Header, state *state.StateDB) (func(feeCurrency *common.Address) *big.Int, types.ToCELOFn) {
406406
vmRunner := chain.NewEVMRunner(header, state)
407407
currencyManager := currency.NewManager(vmRunner)
408408

0 commit comments

Comments
 (0)