diff --git a/cmd.go b/cmd.go index 71cacb6..30d05ea 100644 --- a/cmd.go +++ b/cmd.go @@ -73,7 +73,7 @@ func main() { log.Info("Unable to connect to btcd. Retrying in 5 seconds.") time.Sleep(5 * time.Second) } else if err != nil { - log.Info(err.Error()) + log.Error(err) break } } diff --git a/cmdmgr.go b/cmdmgr.go index cbdf067..9b2d6ca 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -336,10 +336,22 @@ func CreateEncryptedWallet(reply chan []byte, msg []byte) { return } - wallets.Lock() - wallets.m[wname] = &BtcWallet{ - Wallet: w, + // Grab a new unique sequence number for tx notifications in new blocks. + seq.Lock() + n := seq.n + seq.n++ + seq.Unlock() + + bw := &BtcWallet{ + Wallet: w, + NewBlockTxSeqN: n, } + // TODO(jrick): only begin tracking wallet if btcwallet is already + // connected to btcd. + bw.Track() + + wallets.Lock() + wallets.m[wname] = bw wallets.Unlock() ReplySuccess(reply, v["id"], nil) } diff --git a/sockets.go b/sockets.go index d654242..a294eeb 100644 --- a/sockets.go +++ b/sockets.go @@ -45,6 +45,10 @@ var ( // Messages sent to this channel are sent to each connected frontend. frontendNotificationMaster = make(chan []byte, 100) + // replyHandlers maps between a sequence number (passed as part of + // the JSON Id field) and a function to handle a reply or notification + // from btcd. As requests are received, this map is checked for a + // handler function to route the reply to. replyHandlers = struct { sync.Mutex m map[uint64]func(interface{}) bool