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.
This commit is contained in:
Josh Rickmar 2013-10-29 09:35:19 -04:00
parent b2263ba6f5
commit 68cbb4192c

View file

@ -696,22 +696,28 @@ func CreateEncryptedWallet(reply chan []byte, msg *btcjson.Message) {
return return
} }
// Grab a new unique sequence number for tx notifications in new blocks. // Create a new account, with a new JSON ID for transaction
n := <-NewJSONID // notifications.
bw := &BtcWallet{ bw := &BtcWallet{
Wallet: wlt, Wallet: wlt,
name: wname, name: wname,
dirty: true, dirty: true,
NewBlockTxSeqN: n, NewBlockTxSeqN: <-NewJSONID,
} }
// TODO(jrick): only begin tracking wallet if btcwallet is already // TODO(jrick): only begin tracking wallet if btcwallet is already
// connected to btcd. // connected to btcd.
bw.Track() bw.Track()
wallets.m[wname] = bw wallets.m[wname] = bw
// Write new wallet to disk.
if err := bw.writeDirtyToDisk(); err != nil { if err := bw.writeDirtyToDisk(); err != nil {
log.Errorf("cannot sync dirty wallet: %v", err) 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) ReplySuccess(reply, msg.Id, nil)
} }