diff --git a/cmd.go b/cmd.go index c023c49..71cacb6 100644 --- a/cmd.go +++ b/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 diff --git a/sockets.go b/sockets.go index e10e6c1..d654242 100644 --- a/sockets.go +++ b/sockets.go @@ -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