Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }

Implementations§

Source§

impl Agent

Source

pub fn builder() -> AgentBuilder

Source

pub fn new(base_url: String, network: String, account: Account) -> Agent

Source

pub fn program(&self, program_id: &str) -> Result<ProgramManager<'_>>

Source

pub fn account(&self) -> &Account

Source

pub fn base_url(&self) -> &String

Source

pub fn client(&self) -> &Agent

Source

pub fn network(&self) -> &String

Source

pub fn set_url(&mut self, url: &str)

Source

pub fn set_network(&mut self, network: &str)

Source

pub fn set_account(&mut self, account: Account)

Source

pub fn local_testnet(&mut self, port: &str)

Source§

impl Agent

Source

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);
Source

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>>();
Source

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

Source

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.
Source

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.
Source

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

Source

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.

Source

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.

Source

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.

Source

pub fn get_block_of_height(&self, height: u32) -> Result<Block>

Retrieves the block of a specific height from the network.

§Arguments
  • height - The height of the block to retrieve.
§Returns

The Ok variant wraps the block of the specific height as Block.

Source

pub fn get_transactions_of_height(&self, height: u32) -> Result<Transactions>

Retrieves the transactions of a block of a specific height from the network.

§Arguments
  • height - The height of the block.
§Returns

The Ok variant wraps the transactions of the block of the specific height as Transactions.

Source

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.

Source

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

Retrieves a transaction by its transaction id from the network.

§Arguments
  • transaction_id - The id of the transaction to retrieve.
§Returns

The Ok variant wraps the transaction as Transaction.

Source

pub fn get_confirmed_transaction( &self, transaction_id: &str, ) -> Result<ConfirmedTransaction>

Retrieves the confirmed transaction for a given transaction id from the network.

§Arguments
  • transaction_id - The id of the transaction to retrieve.
§Returns

The Ok variant wraps the confirmed transaction as ConfirmedTransaction.

Source

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.

Source

pub fn find_block_hash_by_transaction_id( &self, transaction_id: &TransactionID, ) -> Result<BlockHash>

Returns the block hash that contains the given transaction ID.

§Arguments
  • transaction_id - The id of the transaction to find the block hash for.
§Returns

The Ok variant wraps the block hash as BlockHash.

Source

pub fn find_transition_id_by_input_or_output_id( &self, input_or_output_id: Field, ) -> Result<TransitionID>

Retrieves the transition ID that contains the given input ID or output ID from the network.

§Arguments
  • input_or_output_id - The input ID or output ID to find the transition ID for.
§Returns

The Ok variant wraps the transition ID as TransitionID.

Source§

impl Agent

Source

pub fn deploy_program( &self, program: &Program, priority_fee: u64, fee_record: Option<PlaintextRecord>, ) -> Result<String>

Deploy a program to the network

§Arguments
  • program - The program to deploy
  • priority_fee - The priority fee to pay for the deployment
  • fee_record - The fee record to pay for deployment costs
§Returns
  • The transaction hash of the deployment transaction

Trait Implementations§

Source§

impl Clone for Agent

Source§

fn clone(&self) -> Agent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Agent

Source§

fn default() -> Agent

Returns the “default value” for a type. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more