github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/transactionpool/subscribe.go (about) 1 package transactionpool 2 3 import ( 4 "github.com/NebulousLabs/Sia/modules" 5 "github.com/NebulousLabs/Sia/types" 6 ) 7 8 // updateSubscribersTransactions sends a new transaction pool update to all 9 // subscribers. 10 func (tp *TransactionPool) updateSubscribersTransactions() { 11 var txns []types.Transaction 12 var cc modules.ConsensusChange 13 for _, tSet := range tp.transactionSets { 14 txns = append(txns, tSet...) 15 } 16 for _, tSetDiff := range tp.transactionSetDiffs { 17 cc = cc.Append(tSetDiff) 18 } 19 for _, subscriber := range tp.subscribers { 20 subscriber.ReceiveUpdatedUnconfirmedTransactions(txns, cc) 21 } 22 } 23 24 // TransactionPoolSubscribe adds a subscriber to the transaction pool. 25 // Subscribers will receive the full transaction set every time there is a 26 // significant change to the transaction pool. 27 func (tp *TransactionPool) TransactionPoolSubscribe(subscriber modules.TransactionPoolSubscriber) { 28 tp.mu.Lock() 29 defer tp.mu.Unlock() 30 31 // Add the subscriber to the subscriber list. 32 tp.subscribers = append(tp.subscribers, subscriber) 33 34 // Send the new subscriber the transaction pool set. 35 var txns []types.Transaction 36 for _, tSet := range tp.transactionSets { 37 txns = append(txns, tSet...) 38 } 39 var cc modules.ConsensusChange 40 for _, tSetDiff := range tp.transactionSetDiffs { 41 cc = cc.Append(tSetDiff) 42 } 43 subscriber.ReceiveUpdatedUnconfirmedTransactions(txns, cc) 44 }