From 39259bee37abe24ea2f737da4f1d9afff7be615f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 22 Aug 2013 12:00:37 -0400 Subject: [PATCH] Notify frontends when wallet is locked or unlocked. --- cmdmgr.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmdmgr.go b/cmdmgr.go index fce8f13..2a256ef 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -277,6 +277,7 @@ func WalletLock(reply chan []byte, msg []byte) { ReplyError(reply, v["id"], &WalletWrongEncState) } else { ReplySuccess(reply, v["id"], nil) + NotifyWalletLockStateChange(reply, true) } } } @@ -307,9 +308,23 @@ func WalletPassphrase(reply chan []byte, msg []byte) { return } ReplySuccess(reply, v["id"], nil) + NotifyWalletLockStateChange(reply, false) go func() { time.Sleep(time.Second * time.Duration(int64(timeout))) w.Lock() + NotifyWalletLockStateChange(reply, true) }() } } + +// NotifyWalletLockStateChange sends a notification to all frontends +// that the wallet has just been locked or unlocked. +func NotifyWalletLockStateChange(reply chan []byte, locked bool) { + var id interface{} = "btcwallet:newwalletlockstate" + m := btcjson.Reply{ + Result: locked, + Id: &id, + } + msg, _ := json.Marshal(&m) + frontendNotificationMaster <- msg +}