diff --git a/blockbuster/proposals/abci.go b/blockbuster/abci/abci.go similarity index 99% rename from blockbuster/proposals/abci.go rename to blockbuster/abci/abci.go index cb7e17c..2e8f2f9 100644 --- a/blockbuster/proposals/abci.go +++ b/blockbuster/abci/abci.go @@ -1,4 +1,4 @@ -package proposals +package abci import ( "fmt" diff --git a/blockbuster/proposals/abci_test.go b/blockbuster/abci/abci_test.go similarity index 99% rename from blockbuster/proposals/abci_test.go rename to blockbuster/abci/abci_test.go index b778edf..4444d4a 100644 --- a/blockbuster/proposals/abci_test.go +++ b/blockbuster/abci/abci_test.go @@ -1,4 +1,4 @@ -package proposals_test +package abci_test import ( "math/rand" diff --git a/blockbuster/proposals/check_tx.go b/blockbuster/abci/check_tx.go similarity index 99% rename from blockbuster/proposals/check_tx.go rename to blockbuster/abci/check_tx.go index 7facb9c..e9deaf9 100644 --- a/blockbuster/proposals/check_tx.go +++ b/blockbuster/abci/check_tx.go @@ -1,4 +1,4 @@ -package proposals +package abci import ( "context" diff --git a/blockbuster/lane_constructor.go b/blockbuster/lane_constructor.go index c139978..ccc56ae 100644 --- a/blockbuster/lane_constructor.go +++ b/blockbuster/lane_constructor.go @@ -14,7 +14,7 @@ import ( // and CheckOrderHandler. To extend this lane, you must either utilize the default // handlers or construct your own that you pass into the constructor/setters. type LaneConstructor[C comparable] struct { - // cfg stores functionality requred to encode/decode transactions, maintains how + // cfg stores functionality required to encode/decode transactions, maintains how // many transactions are allowed in this lane's mempool, and the amount of block // space this lane is allowed to consume. cfg LaneConfig diff --git a/blockbuster/lane_handlers.go b/blockbuster/lane_handlers.go index 52fb5d7..627c198 100644 --- a/blockbuster/lane_handlers.go +++ b/blockbuster/lane_handlers.go @@ -1,7 +1,6 @@ package blockbuster import ( - "context" "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -154,46 +153,3 @@ func DefaultMatchHandler() MatchHandler { return true } } - -// DefaultTxPriority returns a default implementation of the TxPriority. It prioritizes -// transactions by their fee. -func DefaultTxPriority() TxPriority[string] { - return TxPriority[string]{ - GetTxPriority: func(goCtx context.Context, tx sdk.Tx) string { - feeTx, ok := tx.(sdk.FeeTx) - if !ok { - return "" - } - - return feeTx.GetFee().String() - }, - Compare: func(a, b string) int { - aCoins, _ := sdk.ParseCoinsNormalized(a) - bCoins, _ := sdk.ParseCoinsNormalized(b) - - switch { - case aCoins == nil && bCoins == nil: - return 0 - - case aCoins == nil: - return -1 - - case bCoins == nil: - return 1 - - default: - switch { - case aCoins.IsAllGT(bCoins): - return 1 - - case aCoins.IsAllLT(bCoins): - return -1 - - default: - return 0 - } - } - }, - MinValue: "", - } -} diff --git a/blockbuster/lane_mempool.go b/blockbuster/lane_mempool.go index aa3c9d4..e102ee8 100644 --- a/blockbuster/lane_mempool.go +++ b/blockbuster/lane_mempool.go @@ -36,6 +36,49 @@ type ( } ) +// DefaultTxPriority returns a default implementation of the TxPriority. It prioritizes +// transactions by their fee. +func DefaultTxPriority() TxPriority[string] { + return TxPriority[string]{ + GetTxPriority: func(goCtx context.Context, tx sdk.Tx) string { + feeTx, ok := tx.(sdk.FeeTx) + if !ok { + return "" + } + + return feeTx.GetFee().String() + }, + Compare: func(a, b string) int { + aCoins, _ := sdk.ParseCoinsNormalized(a) + bCoins, _ := sdk.ParseCoinsNormalized(b) + + switch { + case aCoins == nil && bCoins == nil: + return 0 + + case aCoins == nil: + return -1 + + case bCoins == nil: + return 1 + + default: + switch { + case aCoins.IsAllGT(bCoins): + return 1 + + case aCoins.IsAllLT(bCoins): + return -1 + + default: + return 0 + } + } + }, + MinValue: "", + } +} + // NewConstructorMempool returns a new ConstructorMempool. func NewConstructorMempool[C comparable](txPriority TxPriority[C], txEncoder sdk.TxEncoder, maxTx int) *ConstructorMempool[C] { return &ConstructorMempool[C]{