Skip to content

Commit

Permalink
Merge #276
Browse files Browse the repository at this point in the history
276: get_operation_id r=Eitu33 a=Eitu33



Co-authored-by: Thomas Plisson <[email protected]>
  • Loading branch information
bors[bot] and Eitu33 authored Jul 5, 2023
2 parents 3da4a73 + 38c6320 commit ca2c7f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/as_execution/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,20 @@ pub(crate) fn assembly_script_send_message(
Ok(())
}

/// converts a public key to an address
#[named]
pub(crate) fn assembly_script_get_origin_operation_id(
mut ctx: FunctionEnvMut<ASEnv>,
) -> ABIResult<i32> {
let env = get_env(&ctx)?;
sub_remaining_gas_abi(&env, &mut ctx, function_name!())?;
let operation_id = env
.get_interface()
.get_origin_operation_id()?
.unwrap_or_default();
Ok(pointer_from_string(&env, &mut ctx, &operation_id)?.offset() as i32)
}

/// gets the period of the current execution slot
#[named]
pub(crate) fn assembly_script_get_current_period(mut ctx: FunctionEnvMut<ASEnv>) -> ABIResult<i64> {
Expand Down
1 change: 1 addition & 0 deletions src/as_execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ impl ASContext {
"assembly_script_get_call_coins" => Function::new_typed_with_env(store, &fenv, assembly_script_get_call_coins),
"assembly_script_get_time" => Function::new_typed_with_env(store, &fenv, assembly_script_get_time),
"assembly_script_send_message" => Function::new_typed_with_env(store, &fenv, assembly_script_send_message),
"assembly_script_get_origin_operation_id" => Function::new_typed_with_env(store, &fenv, assembly_script_get_origin_operation_id),
"assembly_script_get_current_period" => Function::new_typed_with_env(store, &fenv, assembly_script_get_current_period),
"assembly_script_get_current_thread" => Function::new_typed_with_env(store, &fenv, assembly_script_get_current_thread),
"assembly_script_set_bytecode" => Function::new_typed_with_env(store, &fenv, assembly_script_set_bytecode),
Expand Down
6 changes: 6 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl Default for GasCosts {
abi_costs.insert(String::from("assembly_script_keccak256_hash"), 83);
abi_costs.insert(String::from("assembly_script_print"), 35);
abi_costs.insert(String::from("assembly_script_send_message"), 316);
abi_costs.insert(String::from("assembly_script_get_origin_operation_id"), 200);
abi_costs.insert(String::from("assembly_script_set_bytecode"), 74);
abi_costs.insert(String::from("assembly_script_set_bytecode_for"), 129);
abi_costs.insert(String::from("assembly_script_set_data"), 158);
Expand Down Expand Up @@ -412,6 +413,11 @@ pub trait Interface: Send + Sync + InterfaceClone {
unimplemented!("send_message")
}

// Returns the operation id that originated the current execution if there is one
fn get_origin_operation_id(&self) -> Result<Option<String>> {
unimplemented!("get_origin_operation_id")
}

// Sha256 hash bytes
fn hash_sha256(&self, bytes: &[u8]) -> Result<[u8; 32]> {
unimplemented!("hash_sha256")
Expand Down

0 comments on commit ca2c7f1

Please sign in to comment.