diff --git a/core/txpool/interface.go b/core/txpool/interface.go index 7a3c807..df82a3f 100644 --- a/core/txpool/interface.go +++ b/core/txpool/interface.go @@ -26,17 +26,16 @@ type ItxPool interface { CheckTxn(stxn *SignedTxn) error Insert(txn *SignedTxn) error + InsertWithTopic(topic string, stxn *SignedTxn) error + SetOrder(order map[int]Hash) SortTxns(fn func(txns []*SignedTxn) []*SignedTxn) - InsertWithTopic(topic string, stxn *SignedTxn) error - GetWithTopic(topic string, numLimit uint64) []*SignedTxn - GetWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) []*SignedTxn - // Pack packs some txns to send to tripods Pack(numLimit uint64) ([]*SignedTxn, error) - PackFor(numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error) + PackWithTopic(topic string, numLimit uint64) ([]*SignedTxn, error) + PackWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error) // GetTxn returns unpacked txn GetTxn(hash Hash) (*SignedTxn, error) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 6aaef23..4b133db 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -110,20 +110,20 @@ func (tp *TxPool) InsertWithTopic(topic string, stxn *SignedTxn) error { return tp.topicUnpackedTxns[topic].Insert(stxn) } -func (tp *TxPool) GetWithTopic(topic string, numLimit uint64) []*SignedTxn { +func (tp *TxPool) PackWithTopic(topic string, numLimit uint64) ([]*SignedTxn, error) { if unpack, ok := tp.topicUnpackedTxns[topic]; ok { - return unpack.Gets(numLimit, tp.filter) + return unpack.Gets(numLimit, tp.filter), nil } - return nil + return nil, nil } -func (tp *TxPool) GetWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) []*SignedTxn { +func (tp *TxPool) PackWithTopicFor(topic string, numLimit uint64, filter func(txn *SignedTxn) bool) ([]*SignedTxn, error) { tp.topicLock.RLock() defer tp.topicLock.RUnlock() if unpack, ok := tp.topicUnpackedTxns[topic]; ok { - return unpack.Gets(numLimit, filter) + return unpack.Gets(numLimit, filter), nil } - return nil + return nil, nil } func (tp *TxPool) SetOrder(order map[int]Hash) {