pub struct AlgodClient { /* private fields */ }
Expand description
Client for interacting with the Algorand protocol daemon
Implementations§
Source§impl AlgodClient
impl AlgodClient
Sourcepub fn new(address: &str, token: &str) -> AlgodClient
pub fn new(address: &str, token: &str) -> AlgodClient
Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 let algod_address = "http://localhost:8080";
9 let algod_token = "contents-of-algod.token";
10
11 let mut f = File::open("./signed.tx")?;
12 let mut raw_transaction = Vec::new();
13 let _ = f.read_to_end(&mut raw_transaction)?;
14
15 let algod_client = AlgodClient::new(algod_address, algod_token);
16
17 let send_response = algod_client.raw_transaction(&raw_transaction)?;
18 println!("Transaction ID: {}", send_response.tx_id);
19
20 Ok(())
21}
More examples
3fn main() {
4 let algod_address = "http://localhost:8080";
5 let algod_token = "contents-of-algod.token";
6 let kmd_address = "http://localhost:7833";
7 let kmd_token = "contents-of-kmd.token";
8
9 let algod_client = AlgodClient::new(algod_address, algod_token);
10 let kmd_client = KmdClient::new(kmd_address, kmd_token);
11
12 println!(
13 "Algod versions: {:?}",
14 algod_client.versions().unwrap().versions
15 );
16 println!(
17 "Kmd versions: {:?}",
18 kmd_client.versions().unwrap().versions
19 );
20}
5fn main() -> Result<(), Box<dyn Error>> {
6 let algod_address = "http://localhost:8080";
7 let algod_token = "contents-of-algod.token";
8
9 let algod_client = AlgodClient::new(algod_address, algod_token);
10
11 // Print algod status
12 let node_status = algod_client.status()?;
13 println!("algod last round: {}", node_status.last_round);
14 println!(
15 "algod time since last round: {}",
16 node_status.time_since_last_round
17 );
18 println!("algod catchup: {}", node_status.catchup_time);
19 println!("algod latest version: {}", node_status.last_version);
20
21 // Fetch block information
22 let last_block = algod_client.block(node_status.last_round)?;
23 println!("{:#?}", last_block);
24
25 Ok(())
26}
6fn main() -> Result<(), Box<dyn Error>> {
7 let kmd_address = "http://localhost:7833";
8 let kmd_token = "contents-of-kmd.token";
9 let algod_address = "http://localhost:8080";
10 let algod_token = "contents-of-algod.token";
11
12 let kmd_client = KmdClient::new(kmd_address, kmd_token);
13 let algod_client = AlgodClient::new(algod_address, algod_token);
14
15 let list_response = kmd_client.list_wallets()?;
16
17 let wallet_id = match list_response
18 .wallets
19 .into_iter()
20 .find(|wallet| wallet.name == "testwallet")
21 {
22 Some(wallet) => wallet.id,
23 None => return Err("Wallet not found".into()),
24 };
25
26 let init_response = kmd_client.init_wallet_handle(&wallet_id, "testpassword")?;
27 let wallet_handle_token = init_response.wallet_handle_token;
28
29 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
30 let from_address = Address::from_string(&gen_response.address)?;
31
32 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
33 let to_address = Address::from_string(&gen_response.address)?;
34
35 let transaction_params = algod_client.transaction_params()?;
36
37 let genesis_id = transaction_params.genesis_id;
38 let genesis_hash = transaction_params.genesis_hash;
39
40 let base = BaseTransaction {
41 sender: from_address,
42 first_valid: transaction_params.last_round,
43 last_valid: transaction_params.last_round + 1000,
44 note: Vec::new(),
45 genesis_id,
46 genesis_hash,
47 };
48
49 let payment = Payment {
50 amount: MicroAlgos(200_000),
51 receiver: to_address,
52 close_remainder_to: None,
53 };
54
55 let transaction = Transaction::new(base, MicroAlgos(1000), TransactionType::Payment(payment))?;
56
57 let sign_response =
58 kmd_client.sign_transaction(&wallet_handle_token, "testpassword", &transaction)?;
59
60 println!(
61 "kmd made signed transaction with {} bytes",
62 sign_response.signed_transaction.len()
63 );
64
65 // Broadcast the transaction to the network
66 // Note this transaction will get rejected because the accounts do not have any tokens
67 let send_response = algod_client.raw_transaction(&sign_response.signed_transaction)?;
68
69 println!("Transaction ID: {}", send_response.tx_id);
70
71 Ok(())
72}
pub fn new_with_headers( address: &str, token: &str, headers: HeaderMap, ) -> AlgodClient
Sourcepub fn versions(&self) -> Result<Version, Error>
pub fn versions(&self) -> Result<Version, Error>
Retrieves the current version
Examples found in repository?
3fn main() {
4 let algod_address = "http://localhost:8080";
5 let algod_token = "contents-of-algod.token";
6 let kmd_address = "http://localhost:7833";
7 let kmd_token = "contents-of-kmd.token";
8
9 let algod_client = AlgodClient::new(algod_address, algod_token);
10 let kmd_client = KmdClient::new(kmd_address, kmd_token);
11
12 println!(
13 "Algod versions: {:?}",
14 algod_client.versions().unwrap().versions
15 );
16 println!(
17 "Kmd versions: {:?}",
18 kmd_client.versions().unwrap().versions
19 );
20}
Sourcepub fn status(&self) -> Result<NodeStatus, Error>
pub fn status(&self) -> Result<NodeStatus, Error>
Gets the current node status
Examples found in repository?
5fn main() -> Result<(), Box<dyn Error>> {
6 let algod_address = "http://localhost:8080";
7 let algod_token = "contents-of-algod.token";
8
9 let algod_client = AlgodClient::new(algod_address, algod_token);
10
11 // Print algod status
12 let node_status = algod_client.status()?;
13 println!("algod last round: {}", node_status.last_round);
14 println!(
15 "algod time since last round: {}",
16 node_status.time_since_last_round
17 );
18 println!("algod catchup: {}", node_status.catchup_time);
19 println!("algod latest version: {}", node_status.last_version);
20
21 // Fetch block information
22 let last_block = algod_client.block(node_status.last_round)?;
23 println!("{:#?}", last_block);
24
25 Ok(())
26}
Sourcepub fn status_after_block(&self, round: Round) -> Result<NodeStatus, Error>
pub fn status_after_block(&self, round: Round) -> Result<NodeStatus, Error>
Waits for a block to appear after the specified round and returns the node status at the time
Sourcepub fn block(&self, round: Round) -> Result<Block, Error>
pub fn block(&self, round: Round) -> Result<Block, Error>
Get the block for the given round
Examples found in repository?
5fn main() -> Result<(), Box<dyn Error>> {
6 let algod_address = "http://localhost:8080";
7 let algod_token = "contents-of-algod.token";
8
9 let algod_client = AlgodClient::new(algod_address, algod_token);
10
11 // Print algod status
12 let node_status = algod_client.status()?;
13 println!("algod last round: {}", node_status.last_round);
14 println!(
15 "algod time since last round: {}",
16 node_status.time_since_last_round
17 );
18 println!("algod catchup: {}", node_status.catchup_time);
19 println!("algod latest version: {}", node_status.last_version);
20
21 // Fetch block information
22 let last_block = algod_client.block(node_status.last_round)?;
23 println!("{:#?}", last_block);
24
25 Ok(())
26}
Sourcepub fn ledger_supply(&self) -> Result<Supply, Error>
pub fn ledger_supply(&self) -> Result<Supply, Error>
Gets the current supply reported by the ledger
pub fn account_information(&self, address: &str) -> Result<Account, Error>
Sourcepub fn pending_transactions(
&self,
limit: u64,
) -> Result<PendingTransactions, Error>
pub fn pending_transactions( &self, limit: u64, ) -> Result<PendingTransactions, Error>
Gets a list of unconfirmed transactions currently in the transaction pool
Sorted by priority in decreasing order and truncated at the specified limit, or returns all if specified limit is 0
Sourcepub fn pending_transaction_information(
&self,
transaction_id: &str,
) -> Result<Transaction, Error>
pub fn pending_transaction_information( &self, transaction_id: &str, ) -> Result<Transaction, Error>
Get a specified pending transaction
Sourcepub fn transactions(
&self,
address: &str,
first_round: Option<Round>,
last_round: Option<Round>,
from_date: Option<String>,
to_date: Option<String>,
limit: Option<u64>,
) -> Result<TransactionList, Error>
pub fn transactions( &self, address: &str, first_round: Option<Round>, last_round: Option<Round>, from_date: Option<String>, to_date: Option<String>, limit: Option<u64>, ) -> Result<TransactionList, Error>
Get a list of confirmed transactions, limited to filters if specified
Sourcepub fn send_transaction(
&self,
signed_transaction: &SignedTransaction,
) -> Result<TransactionID, Error>
pub fn send_transaction( &self, signed_transaction: &SignedTransaction, ) -> Result<TransactionID, Error>
Broadcasts a transaction to the network
Sourcepub fn raw_transaction(&self, raw: &[u8]) -> Result<TransactionID, Error>
pub fn raw_transaction(&self, raw: &[u8]) -> Result<TransactionID, Error>
Broadcasts a raw transaction to the network
Examples found in repository?
7fn main() -> Result<(), Box<dyn Error>> {
8 let algod_address = "http://localhost:8080";
9 let algod_token = "contents-of-algod.token";
10
11 let mut f = File::open("./signed.tx")?;
12 let mut raw_transaction = Vec::new();
13 let _ = f.read_to_end(&mut raw_transaction)?;
14
15 let algod_client = AlgodClient::new(algod_address, algod_token);
16
17 let send_response = algod_client.raw_transaction(&raw_transaction)?;
18 println!("Transaction ID: {}", send_response.tx_id);
19
20 Ok(())
21}
More examples
6fn main() -> Result<(), Box<dyn Error>> {
7 let kmd_address = "http://localhost:7833";
8 let kmd_token = "contents-of-kmd.token";
9 let algod_address = "http://localhost:8080";
10 let algod_token = "contents-of-algod.token";
11
12 let kmd_client = KmdClient::new(kmd_address, kmd_token);
13 let algod_client = AlgodClient::new(algod_address, algod_token);
14
15 let list_response = kmd_client.list_wallets()?;
16
17 let wallet_id = match list_response
18 .wallets
19 .into_iter()
20 .find(|wallet| wallet.name == "testwallet")
21 {
22 Some(wallet) => wallet.id,
23 None => return Err("Wallet not found".into()),
24 };
25
26 let init_response = kmd_client.init_wallet_handle(&wallet_id, "testpassword")?;
27 let wallet_handle_token = init_response.wallet_handle_token;
28
29 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
30 let from_address = Address::from_string(&gen_response.address)?;
31
32 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
33 let to_address = Address::from_string(&gen_response.address)?;
34
35 let transaction_params = algod_client.transaction_params()?;
36
37 let genesis_id = transaction_params.genesis_id;
38 let genesis_hash = transaction_params.genesis_hash;
39
40 let base = BaseTransaction {
41 sender: from_address,
42 first_valid: transaction_params.last_round,
43 last_valid: transaction_params.last_round + 1000,
44 note: Vec::new(),
45 genesis_id,
46 genesis_hash,
47 };
48
49 let payment = Payment {
50 amount: MicroAlgos(200_000),
51 receiver: to_address,
52 close_remainder_to: None,
53 };
54
55 let transaction = Transaction::new(base, MicroAlgos(1000), TransactionType::Payment(payment))?;
56
57 let sign_response =
58 kmd_client.sign_transaction(&wallet_handle_token, "testpassword", &transaction)?;
59
60 println!(
61 "kmd made signed transaction with {} bytes",
62 sign_response.signed_transaction.len()
63 );
64
65 // Broadcast the transaction to the network
66 // Note this transaction will get rejected because the accounts do not have any tokens
67 let send_response = algod_client.raw_transaction(&sign_response.signed_transaction)?;
68
69 println!("Transaction ID: {}", send_response.tx_id);
70
71 Ok(())
72}
Sourcepub fn transaction(&self, transaction_id: &str) -> Result<Transaction, Error>
pub fn transaction(&self, transaction_id: &str) -> Result<Transaction, Error>
Gets the information of a single transaction
Sourcepub fn transaction_information(
&self,
address: &str,
transaction_id: &str,
) -> Result<Transaction, Error>
pub fn transaction_information( &self, address: &str, transaction_id: &str, ) -> Result<Transaction, Error>
Gets a specific confirmed transaction
Sourcepub fn suggested_fee(&self) -> Result<TransactionFee, Error>
pub fn suggested_fee(&self) -> Result<TransactionFee, Error>
Gets suggested fee in units of micro-Algos per byte
Sourcepub fn transaction_params(&self) -> Result<TransactionParams, Error>
pub fn transaction_params(&self) -> Result<TransactionParams, Error>
Gets parameters for constructing a new transaction
Examples found in repository?
6fn main() -> Result<(), Box<dyn Error>> {
7 let kmd_address = "http://localhost:7833";
8 let kmd_token = "contents-of-kmd.token";
9 let algod_address = "http://localhost:8080";
10 let algod_token = "contents-of-algod.token";
11
12 let kmd_client = KmdClient::new(kmd_address, kmd_token);
13 let algod_client = AlgodClient::new(algod_address, algod_token);
14
15 let list_response = kmd_client.list_wallets()?;
16
17 let wallet_id = match list_response
18 .wallets
19 .into_iter()
20 .find(|wallet| wallet.name == "testwallet")
21 {
22 Some(wallet) => wallet.id,
23 None => return Err("Wallet not found".into()),
24 };
25
26 let init_response = kmd_client.init_wallet_handle(&wallet_id, "testpassword")?;
27 let wallet_handle_token = init_response.wallet_handle_token;
28
29 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
30 let from_address = Address::from_string(&gen_response.address)?;
31
32 let gen_response = kmd_client.generate_key(&wallet_handle_token)?;
33 let to_address = Address::from_string(&gen_response.address)?;
34
35 let transaction_params = algod_client.transaction_params()?;
36
37 let genesis_id = transaction_params.genesis_id;
38 let genesis_hash = transaction_params.genesis_hash;
39
40 let base = BaseTransaction {
41 sender: from_address,
42 first_valid: transaction_params.last_round,
43 last_valid: transaction_params.last_round + 1000,
44 note: Vec::new(),
45 genesis_id,
46 genesis_hash,
47 };
48
49 let payment = Payment {
50 amount: MicroAlgos(200_000),
51 receiver: to_address,
52 close_remainder_to: None,
53 };
54
55 let transaction = Transaction::new(base, MicroAlgos(1000), TransactionType::Payment(payment))?;
56
57 let sign_response =
58 kmd_client.sign_transaction(&wallet_handle_token, "testpassword", &transaction)?;
59
60 println!(
61 "kmd made signed transaction with {} bytes",
62 sign_response.signed_transaction.len()
63 );
64
65 // Broadcast the transaction to the network
66 // Note this transaction will get rejected because the accounts do not have any tokens
67 let send_response = algod_client.raw_transaction(&sign_response.signed_transaction)?;
68
69 println!("Transaction ID: {}", send_response.tx_id);
70
71 Ok(())
72}
Auto Trait Implementations§
impl Freeze for AlgodClient
impl RefUnwindSafe for AlgodClient
impl Send for AlgodClient
impl Sync for AlgodClient
impl Unpin for AlgodClient
impl UnwindSafe for AlgodClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more