Struct ProgramManager

Source
pub struct ProgramManager<N: Network> { /* private fields */ }
Expand description

Program management object for loading programs for building, execution, and deployment

This object is meant to be a software abstraction that can be consumed by software like CLI tools, IDE plugins, Server-side stack components and other software that needs to interact with the Aleo network.

Implementations§

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn deploy_program( &mut self, program_id: impl TryInto<ProgramID<N>>, priority_fee: u64, fee_record: Option<Record<N, Plaintext<N>>>, password: Option<&str>, ) -> Result<String>

Deploy a program to the network

Source

pub fn create_deploy_transaction( program: &Program<N>, private_key: &PrivateKey<N>, priority_fee: u64, fee_record: Option<Record<N, Plaintext<N>>>, node_url: String, api_client: &AleoAPIClient<N>, vm: &Option<VM<N, ConsensusMemory<N>>>, ) -> Result<Transaction<N>>

Create a deploy transaction for a program without instantiating the program manager

Source

pub fn estimate_deployment_fee<A: Aleo<Network = N>>( &self, program: &Program<N>, ) -> Result<(u64, (u64, u64))>

Estimate deployment fee for a program in microcredits. The result will be in the form (total_cost, (storage_cost, namespace_cost))

Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network

Source

pub fn estimate_namespace_fee( program_id: impl TryInto<ProgramID<N>>, ) -> Result<u64>

Estimate the component of the deployment cost derived from the program name. Note that this cost does not represent the entire cost of deployment. It is additional to the cost of the size (in bytes) of the deployment.

Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn execute_program_offline<A: Aleo<Network = N>>( &self, private_key: &PrivateKey<N>, program: &Program<N>, function: impl TryInto<Identifier<N>>, imports: &[Program<N>], inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, include_outputs: bool, url: &str, ) -> Result<OfflineExecution<N>>

Create an offline execution of a program to share with a third party.

DISCLAIMER: Offline executions will not interact with the Aleo network and cannot use all of the features of the Leo programming language or Aleo instructions. Any code written inside finalize blocks will not be executed, mappings cannot be initialized, updated or read, and a chain of records cannot be created.

Offline executions however can be used to verify that program outputs follow from program inputs and that the program was executed correctly. If this is the aim and no chain interaction is desired, this function can be used.

Source

pub fn execute_program( &mut self, program_id: impl TryInto<ProgramID<N>>, function: impl TryInto<Identifier<N>>, inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, priority_fee: u64, fee_record: Option<Record<N, Plaintext<N>>>, password: Option<&str>, private_key: Option<&PrivateKey<N>>, ) -> Result<String>

Execute a program function on the Aleo Network.

To run this function successfully, the program must already be deployed on the Aleo Network

Source

pub fn create_execute_transaction( private_key: &PrivateKey<N>, priority_fee: u64, inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, fee_record: Option<Record<N, Plaintext<N>>>, program: &Program<N>, function: impl TryInto<Identifier<N>>, node_url: String, api_client: &AleoAPIClient<N>, vm: &Option<VM<N, ConsensusMemory<N>>>, ) -> Result<Transaction<N>>

Create an execute transaction without initializing a program manager instance

Source

pub fn estimate_execution_fee<A: Aleo<Network = N>>( &self, program: &Program<N>, function: impl TryInto<Identifier<N>>, inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>, ) -> Result<(u64, (u64, u64))>

Estimate the cost of executing a program with the given inputs in microcredits. The response will be in the form of (total_cost, (storage_cost, finalize_cost))

Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network

Source

pub fn estimate_finalize_fee( &self, program: &Program<N>, function: impl TryInto<Identifier<N>>, ) -> Result<u64>

Estimate the finalize fee component for executing a function. This fee is additional to the size of the execution of the program in bytes. If the function does not have a finalize step, then the finalize fee is 0.

Disclaimer: Fee estimation is experimental and may not represent a correct estimate on any current or future network

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn broadcast_transaction( &self, transaction: Transaction<N>, ) -> Result<String>

