fix(config)!: Auction mempool inherits config interface (#82)
This commit is contained in:
parent
e5be99baa1
commit
5f5a1c1737
@ -27,6 +27,9 @@ type (
|
||||
// bundle transaction i.e. transaction that was included in the auction transaction's bundle.
|
||||
GetTransactionSigners(tx []byte) (map[string]struct{}, error)
|
||||
|
||||
// GetBundleSigners defines a function that returns the signers of every transaction in a bundle.
|
||||
GetBundleSigners(tx [][]byte) ([]map[string]struct{}, error)
|
||||
|
||||
// WrapBundleTransaction defines a function that wraps a bundle transaction into a sdk.Tx.
|
||||
WrapBundleTransaction(tx []byte) (sdk.Tx, error)
|
||||
|
||||
@ -42,6 +45,9 @@ type (
|
||||
|
||||
// GetTimeout defines a function that returns the timeout of an auction transaction.
|
||||
GetTimeout(tx sdk.Tx) (uint64, error)
|
||||
|
||||
// GetAuctionBidInfo defines a function that returns the bid info from an auction transaction.
|
||||
GetAuctionBidInfo(tx sdk.Tx) (AuctionBidInfo, error)
|
||||
}
|
||||
|
||||
// DefaultConfig defines a default configuration for processing auction transactions.
|
||||
@ -98,6 +104,24 @@ func (config *DefaultConfig) GetTransactionSigners(tx []byte) (map[string]struct
|
||||
return signers, nil
|
||||
}
|
||||
|
||||
// GetBundleSigners defines a default function that returns the signers of every transaction
|
||||
// in a bundle. In the default case, each bundle transaction will be an sdk.Tx and the
|
||||
// signers are the signers of each sdk.Msg in the transaction.
|
||||
func (config *DefaultConfig) GetBundleSigners(txs [][]byte) ([]map[string]struct{}, error) {
|
||||
signers := make([]map[string]struct{}, len(txs))
|
||||
|
||||
for index, tx := range txs {
|
||||
txSigners, err := config.GetTransactionSigners(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
signers[index] = txSigners
|
||||
}
|
||||
|
||||
return signers, nil
|
||||
}
|
||||
|
||||
// WrapBundleTransaction defines a default function that wraps a transaction
|
||||
// that is included in the bundle into a sdk.Tx. In the default case, the transaction
|
||||
// that is included in the bundle will be the raw bytes of an sdk.Tx so we can just
|
||||
@ -109,6 +133,15 @@ func (config *DefaultConfig) WrapBundleTransaction(tx []byte) (sdk.Tx, error) {
|
||||
// GetBidder defines a default function that returns the bidder of an auction transaction.
|
||||
// In the default case, the bidder is the address defined in MsgAuctionBid.
|
||||
func (config *DefaultConfig) GetBidder(tx sdk.Tx) (sdk.AccAddress, error) {
|
||||
isAuctionTx, err := config.IsAuctionTx(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isAuctionTx {
|
||||
return nil, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
msg, err := GetMsgAuctionBidFromTx(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -125,6 +158,15 @@ func (config *DefaultConfig) GetBidder(tx sdk.Tx) (sdk.AccAddress, error) {
|
||||
// GetBid defines a default function that returns the bid of an auction transaction.
|
||||
// In the default case, the bid is the amount defined in MsgAuctionBid.
|
||||
func (config *DefaultConfig) GetBid(tx sdk.Tx) (sdk.Coin, error) {
|
||||
isAuctionTx, err := config.IsAuctionTx(tx)
|
||||
if err != nil {
|
||||
return sdk.Coin{}, err
|
||||
}
|
||||
|
||||
if !isAuctionTx {
|
||||
return sdk.Coin{}, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
msg, err := GetMsgAuctionBidFromTx(tx)
|
||||
if err != nil {
|
||||
return sdk.Coin{}, err
|
||||
@ -138,6 +180,15 @@ func (config *DefaultConfig) GetBid(tx sdk.Tx) (sdk.Coin, error) {
|
||||
// the bundled transactions will be the raw bytes of sdk.Tx's that are included in the
|
||||
// MsgAuctionBid.
|
||||
func (config *DefaultConfig) GetBundledTransactions(tx sdk.Tx) ([][]byte, error) {
|
||||
isAuctionTx, err := config.IsAuctionTx(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isAuctionTx {
|
||||
return nil, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
msg, err := GetMsgAuctionBidFromTx(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -155,3 +206,33 @@ func (config *DefaultConfig) GetTimeout(tx sdk.Tx) (uint64, error) {
|
||||
|
||||
return timeoutTx.GetTimeoutHeight(), nil
|
||||
}
|
||||
|
||||
// GetAuctionBidInfo returns the auction bid info from an auction transaction.
|
||||
func (config *DefaultConfig) GetAuctionBidInfo(tx sdk.Tx) (AuctionBidInfo, error) {
|
||||
bid, err := config.GetBid(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
bidder, err := config.GetBidder(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
bundle, err := config.GetBundledTransactions(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
timeout, err := config.GetTimeout(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
return AuctionBidInfo{
|
||||
Bid: bid,
|
||||
Bidder: bidder,
|
||||
Transactions: bundle,
|
||||
Timeout: timeout,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -38,8 +38,8 @@ type AuctionMempool struct {
|
||||
// to quickly check if a transaction is already in the mempool.
|
||||
txIndex map[string]struct{}
|
||||
|
||||
// config defines the transaction configuration for processing auction transactions.
|
||||
config Config
|
||||
// Config defines the transaction configuration for processing auction transactions.
|
||||
Config
|
||||
}
|
||||
|
||||
// AuctionTxPriority returns a TxPriority over auction bid transactions only. It
|
||||
@ -102,7 +102,7 @@ func NewAuctionMempool(txDecoder sdk.TxDecoder, txEncoder sdk.TxEncoder, maxTx i
|
||||
txDecoder: txDecoder,
|
||||
txEncoder: txEncoder,
|
||||
txIndex: make(map[string]struct{}),
|
||||
config: config,
|
||||
Config: config,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
package mempool
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// IsAuctionTx returns true if the transaction is a transaction that is attempting to
|
||||
// bid to the auction.
|
||||
func (am *AuctionMempool) IsAuctionTx(tx sdk.Tx) (bool, error) {
|
||||
return am.config.IsAuctionTx(tx)
|
||||
}
|
||||
|
||||
// GetTransactionSigners returns the signers of the bundle transaction.
|
||||
func (am *AuctionMempool) GetTransactionSigners(tx []byte) (map[string]struct{}, error) {
|
||||
return am.config.GetTransactionSigners(tx)
|
||||
}
|
||||
|
||||
// WrapBundleTransaction wraps a bundle transaction into sdk.Tx transaction.
|
||||
func (am *AuctionMempool) WrapBundleTransaction(tx []byte) (sdk.Tx, error) {
|
||||
return am.config.WrapBundleTransaction(tx)
|
||||
}
|
||||
|
||||
// GetAuctionBidInfo returns the bid info from an auction transaction.
|
||||
func (am *AuctionMempool) GetAuctionBidInfo(tx sdk.Tx) (AuctionBidInfo, error) {
|
||||
bidder, err := am.GetBidder(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
bid, err := am.GetBid(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
transactions, err := am.GetBundledTransactions(tx)
|
||||
if err != nil {
|
||||
return AuctionBidInfo{}, err
|
||||
}
|
||||
|
||||
return AuctionBidInfo{
|
||||
Bidder: bidder,
|
||||
Bid: bid,
|
||||
Transactions: transactions,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetBidder returns the bidder from an auction transaction.
|
||||
func (am *AuctionMempool) GetBidder(tx sdk.Tx) (sdk.AccAddress, error) {
|
||||
if isAuctionTx, err := am.IsAuctionTx(tx); err != nil || !isAuctionTx {
|
||||
return nil, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
return am.config.GetBidder(tx)
|
||||
}
|
||||
|
||||
// GetBid returns the bid from an auction transaction.
|
||||
func (am *AuctionMempool) GetBid(tx sdk.Tx) (sdk.Coin, error) {
|
||||
if isAuctionTx, err := am.IsAuctionTx(tx); err != nil || !isAuctionTx {
|
||||
return sdk.Coin{}, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
return am.config.GetBid(tx)
|
||||
}
|
||||
|
||||
// GetBundledTransactions returns the transactions that are bundled in an auction transaction.
|
||||
func (am *AuctionMempool) GetBundledTransactions(tx sdk.Tx) ([][]byte, error) {
|
||||
if isAuctionTx, err := am.IsAuctionTx(tx); err != nil || !isAuctionTx {
|
||||
return nil, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
return am.config.GetBundledTransactions(tx)
|
||||
}
|
||||
|
||||
// GetTimeout returns the timeout of an auction transaction.
|
||||
func (am *AuctionMempool) GetTimeout(tx sdk.Tx) (uint64, error) {
|
||||
if isAuctionTx, err := am.IsAuctionTx(tx); err != nil || !isAuctionTx {
|
||||
return 0, fmt.Errorf("transaction is not an auction transaction")
|
||||
}
|
||||
|
||||
return am.config.GetTimeout(tx)
|
||||
}
|
||||
|
||||
// GetBundleSigners returns all of the signers for each transaction in the bundle.
|
||||
func (am *AuctionMempool) GetBundleSigners(txs [][]byte) ([]map[string]struct{}, error) {
|
||||
signers := make([]map[string]struct{}, len(txs))
|
||||
|
||||
for index, tx := range txs {
|
||||
txSigners, err := am.GetTransactionSigners(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
signers[index] = txSigners
|
||||
}
|
||||
|
||||
return signers, nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user