here i add `pkg/zmq`, a package aimed at providing one with the ability
of subscribing to zmq topics that the monero daemon published messages
to.
as exaplined under [1], there are four topics that one can subscribe to:
- json-minimal-txpool_add
- json-full-txpool_add
- json-minimal-chain_main
- json-full-chain_main
in the implementation provided here, one goes about listening to these
by:
1. creating a client aiming at a topic
2. telling the client to listen
3. consuming typed objects from a "stream" object
e.g.:
client := zmq.NewClient(endpoint, zmq.TopicMinimalTxPoolAdd)
defer client.Close()
stream, _ := client.Listen(ctx)
for {
select {
case err := <-stream.ErrC:
panic(err)
case tx := <-stream.MinimalTxPoolAddC:
fmt.Println(tx)
}
}
CLI users can also make use of it via `monero daemon zmq`:
$ monero daemon zmq \
--topic json-minimal-chain_main \
--endpoint tcp://127.0.0.1:18085
[1]: https://github.com/monero-project/monero/blob/master/docs/ZMQ.md
Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>