Created
June 1, 2019 00:08
-
-
Save fguisso/063fedba8f94e6eb3514a8ce4c4c0c2f 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" | |
) | |
type cliente struct { | |
c *rpcclient.Client | |
h *rpcclient.NotificationHandlers | |
} | |
func (c *cliente) OnBlock() { | |
func(blockHeader []byte, transactions [][]byte) { | |
log.Printf("Block connected: %v %v", blockHeader, transactions) | |
count, err := c.GetBlockCount() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
} | |
func main() { | |
cli := &cliente{} | |
cli.h = rpcclient.NotificationHandlers{OnBlock: OnBlockConnected()} | |
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, cli) | |
if err != nil { | |
log.Fatal(err) | |
} | |
cli.c = client | |
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