pub struct Program(/* private fields */);
Expand description

Webassembly Representation of an Aleo program

Implementations§

source§

impl Program

source

pub fn from_string(program: &str) -> Result<Program, String>

Create a program from a program string

@param {string} program Aleo program source code @returns {Program | Error} Program object

source

pub fn to_string(&self) -> String

Get a string representation of the program

@returns {string} String containing the program source code

source

pub fn has_function(&self, function_name: &str) -> bool

Determine if a function is present in the program

@param {string} functionName Name of the function to check for @returns {boolean} True if the program is valid, false otherwise

source

pub fn get_functions(&self) -> Array

Get javascript array of functions names in the program

@returns {Array} Array of all function names present in the program

@example const expected_functions = [ “mint”, “transfer_private”, “transfer_private_to_public”, “transfer_public”, “transfer_public_to_private”, “join”, “split”, “fee” ]

const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_functions = credits_program.getFunctions(); console.log(credits_functions === expected_functions); // Output should be “true”

source

pub fn get_function_inputs( &self, function_name: String ) -> Result<Array, String>

Get a javascript object representation of the function inputs and types. This can be used to generate a web form to capture user inputs for an execution of a function.

@param {string} function_name Name of the function to get inputs for @returns {Array | Error} Array of function inputs

@example const expected_inputs = [ { type:“record”, visibility:“private”, record:“credits”, members:[ { name:“microcredits”, type:“u64”, visibility:“private” } ], register:“r0” }, { type:“address”, visibility:“private”, register:“r1” }, { type:“u64”, visibility:“private”, register:“r2” } ];

const credits_program = aleo_wasm.Program.getCreditsProgram(); const transfer_function_inputs = credits_program.getFunctionInputs(“transfer_private”); console.log(transfer_function_inputs === expected_inputs); // Output should be “true”

source

pub fn get_mappings(&self) -> Result<Array, String>

Get a the list of a program’s mappings and the names/types of their keys and values.

@returns {Array | Error} - An array of objects representing the mappings in the program @example const expected_mappings = [ { name: “account”, key_name: “owner”, key_type: “address”, value_name: “microcredits”, value_type: “u64” } ]

const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_mappings = credits_program.getMappings(); console.log(credits_mappings === expected_mappings); // Output should be “true”

source

pub fn get_record_members(&self, record_name: String) -> Result<Object, String>

Get a javascript object representation of a program record and its types

@param {string} record_name Name of the record to get members for @returns {Object | Error} Object containing the record name, type, and members

@example

const expected_record = { type: “record”, record: “Credits”, members: [ { name: “owner”, type: “address”, visibility: “private” }, { name: “microcredits”, type: “u64”, visibility: “private” } ]; };

const credits_program = aleo_wasm.Program.getCreditsProgram(); const credits_record = credits_program.getRecordMembers(“Credits”); console.log(credits_record === expected_record); // Output should be “true”

source

pub fn get_struct_members(&self, struct_name: String) -> Result<Array, String>

Get a javascript object representation of a program struct and its types

@param {string} struct_name Name of the struct to get members for @returns {Array | Error} Array containing the struct members

@example

const STRUCT_PROGRAM = “program token_issue.aleo;

struct token_metadata: network as u32; version as u32;

struct token: token_id as u32; metadata as token_metadata;

function no_op: input r0 as u64; output r0 as u64;“

const expected_struct_members = [ { name: “token_id”, type: “u32”, }, { name: “metadata”, type: “struct”, struct_id: “token_metadata”, members: [ { name: “network”, type: “u32”, } { name: “version”, type: “u32”, } ] } ];

const program = aleo_wasm.Program.fromString(STRUCT_PROGRAM); const struct_members = program.getStructMembers(“token”); console.log(struct_members === expected_struct_members); // Output should be “true”

source

pub fn get_credits_program() -> Program

Get the credits.aleo program

@returns {Program} The credits.aleo program

source

pub fn id(&self) -> String

Get the id of the program

@returns {string} The id of the program

source

pub fn is_equal(&self, other: &Program) -> bool

Determine equality with another program

@param {Program} other The other program to compare @returns {boolean} True if the programs are equal, false otherwise

source

pub fn get_imports(&self) -> Array

Get program_imports

@returns {Array} The program imports

@example

const DOUBLE_TEST = “import multiply_test.aleo;

program double_test.aleo;

function double_it: input r0 as u32.private; call multiply_test.aleo/multiply 2u32 r0 into r1; output r1 as u32.private;“;

const expected_imports = [ “multiply_test.aleo” ];

const program = aleo_wasm.Program.fromString(DOUBLE_TEST_PROGRAM); const imports = program.getImports(); console.log(imports === expected_imports); // Output should be “true”

