Closed swastkk closed 1 year ago
The get_account_info
returns an AccountInfo. If the account is not found then an Err
is returned (and you can check if it is not found using https://docs.rs/concordium-rust-sdk/latest/concordium_rust_sdk/endpoints/enum.QueryError.html#method.is_not_found )
So
let ai = client.get_account_info(acc, &block).await;
match ai {
Ok(ai) => {
let account_amount = ai.response
.account_amount;
println!("Account Amount: {:?}", account_amount);
Ok::<_, anyhow::Error>(account_amount)
}
Err(e) if e.is_not_found() => {
eprintln!("No account info found for account: {:?}", acc);
// Handle the case where account_info_response.response is None
// You can return an appropriate value or error here
// For now, returning 0 as an example
Ok::<_, anyhow::Error>(0.into())
}
Err(e) => return Err(e)
}
Also getting this
no method named `expect` found for struct `concordium_rust_sdk::smart_contracts::concordium_contracts_common::Amount` in the current scope
I removed the .expect. I did not notice it and just copy pasted your response.
This is my complete code but I am getting a large error Can you help me out to fix this.
async fn consens_info() -> anyhow::Result<()>{
let endpoint_node = Endpoint::from_str("http://127.0.0.1:20100")?;
let mut client = v2::Client::new(endpoint_node)
.await?;
let info = client.get_consensus_info().await?;
let finalized_block = info.last_finalized_block;
println!("Listing accounts in block {}.", finalized_block);
move |acc| {
let mut client = client.clone();
let block = finalized_block;
async move {
let ai = client.get_account_info(acc, &block).await;
match ai {
Ok(ai) => {
let account_amount = ai.response
.account_amount;
println!("Account Amount: {:?}", account_amount);
Ok::<_, anyhow::Error>(account_amount)
}
Err(err) => {
// Handle specific error cases
if err.is_not_found() {
eprintln!("No account info found for account: {:?}", acc);
// Handle the case where account_info_response.response is None
// You can return an appropriate value or error here
// For now, returning 0 as an example
Ok::<_, anyhow::Error>(0.into())
} else {
// Handle other errors
Err(err.into())
}
}
}
}
}
}
So this block
move |acc| {
let mut client = client.clone();
let block = finalized_block;
async move {
let ai = client.get_account_info(acc, &block).await;
match ai {
Ok(ai) => {
let account_amount = ai.response
.account_amount;
println!("Account Amount: {:?}", account_amount);
Ok::<_, anyhow::Error>(account_amount)
}
Err(err) => {
// Handle specific error cases
if err.is_not_found() {
eprintln!("No account info found for account: {:?}", acc);
// Handle the case where account_info_response.response is None
// You can return an appropriate value or error here
// For now, returning 0 as an example
Ok::<_, anyhow::Error>(0.into())
} else {
// Handle other errors
Err(err.into())
}
}
}
}
}
returns a closure, but the return type of your function states that it is a Result<()>
.
What do you want your function to do exactly?
I want my func to return the account_amount
in a variable from the last finalized_block
of the chain.
Bug Description Unable to use the AccountInfo Struct after declaring a variable
Steps to Reproduce
Expected Result
I wanted to get the Struct fields like
account_amount
,account_address
Actual Result ErrorVersions