From b2263ba6f5c017f77b1be80f9b115863a1a5b7ca Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 29 Oct 2013 09:19:11 -0400 Subject: [PATCH] Notify connecting frontends of btcd connect state. This change automatically sends the btcdconnected notification for all frontends as they connect to btcwallet. The old btcdconnected command has been removed, as it is no longer needed for clients to explicitly request this information any longer. --- cmdmgr.go | 9 --------- sockets.go | 22 +++++++++++++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cmdmgr.go b/cmdmgr.go index e576bbb..2030212 100644 --- a/cmdmgr.go +++ b/cmdmgr.go @@ -65,8 +65,6 @@ func ProcessFrontendMsg(reply chan []byte, msg []byte) { GetBalances(reply, &jsonMsg) case "walletislocked": WalletIsLocked(reply, &jsonMsg) - case "btcdconnected": - BtcdConnected(reply, &jsonMsg) default: // btcwallet does not understand method. Pass to btcd. @@ -794,13 +792,6 @@ func WalletPassphrase(reply chan []byte, msg *btcjson.Message) { } } -// BtcdConnected is the wallet handler for the frontend -// 'btcdconnected' method. It returns to the frontend whether btcwallet -// is currently connected to btcd or not. -func BtcdConnected(reply chan []byte, msg *btcjson.Message) { - ReplySuccess(reply, msg.Id, btcdConnected.b) -} - // AccountNtfn is a struct for marshalling any generic notification // about a account for a wallet frontend. // diff --git a/sockets.go b/sockets.go index 16861b0..db0a17e 100644 --- a/sockets.go +++ b/sockets.go @@ -108,6 +108,8 @@ func frontendListenerDuplicator() { // TODO(jrick): these notifications belong somewhere better. // Probably want to copy AddWalletListener from btcd, and // place these notifications in that function. + NotifyBtcdConnected(frontendNotificationMaster, + btcdConnected.b) if btcdConnected.b { NotifyNewBlockChainHeight(c, getCurHeight()) NotifyBalances(c) @@ -128,13 +130,8 @@ func frontendListenerDuplicator() { select { case conn := <-btcdConnected.c: - btcdConnected.b = conn - var idStr interface{} = "btcwallet:btcdconnected" - r := btcjson.Reply{ - Result: conn, - Id: &idStr, - } - ntfn, _ = json.Marshal(r) + NotifyBtcdConnected(frontendNotificationMaster, conn) + continue case ntfn = <-frontendNotificationMaster: } @@ -147,6 +144,17 @@ func frontendListenerDuplicator() { } } +func NotifyBtcdConnected(reply chan []byte, conn bool) { + btcdConnected.b = conn + var idStr interface{} = "btcwallet:btcdconnected" + r := btcjson.Reply{ + Result: conn, + Id: &idStr, + } + ntfn, _ := json.Marshal(r) + frontendNotificationMaster <- ntfn +} + // frontendReqsNotifications is the handler function for websocket // connections from a btcwallet instance. It reads messages from wallet and // sends back replies, as well as notififying wallets of chain updates.