diff --git a/rpc.go b/rpc.go index a1632a5..d1816b8 100644 --- a/rpc.go +++ b/rpc.go @@ -113,6 +113,14 @@ func GetCurrentNet(rpc RPCConn) (btcwire.BitcoinNet, *btcjson.Error) { return btcwire.BitcoinNet(uint32(response.Result.(float64))), nil } +// NotifyBlocks requests blockconnected and blockdisconnected notifications. +func NotifyBlocks(rpc RPCConn) *btcjson.Error { + cmd := btcws.NewNotifyBlocksCmd(<-NewJSONID) + request := NewRPCRequest(cmd, nil) + response := <-rpc.SendRequest(request) + return response.Err +} + // NotifyNewTXs requests notifications for new transactions that spend // to any of the addresses in addrs. func NotifyNewTXs(rpc RPCConn, addrs []string) *btcjson.Error { diff --git a/sockets.go b/sockets.go index dd84059..0d5053f 100644 --- a/sockets.go +++ b/sockets.go @@ -507,6 +507,9 @@ func Handshake(rpc RPCConn) error { return errors.New("btcd and btcwallet running on different Bitcoin networks") } + // Request notifications for connected and disconnected blocks. + NotifyBlocks(rpc) + // Get current best block. If this is before than the oldest // saved block hash, assume that this btcd instance is not yet // synced up to a previous btcd that was last used with this