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.
This commit is contained in:
parent
0e26aa7452
commit
b2263ba6f5
2 changed files with 15 additions and 16 deletions
|
@ -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.
|
||||
//
|
||||
|
|
22
sockets.go
22
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.
|
||||
|
|
Loading…
Reference in a new issue