github.com/btcsuite/btcd@v0.24.0/rpcclient/zmq.go (about) 1 package rpcclient 2 3 import ( 4 "encoding/json" 5 6 "github.com/btcsuite/btcd/btcjson" 7 ) 8 9 // FutureGetZmqNotificationsResult is a future promise to deliver the result of 10 // a GetZmqNotifications RPC invocation 11 type FutureGetZmqNotificationsResult chan *Response 12 13 // Receive waits for the response promised by the future and returns the unmarshalled 14 // response, or an error if the request was unsuccessful. 15 func (r FutureGetZmqNotificationsResult) Receive() (btcjson.GetZmqNotificationResult, error) { 16 res, err := ReceiveFuture(r) 17 if err != nil { 18 return nil, err 19 } 20 var notifications btcjson.GetZmqNotificationResult 21 if err := json.Unmarshal(res, ¬ifications); err != nil { 22 return nil, err 23 } 24 return notifications, nil 25 } 26 27 // GetZmqNotificationsAsync returns an instance ofa type that can be used to get 28 // the result of a custom RPC request at some future time by invoking the Receive 29 // function on the returned instance. 30 // 31 // See GetZmqNotifications for the blocking version and more details. 32 func (c *Client) GetZmqNotificationsAsync() FutureGetZmqNotificationsResult { 33 return c.SendCmd(btcjson.NewGetZmqNotificationsCmd()) 34 } 35 36 // GetZmqNotifications returns information about the active ZeroMQ notifications. 37 func (c *Client) GetZmqNotifications() (btcjson.GetZmqNotificationResult, error) { 38 return c.GetZmqNotificationsAsync().Receive() 39 }