refactor(network): simplify local state mini-protocol implementation (#326)
This commit is contained in:
parent
aae7d92b44
commit
e0f9f14dea
11 changed files with 599 additions and 547 deletions
|
|
@ -1,19 +1,30 @@
|
|||
use pallas::network::{
|
||||
facades::NodeClient,
|
||||
miniprotocols::{chainsync, localstate, Point, MAINNET_MAGIC},
|
||||
miniprotocols::{chainsync, localstate::queries_v16, Point, PRE_PRODUCTION_MAGIC},
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
async fn do_localstate_query(client: &mut NodeClient) {
|
||||
client.statequery().acquire(None).await.unwrap();
|
||||
let client = client.statequery();
|
||||
|
||||
let result = client
|
||||
.statequery()
|
||||
.query(localstate::queries::Request::GetSystemStart)
|
||||
client.acquire(None).await.unwrap();
|
||||
|
||||
let result = queries_v16::get_chain_point(client).await.unwrap();
|
||||
info!("result: {:?}", result);
|
||||
|
||||
let result = queries_v16::get_system_start(client).await.unwrap();
|
||||
info!("result: {:?}", result);
|
||||
|
||||
let era = queries_v16::get_current_era(client).await.unwrap();
|
||||
info!("result: {:?}", era);
|
||||
|
||||
let result = queries_v16::get_block_epoch_number(client, era)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
info!("system start result: {:?}", result);
|
||||
info!("result: {:?}", result);
|
||||
|
||||
client.send_release().await.unwrap();
|
||||
}
|
||||
|
||||
async fn do_chainsync(client: &mut NodeClient) {
|
||||
|
|
@ -43,6 +54,10 @@ async fn do_chainsync(client: &mut NodeClient) {
|
|||
}
|
||||
}
|
||||
|
||||
// change the following to match the Cardano node socket in your local
|
||||
// environment
|
||||
const SOCKET_PATH: &str = "/tmp/node.socket";
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
|
@ -55,15 +70,7 @@ async fn main() {
|
|||
|
||||
// we connect to the unix socket of the local node. Make sure you have the right
|
||||
// path for your environment
|
||||
let socket_path = "/tmp/node.socket";
|
||||
|
||||
// we connect to the unix socket of the local node and perform a handshake query
|
||||
let version_table = NodeClient::handshake_query(socket_path, MAINNET_MAGIC)
|
||||
.await
|
||||
.unwrap();
|
||||
info!("handshake query result: {:?}", version_table);
|
||||
|
||||
let mut client = NodeClient::connect(socket_path, MAINNET_MAGIC)
|
||||
let mut client = NodeClient::connect(SOCKET_PATH, PRE_PRODUCTION_MAGIC)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -75,7 +82,6 @@ async fn main() {
|
|||
}
|
||||
|
||||
#[cfg(not(target_family = "unix"))]
|
||||
|
||||
fn main() {
|
||||
panic!("can't use n2c unix socket on non-unix systems");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue