Track opened wallets after establishing btcd connection.
This commit is contained in:
parent
019df772b1
commit
ed98256553
2 changed files with 13 additions and 21 deletions
27
cmd.go
27
cmd.go
|
@ -60,7 +60,9 @@ func main() {
|
|||
if err != nil {
|
||||
log.Info(err.Error())
|
||||
} else {
|
||||
w.Track()
|
||||
wallets.Lock()
|
||||
wallets.m[""] = w
|
||||
wallets.Unlock()
|
||||
}
|
||||
|
||||
// Start HTTP server to listen and send messages to frontend and btcd
|
||||
|
@ -189,26 +191,9 @@ func (w *BtcWallet) Track() {
|
|||
seq.n++
|
||||
seq.Unlock()
|
||||
|
||||
// Use goroutines and a WaitGroup to prevent unnecessary waiting for
|
||||
// released locks.
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wallets.Lock()
|
||||
name := w.Name()
|
||||
if wallets.m[name] == nil {
|
||||
wallets.m[name] = w
|
||||
}
|
||||
wallets.Unlock()
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
w.mtx.Lock()
|
||||
w.NewBlockTxSeqN = n
|
||||
w.mtx.Unlock()
|
||||
}()
|
||||
wg.Wait()
|
||||
w.mtx.Lock()
|
||||
w.NewBlockTxSeqN = n
|
||||
w.mtx.Unlock()
|
||||
|
||||
replyHandlers.Lock()
|
||||
replyHandlers.m[n] = w.NewBlockTxHandler
|
||||
|
|
|
@ -313,6 +313,13 @@ func ListenAndServe() error {
|
|||
|
||||
log.Info("Established connection to btcd.")
|
||||
|
||||
// Begin tracking wallets.
|
||||
wallets.RLock()
|
||||
for _, w := range wallets.m {
|
||||
w.Track()
|
||||
}
|
||||
wallets.RUnlock()
|
||||
|
||||
// We'll need to duplicate replies to frontends to each frontend.
|
||||
// Replies are sent to frontendReplyMaster, and duplicated to each valid
|
||||
// channel in frontendReplySet. This runs a goroutine to duplicate
|
||||
|
|
Loading…
Add table
Reference in a new issue