Struct AlgodClient

Source
pub struct AlgodClient { /* private fields */ }
Expand description

Client for interacting with the Algorand protocol daemon

Implementations§

Source§

impl AlgodClient

Source

pub fn new(address: &str, token: &str) -> AlgodClient

Examples found in repository?
examples/submit_file.rs (line 15)
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
Hide additional examples
examples/quickstart.rs (line 9)
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}
examples/algod_client.rs (line 9)
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}
examples/sign_submit_transaction.rs (line 13)
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}
Source

pub fn new_with_headers( address: &str, token: &str, headers: HeaderMap, ) -> AlgodClient

Source

pub fn health(&self) -> Result<(), Error>

Returns Ok if healthy

Source

pub fn versions(&self) -> Result<Version, Error>

Retrieves the current version

Examples found in repository?
examples/quickstart.rs (line 14)
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}
Source

pub fn status(&self) -> Result<NodeStatus, Error>

Gets the current node status

Examples found in repository?
examples/algod_client.rs (line 12)
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}
Source

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

Source

pub fn block(&self, round: Round) -> Result<Block, Error>

Get the block for the given round

Examples found in repository?
examples/algod_client.rs (line 22)
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}
Source

pub fn ledger_supply(&self) -> Result<Supply, Error>

Gets the current supply reported by the ledger

Source

pub fn account_information(&self, address: &str) -> Result<Account, Error>

Source

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

Source

pub fn pending_transaction_information( &self, transaction_id: &str, ) -> Result<Transaction, Error>

Get a specified pending transaction

Source

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

Source

pub fn send_transaction( &self, signed_transaction: &SignedTransaction, ) -> Result<TransactionID, Error>

Broadcasts a transaction to the network

Source

pub fn raw_transaction(&self, raw: &[u8]) -> Result<TransactionID, Error>

Broadcasts a raw transaction to the network

Examples found in repository?
examples/submit_file.rs (line 17)
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
Hide additional examples
examples/sign_submit_transaction.rs (line 67)
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}
Source

pub fn transaction(&self, transaction_id: &str) -> Result<Transaction, Error>

Gets the information of a single transaction

Source

pub fn transaction_information( &self, address: &str, transaction_id: &str, ) -> Result<Transaction, Error>

Gets a specific confirmed transaction

Source

pub fn suggested_fee(&self) -> Result<TransactionFee, Error>

Gets suggested fee in units of micro-Algos per byte

Source

pub fn transaction_params(&self) -> Result<TransactionParams, Error>

Gets parameters for constructing a new transaction

Examples found in repository?
examples/sign_submit_transaction.rs (line 35)
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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Err = <U as TryFrom<T>>::Err

Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Err>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,