Broadcast a transaction to the network

Source

pub fn api_client(&self) -> Result<&AleoAPIClient<N>>

Get a reference to the configured API client

Source

pub fn on_chain_program_state( &self, program: &Program<N>, ) -> Result<OnChainProgramState>

Check the on-chain version of a program to determine if it is deployed, and if so, if it is the same as the local version

Source

pub fn get_mapping_value( &self, program_id: impl TryInto<ProgramID<N>>, mapping_name: impl TryInto<Identifier<N>>, key: impl TryInto<Plaintext<N>>, ) -> Result<Value<N>>

Check the value of an on-chain mapping

Source

pub fn get_mappings( &self, program_id: impl TryInto<ProgramID<N>>, ) -> Result<Vec<Identifier<N>>>

Check the mappings available in a program

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn find_program(&self, program_id: &ProgramID<N>) -> Result<Program<N>>

Find a program by first looking on disk, and if not found, on the aleo network

Source

pub fn find_program_on_disk( &self, program_id: &ProgramID<N>, ) -> Result<Program<N>>

Load a program from a local program directory

Source

pub fn find_program_on_chain( &self, program_id: &ProgramID<N>, ) -> Result<Program<N>>

Load a program from the network

Source

pub fn find_program_imports( &self, program: &Program<N>, ) -> Result<Vec<Program<N>>>

Find a program’s imports by first searching on disk, and if not found, on the aleo network

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn transfer( &self, amount: u64, fee: u64, recipient_address: Address<N>, transfer_type: TransferType, password: Option<&str>, amount_record: Option<Record<N, Plaintext<N>>>, fee_record: Option<Record<N, Plaintext<N>>>, ) -> Result<String>

Executes a transfer to the specified recipient_address with the specified amount and fee. Specify 0 for no fee.

Source§

impl<N: Network> ProgramManager<N>

Source

pub fn new( private_key: Option<PrivateKey<N>>, private_key_ciphertext: Option<Ciphertext<N>>, api_client: Option<AleoAPIClient<N>>, local_program_directory: Option<PathBuf>, use_cache: bool, ) -> Result<Self>

Create a new program manager by specifying custom options for the private key (or private key ciphertext) and resolver. Use this method if you want to create a custom resolver (i.e. one that searches a local or remote database) for program and record resolution.

Source

pub fn add_program(&mut self, program: &Program<N>) -> Result<()>

Manually add a program to the program manager from memory if it does not already exist

Source

pub fn initialize_vm( api_client: &AleoAPIClient<N>, program: &Program<N>, initialize_execution: bool, ) -> Result<VM<N, ConsensusMemory<N>>>

Initialize a SnarkVM instance with a program and its imports

Source

pub fn update_program(&mut self, program: &Program<N>) -> Option<Program<N>>

Manually add a program to the program manager if it does not already exist or update it if it does

Source

pub fn get_program( &self, program_id: impl TryInto<ProgramID<N>>, ) -> Result<Program<N>>

Retrieve a program from the program manager if it exists

Source

pub fn contains_program( &self, program_id: impl TryInto<ProgramID<N>>, ) -> Result<bool>

Determine if a program exists in the program manager

Source

pub fn vm(&self) -> &Option<VM<N, ConsensusMemory<N>>>

Trait Implementations§

Source§

impl<N: Clone + Network> Clone for ProgramManager<N>

Source§

fn clone(&self) -> ProgramManager<N>

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<N> Freeze for ProgramManager<N>
where <N as Environment>::Field: Freeze, <N as Environment>::Scalar: Freeze,

§

impl<N> !RefUnwindSafe for ProgramManager<N>

§

impl<N> Send for ProgramManager<N>

§

impl<N> Sync for ProgramManager<N>

§

impl<N> Unpin for ProgramManager<N>

§

impl<N> !UnwindSafe for ProgramManager<N>

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

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

Source§

impl<T> MaybeSendSync for T