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.