From 68cbb4192c19c20733e31439b970954558906006 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 29 Oct 2013 09:35:19 -0400 Subject: [PATCH] Notify all frontends of new accounts. When a new account (wallet) is created with the createencryptedwallet JSON method, all frontends, including the one requesting the wallet, must be notified of this new account and its balance (probably zero). This removes the need for frontends to poll and check for any new accounts. --- cmdmgr.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmdmgr.go b/cmdmgr.go index 2030212..6e9d4e4 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -696,22 +696,28 @@ func CreateEncryptedWallet(reply chan []byte, msg *btcjson.Message) { return } - // Grab a new unique sequence number for tx notifications in new blocks. - n := <-NewJSONID + // Create a new account, with a new JSON ID for transaction + // notifications. bw := &BtcWallet{ Wallet: wlt, name: wname, dirty: true, - NewBlockTxSeqN: n, + NewBlockTxSeqN: <-NewJSONID, } // TODO(jrick): only begin tracking wallet if btcwallet is already // connected to btcd. bw.Track() wallets.m[wname] = bw + + // Write new wallet to disk. if err := bw.writeDirtyToDisk(); err != nil { log.Errorf("cannot sync dirty wallet: %v", err) } + + // Notify all frontends of this new account, and its balance. + NotifyBalances(frontendNotificationMaster) + ReplySuccess(reply, msg.Id, nil) }