Created
May 31, 2019 20:57
-
-
Save fguisso/515ca8d38291c39068bbb5566e0bbbc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"io/ioutil" | |
"path/filepath" | |
"time" | |
"github.com/decred/dcrd/dcrutil" | |
"github.com/decred/dcrd/rpcclient" | |
) | |
func main() { | |
ntfnHandlers := rpcclient.NotificationHandlers{ | |
OnBlockConnected: func(blockHeader []byte, transactions [][]byte) { | |
log.Printf("Block connected: %v %v", blockHeader, transactions) | |
client.generate() | |
} | |
} | |
dcrdHomeDir := dcrutil.AppDataDir("dcrd", false) | |
certs, err := ioutil.ReadFile(filepath.Join(dcrdHomeDir, "rpc.cert")) | |
if err != nil { | |
log.Fatal(err) | |
} | |
connCfg := &rpcclient.ConnConfig{ | |
Host: "localhost:19109", | |
Endpoint: "ws", | |
User: "", | |
Pass: "", | |
Certificates: certs, | |
} | |
client, err := rpcclient.New(connCfg, &ntfnHandlers) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if err := client.NotifyBlocks(); err != nil { | |
log.Fatal(err) | |
} | |
log.Println("NotifyBlocks: Registration Complete") | |
block_hash, err := client.Generate(1) | |
if err != nil { | |
log.Fatal(err) | |
} | |
client.WaitForShutdown() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment