Skip to content

Commit

Permalink
feat: implement message pool tx submitter option
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Aug 10, 2022
1 parent 8fece85 commit c881f68
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/client/message_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
// MessagePool atomically manage a pool of messages waiting to be sent through a transaction. It also allows to
// subscribe to the transaction response once submitted to receive it through a channel.
type MessagePool struct {
mut *sync.Mutex
txFunc TxSubmitter
msgs []*types.Msg
subscribers []chan *types.TxResponse
mut *sync.Mutex
submitterFunc TxSubmitter
msgs []*types.Msg
subscribers []chan *types.TxResponse
}

// TxSubmitter shall implement all the logic to build, sign and submit a transaction containing all the messages of the
Expand All @@ -35,6 +35,12 @@ func NewMessagePool(opts ...MessagePoolOption) *MessagePool {
return pool
}

func WithTxSubmitter(submitterFunc TxSubmitter) MessagePoolOption {
return func(pool *MessagePool) {
pool.submitterFunc = submitterFunc
}
}

// RegisterMsg atomically add the message in the pool.
func (pool *MessagePool) RegisterMsg(msg *types.Msg) {
pool.lock()
Expand Down Expand Up @@ -72,7 +78,7 @@ func (pool *MessagePool) Submit() error {
pool.unlock()
}()

resp, err := pool.txFunc(pool.msgs)
resp, err := pool.submitterFunc(pool.msgs)
if err != nil {
return err
}
Expand Down

0 comments on commit c881f68

Please sign in to comment.