Methods from Deref<Target = Program<Testnet3>>§

pub fn id(&self) -> &ProgramID<N>

Returns the ID of the program.

pub fn imports(&self) -> &IndexMap<ProgramID<N>, Import<N>>

Returns the imports in the program.

pub fn mappings(&self) -> &IndexMap<Identifier<N>, Mapping<N>>

Returns the mappings in the program.

pub fn structs(&self) -> &IndexMap<Identifier<N>, StructType<N>>

Returns the structs in the program.

pub fn records(&self) -> &IndexMap<Identifier<N>, RecordType<N>>

Returns the records in the program.

pub fn closures(&self) -> &IndexMap<Identifier<N>, ClosureCore<N, Instruction>>

Returns the closures in the program.

pub fn functions( &self ) -> &IndexMap<Identifier<N>, FunctionCore<N, Instruction, Command>>

Returns the functions in the program.

pub fn contains_import(&self, id: &ProgramID<N>) -> bool

Returns true if the program contains an import with the given program ID.

pub fn contains_mapping(&self, name: &Identifier<N>) -> bool

Returns true if the program contains a mapping with the given name.

pub fn contains_struct(&self, name: &Identifier<N>) -> bool

Returns true if the program contains a struct with the given name.

pub fn contains_record(&self, name: &Identifier<N>) -> bool

Returns true if the program contains a record with the given name.

pub fn contains_closure(&self, name: &Identifier<N>) -> bool

Returns true if the program contains a closure with the given name.

pub fn contains_function(&self, name: &Identifier<N>) -> bool

Returns true if the program contains a function with the given name.

pub fn get_mapping(&self, name: &Identifier<N>) -> Result<Mapping<N>, Error>

Returns the mapping with the given name.

pub fn get_struct(&self, name: &Identifier<N>) -> Result<&StructType<N>, Error>

Returns the struct with the given name.

pub fn get_record(&self, name: &Identifier<N>) -> Result<&RecordType<N>, Error>

Returns the record with the given name.

pub fn get_closure( &self, name: &Identifier<N> ) -> Result<ClosureCore<N, Instruction>, Error>

Returns the closure with the given name.

pub fn get_function( &self, name: &Identifier<N> ) -> Result<FunctionCore<N, Instruction, Command>, Error>

Returns the function with the given name.

pub fn get_function_ref( &self, name: &Identifier<N> ) -> Result<&FunctionCore<N, Instruction, Command>, Error>

Returns a reference to the function with the given name.

Trait Implementations§

source§

impl Clone for Program

source§

fn clone(&self) -> Program

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

impl Debug for Program

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Program

§

type Target = ProgramCore<Testnet3, Instruction<Testnet3>, Command<Testnet3>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<Program> for JsValue

source§

fn from(value: Program) -> Self

Converts to this type from the input type.
source§

impl From<Program> for Program<Testnet3>

source§

fn from(program: Program) -> Self

Converts to this type from the input type.
source§

impl From<ProgramCore<Testnet3, Instruction<Testnet3>, Command<Testnet3>>> for Program

source§

fn from(value: Program<Testnet3>) -> Self

Converts to this type from the input type.
source§

impl FromStr for Program

§

type Err = String

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl FromWasmAbi for Program

§

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary.
source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
source§

impl IntoWasmAbi for Program

§

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary.
source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
source§

impl LongRefFromWasmAbi for Program

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = Ref<'static, Program>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl OptionFromWasmAbi for Program

source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
source§

impl OptionIntoWasmAbi for Program

source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
source§

impl PartialEq for Program

source§

fn eq(&self, other: &Program) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RefFromWasmAbi for Program

§

type Abi = u32

The wasm ABI type references to Self are recovered from.
§

type Anchor = Ref<'static, Program>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
source§

impl RefMutFromWasmAbi for Program

§

type Abi = u32

Same as RefFromWasmAbi::Abi
§

type Anchor = RefMut<'static, Program>

Same as RefFromWasmAbi::Anchor
source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
source§

impl TryFromJsValue for Program

§

type Error = JsValue

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

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl VectorFromWasmAbi for Program

§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Program]>

source§

impl VectorIntoWasmAbi for Program

§

type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi

source§

fn vector_into_abi(vector: Box<[Program]>) -> Self::Abi

source§

impl WasmDescribe for Program

source§

impl WasmDescribeVector for Program

source§

impl Eq for Program

source§

impl StructuralEq for Program

source§

impl StructuralPartialEq for Program

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ReturnWasmAbi for Twhere T: IntoWasmAbi,

§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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