pub struct Agent { /* private fields */ }Implementations§
Source§impl Agent
impl Agent
pub fn builder() -> AgentBuilder
pub fn new(base_url: String, network: String, account: Account) -> Agent
pub fn program(&self, program_id: &str) -> Result<ProgramManager<'_>>
pub fn account(&self) -> &Account
pub fn base_url(&self) -> &String
pub fn client(&self) -> &Agent
pub fn network(&self) -> &String
pub fn set_url(&mut self, url: &str)
pub fn set_network(&mut self, network: &str)
pub fn set_account(&mut self, account: Account)
pub fn local_testnet(&mut self, port: &str)
Source§impl Agent
impl Agent
Sourcepub fn decrypt_ciphertext_record(
&self,
ciphertext_record: &CiphertextRecord,
) -> Result<PlaintextRecord>
pub fn decrypt_ciphertext_record( &self, ciphertext_record: &CiphertextRecord, ) -> Result<PlaintextRecord>
Decrypts a ciphertext record to a plaintext record using the agent’s view key.
§Arguments
ciphertext_record- The ciphertext record to decrypt.
§Returns
A Result which is:
- a
PlaintextRecord- The decrypted plaintext record. - an
Error- If there was an issue decrypting the record.
§Example
use std::str::FromStr;
use aleo_agent::agent::Agent;
use aleo_agent::CiphertextRecord;
let agent = Agent::default();
let ciphertext_record = CiphertextRecord::from_str( "CIPHERTEXT RECORD").expect("Failed to parse ciphertext record");
let plaintext_record = agent.decrypt_ciphertext_record(&ciphertext_record);Sourcepub fn get_unspent_records(
&self,
block_heights: Range<u32>,
max_gates: Option<u64>,
) -> Result<Vec<(Field, PlaintextRecord)>>
pub fn get_unspent_records( &self, block_heights: Range<u32>, max_gates: Option<u64>, ) -> Result<Vec<(Field, PlaintextRecord)>>
Finds unspent records on chain.
§Arguments
block_heights- The range of block heights to search for unspent records.max_gates- The minimum threshold microcredits for the sum of balances collected from records
§Returns
The Ok variant wraps the unspent records as a vector of tuples of (Field, PlaintextRecord).
§Example
use aleo_agent::agent::Agent;
use aleo_agent::{MICROCREDITS, PlaintextRecord};
let agent = Agent::default();
let gate = 10 * MICROCREDITS;
// Get unspent records with a minimum of 10 credits in the range of blocks 0 to 100
let res = agent.get_unspent_records(0..100, Some(gate)).expect("Failed to get unspent records");
let records = res
.iter().filter_map(|(_, record)| Some(record.cloned()) )
.collect::<Vec<PlaintextRecord>>();Sourcepub fn scan_records(
&self,
block_heights: Range<u32>,
max_records: Option<usize>,
) -> Result<Vec<(Field, PlaintextRecord)>>
pub fn scan_records( &self, block_heights: Range<u32>, max_records: Option<usize>, ) -> Result<Vec<(Field, PlaintextRecord)>>
Scans the chain for all records matching the address of agent.
§Return
A Result which is:
- a
Vec<(Field, PlaintextRecord)>- The records that match the view key. - an
Error- If there was an issue scanning the ledger.
§Example
use aleo_agent::agent::Agent;
let agent = Agent::default();
let end_height = agent.get_latest_block_height().unwrap();
let start_height = end_height - 50; // You can arbitrarily specify the {start block}
let records = agent.scan_records(start_height..end_height, None);
match records {
Ok(records) => {
println!("Records:\n{records:#?}");
}
Err(e) => {
eprintln!("Failed to get records : {e}");
}
}Source§impl Agent
impl Agent
Sourcepub fn get_public_balance(&self) -> Result<u64>
pub fn get_public_balance(&self) -> Result<u64>
Fetch the public balance in microcredits associated with the address.
§Returns
A Result which is:
- a
u64- The public balance in microcredits associated with the address. - an
Error- If there was an issue fetching the public balance.
Sourcepub fn get_transactions(&self) -> Result<Vec<Transaction>>
pub fn get_transactions(&self) -> Result<Vec<Transaction>>
Fetches the transactions associated with the agent’s account.
§Returns
A Result which is:
- a
Vec<Transaction>- The transactions associated with the agent’s account. - an
Error- If there was an issue fetching the transactions.
Sourcepub fn transfer(&self, args: TransferArgs) -> Result<String>
pub fn transfer(&self, args: TransferArgs) -> Result<String>
Executes a transfer to the specified recipient_address with the specified amount and fee.
§Arguments
amount- The amount to be transferred.fee- The fee for the transfer.recipient_address- The address of the recipient.transfer_type- The type of transfer.amount_record- An optional record of the amount.fee_record- An optional record of the fee.
§Returns
A Result which is:
- a
String- The transaction hash . - an
Error- If there was an issue executing the transfer. Executes a transfer to the specified recipient_address with the specified amount and fee. Specify 0 for no fee.
§Example
use std::str::FromStr;
use aleo_agent::Address;
use aleo_agent::agent::{Agent, TransferArgs, TransferType};
let agent = Agent::default();
// just use for test
let recipient_address = Address::zero();
let amount = 100;
let priority_fee = 0;
// Public transfer 100 microcredits to the recipient address with 0 priority fee
let transfer_args = TransferArgs::from(amount, recipient_address, priority_fee, None, TransferType::Public);
let transfer_result = agent.transfer(transfer_args);Source§impl Agent
impl Agent
Sourcepub fn get_latest_block_height(&self) -> Result<u32>
pub fn get_latest_block_height(&self) -> Result<u32>
Retrieves the latest block height from the network.
§Returns
The Ok variant wraps the latest block height as u32.
Sourcepub fn get_latest_block_hash(&self) -> Result<BlockHash>
pub fn get_latest_block_hash(&self) -> Result<BlockHash>
Retrieves the latest block hash from the network.
§Returns
The Ok variant wraps the latest block hash as BlockHash.
Sourcepub fn get_latest_block(&self) -> Result<Block>
pub fn get_latest_block(&self) -> Result<Block>
Retrieves the latest block from the network.
§Returns
The Ok variant wraps the latest block as Block.
Sourcepub fn get_block_of_height(&self, height: u32) -> Result<Block>
pub fn get_block_of_height(&self, height: u32) -> Result<Block>
Sourcepub fn get_transactions_of_height(&self, height: u32) -> Result<Transactions>
pub fn get_transactions_of_height(&self, height: u32) -> Result<Transactions>
Sourcepub fn get_blocks_in_range(
&self,
start_height: u32,
end_height: u32,
) -> Result<Vec<Block>>
pub fn get_blocks_in_range( &self, start_height: u32, end_height: u32, ) -> Result<Vec<Block>>
Retrieves a range of blocks from the network.
§Arguments
start_height- The starting height of the range of blocks to retrieve.end_height- The ending height of the range of blocks to retrieve.- end_height - start_height must be less than or equal to 50.
§Returns
The Ok variant wraps a vector of Block.
Sourcepub fn get_transaction(&self, transaction_id: &str) -> Result<Transaction>
pub fn get_transaction(&self, transaction_id: &str) -> Result<Transaction>
Sourcepub fn get_confirmed_transaction(
&self,
transaction_id: &str,
) -> Result<ConfirmedTransaction>
pub fn get_confirmed_transaction( &self, transaction_id: &str, ) -> Result<ConfirmedTransaction>
Sourcepub fn broadcast_transaction(&self, transaction: &Transaction) -> Result<String>
pub fn broadcast_transaction(&self, transaction: &Transaction) -> Result<String>
Retrieves the pending transactions currently in the mempool from the network.
§Returns
The Ok variant wraps the pending transactions as a vector of Transaction.
Broadcasts a transaction to the Aleo network.
§Arguments
transaction- The transaction to broadcast.
§Returns
The Ok variant wraps the Transaction ID from the network as a String.
Sourcepub fn find_block_hash_by_transaction_id(
&self,
transaction_id: &TransactionID,
) -> Result<BlockHash>
pub fn find_block_hash_by_transaction_id( &self, transaction_id: &TransactionID, ) -> Result<BlockHash>
Sourcepub fn find_transition_id_by_input_or_output_id(
&self,
input_or_output_id: Field,
) -> Result<TransitionID>
pub fn find_transition_id_by_input_or_output_id( &self, input_or_output_id: Field, ) -> Result<TransitionID>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Agent
impl !RefUnwindSafe for Agent
impl Send for Agent
impl Sync for Agent
impl Unpin for Agent
impl !UnwindSafe for Agent
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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