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.
This commit is contained in:
parent
80f9a8e5e2
commit
eb82f35aac
1 changed files with 10 additions and 1 deletions
|
@ -5,9 +5,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/conformal/btcrpcclient"
|
||||||
"github.com/conformal/btcutil"
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/btcrpcclient"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -16,6 +16,9 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Only override the handlers for notifications you care about.
|
// 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{
|
ntfnHandlers := btcrpcclient.NotificationHandlers{
|
||||||
OnBlockConnected: func(hash *btcwire.ShaHash, height int32) {
|
OnBlockConnected: func(hash *btcwire.ShaHash, height int32) {
|
||||||
log.Printf("Block connected: %v (%d)", hash, height)
|
log.Printf("Block connected: %v (%d)", hash, height)
|
||||||
|
@ -43,6 +46,12 @@ func main() {
|
||||||
log.Fatal(err)
|
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.
|
// Get the current block count.
|
||||||
blockCount, err := client.GetBlockCount()
|
blockCount, err := client.GetBlockCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue