use algonaut::Algod;
use algonaut::abi::abi_call;
use algonaut::atomic::{AtomicGroupBuilder, MethodCall};
use algonaut::core::AppId;
use algonaut::transaction::account::Account;
use dotenv::dotenv;
use std::env;
use std::error::Error;
use std::sync::Arc;
#[macro_use]
extern crate log;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
dotenv().ok();
env_logger::init();
info!("creating algod client");
let algod = Algod::new(&env::var("ALGOD_URL")?, &env::var("ALGOD_TOKEN")?)?;
info!("creating account for alice");
let alice = Account::from_mnemonic(&env::var("ALICE_MNEMONIC")?)?;
let signer = Arc::new(alice.clone());
info!("retrieving suggested params");
let params = algod.suggested_params().await?;
info!("building method call");
let call = MethodCall::builder(AppId(5), alice.address(), signer)
.invoke(abi_call!("add(uint64,uint64)uint64", 2u64, 3u64))
.build(¶ms);
info!("composing and executing");
let result = AtomicGroupBuilder::new()
.add_method_call(call)
.build()?
.sign()
.await?
.execute(&algod)
.await?;
info!("confirmed in round {:?}", result.confirmed_round);
for r in result.method_results {
info!("method return: {:?}", r.return_value);
}
Ok(())
}