Capture all broadcast messages coming from chia_full_node
service.
You need to create Websocket connection before subscribing websocket messages.
const {getDaemon} = require("chia-agent");
const {on_message_from_full_node} = require("chia-agent/api/ws");
const daemon = getDaemon(); // This is the websocket connection handler
await daemon.connect(); // connect to local daemon using config file.
// Capture all messages from `chia_full_node`
const unsubscribe = await on_message_from_full_node(daemon, (event) => {
console.log(e.data);
// Close connection if you don't need it anymore.
if(...){
unsubscribe(); // stop listening to this ws message.
}
});
...
Capture broadcast message of command get_connections
from chia_full_node
service.
const {getDaemon} = require("chia-agent");
const {on_get_connections} = require("chia-agent/api/ws/full_node");
const daemon = getDaemon();
await daemon.connect();
const unsubscribe = await on_get_connections(daemon, (event) => {
// Format of `event` object is described below.
...
});
...
unsubscribe(); // Stop subscribing messages
{
origin: "chia_full_node";
command: "get_connections";
ack: boolean;
data: /*See below*/;
request_id: string;
destination: "wallet_ui";
}
{
connections: TConnectionFullNode[];
}
For content of TConnectionFullNode
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/ws/full_node/index.ts
Capture broadcast message of command get_blockchain_state
from chia_full_node
service.
const {getDaemon} = require("chia-agent");
const {on_get_blockchain_state} = require("chia-agent/api/ws");
const daemon = getDaemon();
await daemon.connect();
const unsubscribe = await on_get_blockchain_state(daemon, (event) => {
// Format of `event` object is described below.
...
});
...
unsubscribe(); // Stop subscribing messages
{
origin: "chia_full_node";
command: "get_blockchain_state";
ack: boolean;
data: /*See below*/;
request_id: string;
destination: "wallet_ui"|"metrics";
}
{
blockchain_state: {
peak: BlockRecord;
genesis_challenge_initialized: bool;
sync: {
sync_mode: bool;
synced: bool;
sync_tip_height: uint32;
sync_progress_height: uint32;
};
difficulty: uint64;
sub_slot_iters: uint64;
space: uint128;
mempool_size: int;
mempool_cost: int;
"mempool_min_fees": {
"cost_5000000": float,
},
"mempool_max_total_cost": int,
"block_max_cost": int,
"node_id": str,
}
}
Capture broadcast message of command block
from chia_full_node
service.
const {getDaemon} = require("chia-agent");
const {on_block} = require("chia-agent/api/ws");
const daemon = getDaemon();
await daemon.connect();
const unsubscribe = await on_block(daemon, (event) => {
// Format of `event` object is described below.
...
});
...
unsubscribe(); // Stop subscribing messages
{
origin: "chia_full_node";
command: "block";
ack: boolean;
data: /*See below*/;
request_id: string;
destination: "metrics";
}
{} | {
transaction_block: bool;
k_size: uint8;
header_hash: bytes32;
height: uint32;
block_cost?: uint64;
block_fees?: uint64;
timestamp?: uint64;
transaction_generator_size_bytes?: int;
transaction_generator_ref_list: uint32[];
receive_block_result?: ReceiveBlockResult;
}
For content of ReceiveBlockResult
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/chia/consensus/blockchain.ts
Capture broadcast message of command signage_point
from chia_full_node
service.
const {getDaemon} = require("chia-agent");
const {on_signage_point} = require("chia-agent/api/ws");
const daemon = getDaemon();
await daemon.connect();
const unsubscribe = await on_signage_point(daemon, (event) => {
// Format of `event` object is described below.
...
});
...
unsubscribe(); // Stop subscribing messages
{
origin: "chia_full_node";
command: "signage_point";
ack: boolean;
data: /*See below*/;
request_id: string;
destination: "metrics";
}
{
broadcast_farmer: NewSignagePoint;
}
For content of NewSignagePoint
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/chia/protocols/farmer_protocol.ts
Capture broadcast message of command unfinished_block
from chia_full_node
service.
const {getDaemon} = require("chia-agent");
const {on_unfinished_block} = require("chia-agent/api/ws");
const daemon = getDaemon();
await daemon.connect();
const unsubscribe = await on_unfinished_block(daemon, (event) => {
// Format of `event` object is described below.
...
});
...
unsubscribe(); // Stop subscribing messages
{
origin: "chia_full_node";
command: "unfinished_block";
ack: boolean;
data: /*See below*/;
request_id: string;
destination: "metrics";
}
{
block_duration_in_seconds: float;
validation_time_in_seconds: float;
pre_validation_time_in_seconds: float | None;
unfinished_block: UnfinishedBlock;
}
For content of UnfinishedBlock
,
see https://github.com/Chia-Mine/chia-agent/blob/main/src/api/chia_rs/chia-protocol/unfinished_block.ts