Create the run function that handles the execution of the chosen subcommand (ReadCount or IncrementCount).
For ReadCount, it compiles the Pint project, queries the current count, and displays it.
For IncrementCount, it compiles the project, queries the current count, creates an incremented solution, submits it to the builder, and displays the new count:
#![allow(unused)]fnmain() {
asyncfnrun(cli: Cli) -> anyhow::Result<()> {
let Cli { command } = cli;
match command {
Command::ReadCount {
server: Shared {
node_api,
pint_directory,
},
} => {
let address = compile_address(pint_directory).await?;
let node = EssentialNodeClient::new(node_api)?;
let key = counter_key();
let count = query_count(node, address.contract, key).await?;
let count_value = extract_count(count)?;
println!("Current count is: {}", count_value);
}
Command::IncrementCount {
builder_api,
server: Shared {
node_api,
pint_directory,
},
} => {
let address = compile_address(pint_directory).await?;
let node = EssentialNodeClient::new(node_api)?;
let key = counter_key();
let count = query_count(node, address.contract.clone(), key).await?;
let (solution, new_count) = incremented_solution(count)?; // Pass only countlet builder =
essential_rest_client::builder_client::EssentialBuilderClient::new(builder_api)?;
let ca = builder.submit_solution(&solution).await?;
println!("Submitted solution: {}", ca);
println!("Incremented count to: {}", new_count);
}
}
Ok(())
}
}
Add the main entry point of the application. It uses tokio for asynchronous execution, parses the command-line arguments, and calls the run function to execute the appropriate command: