pub struct Program(/* private fields */);
Expand description
Webassembly Representation of an Aleo program
Implementations§
source§impl Program
impl Program
sourcepub fn from_string(program: &str) -> Result<Program, String>
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
sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Get a string representation of the program
@returns {string} String containing the program source code
sourcepub fn has_function(&self, function_name: &str) -> bool
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
sourcepub fn get_functions(&self) -> Array
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”
sourcepub fn get_function_inputs(
&self,
function_name: String
) -> Result<Array, String>
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”
sourcepub fn get_mappings(&self) -> Result<Array, String>
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”
sourcepub fn get_record_members(&self, record_name: String) -> Result<Object, String>
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”
sourcepub fn get_struct_members(&self, struct_name: String) -> Result<Array, String>
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”
sourcepub fn get_credits_program() -> Program
pub fn get_credits_program() -> Program
Get the credits.aleo program
@returns {Program} The credits.aleo program
sourcepub fn is_equal(&self, other: &Program) -> bool
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
sourcepub fn get_imports(&self) -> Array
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>
pub fn id(&self) -> &ProgramID<N>
Returns the ID of the program.
pub fn closures(&self) -> &IndexMap<Identifier<N>, ClosureCore<N, Instruction>>
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>>
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
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
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
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
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
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
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>
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>
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>
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>
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>
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>
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 FromWasmAbi for Program
impl FromWasmAbi for Program
source§impl IntoWasmAbi for Program
impl IntoWasmAbi for Program
source§impl LongRefFromWasmAbi for Program
impl LongRefFromWasmAbi for Program
source§impl OptionFromWasmAbi for Program
impl OptionFromWasmAbi for Program
source§impl OptionIntoWasmAbi for Program
impl OptionIntoWasmAbi for Program
source§impl PartialEq for Program
impl PartialEq for Program
source§impl RefFromWasmAbi for Program
impl RefFromWasmAbi for Program
source§impl RefMutFromWasmAbi for Program
impl RefMutFromWasmAbi for Program
source§impl TryFromJsValue for Program
impl TryFromJsValue for Program
source§impl VectorFromWasmAbi for Program
impl VectorFromWasmAbi for Program
source§impl VectorIntoWasmAbi for Program
impl VectorIntoWasmAbi for Program
impl Eq for Program
impl StructuralEq for Program
impl StructuralPartialEq for Program
Auto Trait Implementations§
impl RefUnwindSafe for Program
impl Send for Program
impl Sync for Program
impl Unpin for Program
impl UnwindSafe for Program
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.