This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
go-monero/pkg/zmq/types.go
Ciro S. Costa ac58bd1fd1 add zmq support
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>
2021-07-28 07:37:23 -04:00

105 lines
2.9 KiB
Go

package zmq
type Topic string
const (
TopicUnknown Topic = "unknown"
TopicMinimalTxPoolAdd Topic = "json-minimal-txpool_add"
TopicFullTxPoolAdd Topic = "json-full-txpool_add"
TopicMinimalChainMain Topic = "json-minimal-chain_main"
TopicFullChainMain Topic = "json-full-chain_main"
)
type MinimalChainMain struct {
FirstHeight uint64 `json:"first_height"`
FirstPrevID string `json:"first_prev_id"`
Ids []string `json:"ids"`
}
type FullChainMain struct {
MajorVersion int `json:"major_version"`
MinorVersion int `json:"minor_version"`
Timestamp int64 `json:"timestamp"`
PrevID string `json:"prev_id"`
Nonce uint64 `json:"nonce"`
MinerTx struct {
Version int `json:"version"`
UnlockTime int64 `json:"unlock_time"`
Inputs []struct {
Gen struct {
Height uint64 `json:"height"`
} `json:"gen"`
} `json:"inputs"`
Outputs []struct {
Amount uint64 `json:"amount"`
ToKey struct {
Key string `json:"key"`
} `json:"to_key"`
} `json:"outputs"`
Extra string `json:"extra"`
Signatures []interface{} `json:"signatures"`
Ringct struct {
Type int `json:"type"`
Encrypted []interface{} `json:"encrypted"`
Commitments []interface{} `json:"commitments"`
Fee uint64 `json:"fee"`
} `json:"ringct"`
} `json:"miner_tx"`
TxHashes []string `json:"tx_hashes"`
}
type MinimalTxPoolAdd struct {
ID string `json:"id"`
BlobSize uint64 `json:"blob_size"`
}
type FullTxPoolAdd struct {
Version int `json:"version"`
UnlockTime int64 `json:"unlock_time"`
Inputs []struct {
ToKey struct {
Amount uint64 `json:"amount"`
KeyOffsets []uint64 `json:"key_offsets"`
KeyImage string `json:"key_image"`
} `json:"to_key"`
} `json:"inputs"`
Outputs []struct {
Amount int `json:"amount"`
ToKey struct {
Key string `json:"key"`
} `json:"to_key"`
} `json:"outputs"`
Extra string `json:"extra"`
Signatures []interface{} `json:"signatures"`
Ringct struct {
Type int `json:"type"`
Encrypted []struct {
Mask string `json:"mask"`
Amount string `json:"amount"`
} `json:"encrypted"`
Commitments []string `json:"commitments"`
Fee int `json:"fee"`
Prunable struct {
RangeProofs []interface{} `json:"range_proofs"`
Bulletproofs []struct {
V []string `json:"V"`
AUpper string `json:"A"`
S string `json:"S"`
T1 string `json:"T1"`
T2 string `json:"T2"`
Taux string `json:"taux"`
Mu string `json:"mu"`
L []string `json:"L"`
R []string `json:"R"`
ALower string `json:"a"`
B string `json:"b"`
T string `json:"t"`
} `json:"bulletproofs"`
Mlsags []interface{} `json:"mlsags"`
PseudoOuts []string `json:"pseudo_outs"`
} `json:"prunable"`
} `json:"ringct"`
}