Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func Test() (*rpcclient.Client, error) {
- // 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 rpcclient.
- // NotificationHandlers type for more details about each handler.
- ntfnHandlers := rpcclient.NotificationHandlers{
- OnBlockConnected: func(blockHeader []byte, transactions [][]byte) {
- log.Printf("Block connected: %v %v", blockHeader, transactions)
- },
- OnBlockDisconnected: func(blockHeader []byte) {
- log.Printf("Block disconnected: %v", blockHeader)
- },
- }
- // Connect to local dcrd RPC server using websockets.
- certs, err := ioutil.ReadFile(Env.DcrdCertFilePath)
- if err != nil {
- return nil, err
- }
- connCfg := &rpcclient.ConnConfig{
- Host: fmt.Sprintf("%s:%d", Env.DcrdHost, Env.DcrdPort),
- Endpoint: "ws",
- User: Env.DcrdUser,
- Pass: Env.DcrdPass,
- Certificates: certs,
- }
- client, err := rpcclient.New(connCfg, &ntfnHandlers)
- if err != nil {
- return nil, err
- }
- // Register for block connect and disconnect notifications.
- if err := client.NotifyBlocks(); err != nil {
- return nil, err
- }
- c := make(chan os.Signal)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- // For this example gracefully shutdown the client after 10 seconds.
- // Ordinarily when to shutdown the client is highly application
- // specific.
- client.Shutdown()
- // Wait until the client either shuts down gracefully (or the user
- // terminates the process with Ctrl+C).
- client.WaitForShutdown()
- }()
- addr, err := client.GetNewAddress("default")
- log.Println(addr, err) // error here
- return client, nil
- }
Add Comment
Please, Sign In to add comment