From eb82f35aacc8708b15844d7f81edc15db0a66f23 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 9 May 2014 00:44:19 -0500 Subject: [PATCH] Improve btcdwebsockets example. Since the example illustrates callbacks for the OnBlockConnected and OnBlockDisconnected callbacks, also register for the notifications with NotifyBlocks. While here, document the fact that most of the callbacks require registration. --- examples/btcdwebsockets/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/btcdwebsockets/main.go b/examples/btcdwebsockets/main.go index 69b1092d..4d3efa08 100644 --- a/examples/btcdwebsockets/main.go +++ b/examples/btcdwebsockets/main.go @@ -5,9 +5,9 @@ package main import ( + "github.com/conformal/btcrpcclient" "github.com/conformal/btcutil" "github.com/conformal/btcwire" - "github.com/conformal/btcrpcclient" "io/ioutil" "log" "path/filepath" @@ -16,6 +16,9 @@ import ( func main() { // Only override the handlers for notifications you care about. + // Also note most of these handlers will only be called if you register + // for notifications. See the documentation of the btcrpcclient + // NotificationHandlers type for more details about each handler. ntfnHandlers := btcrpcclient.NotificationHandlers{ OnBlockConnected: func(hash *btcwire.ShaHash, height int32) { log.Printf("Block connected: %v (%d)", hash, height) @@ -43,6 +46,12 @@ func main() { log.Fatal(err) } + // Register for block connect and disconnect notifications. + if err := client.NotifyBlocks(); err != nil { + log.Fatal(err) + } + log.Println("NotifyBlocks: Registration Complete") + // Get the current block count. blockCount, err := client.GetBlockCount() if err != nil {