use anyhow::Context;
use clap::AppSettings;
use concordium_rust_sdk::{
smart_contracts::{common, engine},
types::hashes::BlockHash,
v2,
};
use structopt::StructOpt;
#[derive(StructOpt)]
struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:20000"
)]
endpoint: v2::Endpoint,
#[structopt(long = "index", help = "Index of the smart contract to query.")]
index: common::ContractIndex,
#[structopt(long = "block", help = "Hash of the block in which to query.")]
block: Option<BlockHash>,
}
#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
let app = {
let app = App::clap().global_setting(AppSettings::ColoredHelp);
let matches = app.get_matches();
App::from_clap(&matches)
};
let mut client = v2::Client::new(app.endpoint)
.await
.context("Cannot connect.")?;
let block = app
.block
.map_or(v2::BlockIdentifier::LastFinal, v2::BlockIdentifier::Given);
let al = client
.get_instance_state(common::ContractAddress::new(app.index, 0u64), &block)
.await?;
println!("{}", al.block_hash);
let mut state = engine::v1::trie::PersistentState::try_from_stream(al.response).await?;
{
let mut loader = engine::v1::trie::Loader { inner: Vec::new() };
let mut out = Vec::new();
state.serialize(&mut loader, &mut out)?;
println!("Serialized state size: {}", out.len());
}
{
let mut storer = engine::v1::trie::Storer {
inner: std::io::Cursor::new(Vec::new()),
};
let root_ref = state.store_update(&mut storer)?;
println!(
"Stored state has size {}, root is at position {:?}.",
storer.inner.into_inner().len(),
root_ref
);
}
Ok(())
}