Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Nov 9, 2023
1 parent 841f21e commit 67b0100
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
33 changes: 13 additions & 20 deletions examples/n2c-miniprotocols/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
use pallas::network::{
facades::NodeClient,
miniprotocols::{
chainsync,
localstate::{self, queries_v16},
Point, MAINNET_MAGIC, PRE_PRODUCTION_MAGIC,
},
miniprotocols::{chainsync, localstate::queries_v16, Point, PRE_PRODUCTION_MAGIC},
};
use pallas_codec::utils::AnyCbor;
use tracing::info;

async fn do_localstate_query(client: &mut NodeClient) {
client.statequery().acquire(None).await.unwrap();
let client = client.statequery();

let result = queries_v16::get_chain_point(client.statequery())
.await
.unwrap();
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.statequery())
.await
.unwrap();
let result = queries_v16::get_system_start(client).await.unwrap();
info!("result: {:?}", result);

let era = queries_v16::get_current_era(client.statequery())
.await
.unwrap();
let era = queries_v16::get_current_era(client).await.unwrap();
info!("result: {:?}", era);

let result = queries_v16::get_block_epoch_number(client.statequery(), era)
let result = queries_v16::get_block_epoch_number(client, era)
.await
.unwrap();

info!("result: {:?}", result);

client.statequery().send_release().await.unwrap();
client.send_release().await.unwrap();
}

async fn do_chainsync(client: &mut NodeClient) {
Expand Down Expand Up @@ -63,7 +54,9 @@ async fn do_chainsync(client: &mut NodeClient) {
}
}

const SOCKET_PATH: &str = "/Users/santiago_ho/.dmtr/tmp/starters-28e75e/mainnet-stable.socket";
// 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]
Expand All @@ -77,7 +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 mut client = NodeClient::connect(SOCKET_PATH, MAINNET_MAGIC)
let mut client = NodeClient::connect(SOCKET_PATH, PRE_PRODUCTION_MAGIC)
.await
.unwrap();

Expand Down
7 changes: 2 additions & 5 deletions pallas-network/src/miniprotocols/localstate/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl GenericClient {
}
}

pub async fn query_generic(&mut self, request: AnyCbor) -> Result<AnyCbor, ClientError> {
pub async fn query_any(&mut self, request: AnyCbor) -> Result<AnyCbor, ClientError> {
self.send_query(request).await?;
self.recv_while_querying().await
}
Expand All @@ -201,10 +201,7 @@ impl GenericClient {
for<'b> R: pallas_codec::minicbor::Decode<'b, ()>,
{
let request = AnyCbor::from_encode(request);
self.send_query(request).await?;

let response = self.recv_while_querying().await?;

let response = self.query_any(request).await?;
response.into_decode().map_err(ClientError::InvalidCbor)
}
}
Expand Down
1 change: 0 additions & 1 deletion pallas-network/src/miniprotocols/localstate/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::convert::Into;
use std::fmt::Debug;

use pallas_codec::utils::AnyCbor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Encode<()> for BlockQuery {
e.array(1)?;
e.u16(14)?;
}
BlockQuery::GetUTxOByTxIn(x) => {
BlockQuery::GetUTxOByTxIn(_) => {
e.array(2)?;
e.u16(15)?;
e.encode(2)?;
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Encode<()> for HardForkQuery {
}

impl<'b> Decode<'b, ()> for HardForkQuery {
fn decode(d: &mut Decoder<'b>, ctx: &mut ()) -> Result<Self, decode::Error> {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!()
}
}
Expand All @@ -197,7 +197,7 @@ impl Encode<()> for LedgerQuery {
}

impl<'b> Decode<'b, ()> for LedgerQuery {
fn decode(d: &mut Decoder<'b>, ctx: &mut ()) -> Result<Self, decode::Error> {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!()
}
}
Expand Down

0 comments on commit 67b0100

Please sign in to comment.