1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # algonaut
//!
//! Rust **algonaut** aims at becoming a rusty SDK for [Algorand](https://www.algorand.com/).
//! Please, be aware that this crate is a work in progress.
//!
//! ```rust
//! use algonaut::core::MicroAlgos;
//! use algonaut::transaction::{Pay, Txn};
//! use algonaut::{Algod, Kmd};
//! use dotenv::dotenv;
//! use std::env;
//! use std::error::Error;
//!
//! fn main() -> Result<(), Box<dyn Error>> {
//! // load variables in .env
//! dotenv().ok();
//!
//! // kmd manages wallets and accounts
//! let kmd = Kmd::new()
//! .bind(env::var("KMD_URL")?.as_ref())
//! .auth(env::var("KMD_TOKEN")?.as_ref())
//! .client_v1()?;
//!
//! // first we obtain a handle to our wallet
//! let list_response = kmd.list_wallets()?;
//! let wallet_id = match list_response
//! .wallets
//! .into_iter()
//! .find(|wallet| wallet.name == "unencrypted-default-wallet")
//! {
//! Some(wallet) => wallet.id,
//! None => return Err("Wallet not found".into()),
//! };
//! let init_response = kmd.init_wallet_handle(&wallet_id, "")?;
//! let wallet_handle_token = init_response.wallet_handle_token;
//! println!("Wallet Handle: {}", wallet_handle_token);
//!
//! // an account with some funds in our sandbox
//! let from_address = env::var("ACCOUNT")?.parse()?;
//! println!("Sender: {:#?}", from_address);
//!
//! let to_address = "2FMLYJHYQWRHMFKRHKTKX5UNB5DGO65U57O3YVLWUJWKRE4YYJYC2CWWBY".parse()?;
//! println!("Receiver: {:#?}", to_address);
//!
//! // algod has a convenient method that retrieves basic information for a transaction
//! let algod = Algod::new()
//! .bind(env::var("ALGOD_URL")?.as_ref())
//! .auth(env::var("ALGOD_TOKEN")?.as_ref())
//! .client_v1()?;
//!
//! let params = algod.transaction_params()?;
//!
//! // we are ready to build the transaction
//! let t = Txn::new()
//! .sender(from_address)
//! .first_valid(params.last_round)
//! .last_valid(params.last_round + 10)
//! .genesis_id(params.genesis_id)
//! .genesis_hash(params.genesis_hash)
//! .fee(MicroAlgos(10_000))
//! .payment(
//! Pay::new()
//! .amount(MicroAlgos(123_456))
//! .to(to_address)
//! .build(),
//! )
//! .build();
//!
//! // we need to sign the transaction to prove that we own the sender address
//! let sign_response = kmd.sign_transaction(&wallet_handle_token, "", &t)?;
//!
//! // broadcast the transaction to the network
//! let send_response = algod.raw_transaction(&sign_response.signed_transaction)?;
//!
//! println!("Transaction ID: {}", send_response.tx_id);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Objectives
//!
//! - [ ] Example-driven API development
//! - [ ] Clear error messages
//! - [ ] Async requests
//! - [ ] Builder pattern and sensible defaults
//! - [ ] Thorough test suite
//! - [ ] Comprehensive documentation
// TODO #![deny(missing_docs)]
// Re-exports
pub use Algod;
pub use Indexer;
pub use Kmd;
pub use algonaut_core as core;
pub use algonaut_crypto as crypto;
pub use algonaut_transaction as transaction;