Skip to content

Commit

Permalink
Merge pull request #37 from multiversx/transf-exec-by-user
Browse files Browse the repository at this point in the history
new VM hooks - transfer execute by user
  • Loading branch information
andrei-marinica authored Apr 11, 2024
2 parents 9626452 + 70e9ce9 commit 62f1314
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions c-api/src/capi_vm_hook_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ pub struct vm_exec_vm_hook_c_func_pointers {
pub managed_sc_address_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32),
pub managed_owner_address_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32),
pub managed_caller_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32),
pub managed_get_original_caller_addr_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32),
pub managed_get_relayer_addr_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32),
pub managed_signal_error_func_ptr: extern "C" fn(context: *mut c_void, err_handle: i32),
pub managed_write_log_func_ptr: extern "C" fn(context: *mut c_void, topics_handle: i32, data_handle: i32),
pub managed_get_original_tx_hash_func_ptr: extern "C" fn(context: *mut c_void, result_handle: i32),
Expand All @@ -116,6 +118,7 @@ pub struct vm_exec_vm_hook_c_func_pointers {
pub managed_execute_on_same_context_func_ptr: extern "C" fn(context: *mut c_void, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32,
pub managed_execute_on_dest_context_func_ptr: extern "C" fn(context: *mut c_void, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32,
pub managed_multi_transfer_esdt_nft_execute_func_ptr: extern "C" fn(context: *mut c_void, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32,
pub managed_multi_transfer_esdt_nft_execute_by_user_func_ptr: extern "C" fn(context: *mut c_void, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32,
pub managed_transfer_value_execute_func_ptr: extern "C" fn(context: *mut c_void, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32,
pub managed_is_esdt_frozen_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64) -> i32,
pub managed_is_esdt_limited_transfer_func_ptr: extern "C" fn(context: *mut c_void, token_id_handle: i32) -> i32,
Expand Down
12 changes: 12 additions & 0 deletions c-api/src/capi_vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks {
(self.c_func_pointers_ptr.managed_caller_func_ptr)(self.vm_hooks_ptr, destination_handle)
}

fn managed_get_original_caller_addr(&self, destination_handle: i32) {
(self.c_func_pointers_ptr.managed_get_original_caller_addr_func_ptr)(self.vm_hooks_ptr, destination_handle)
}

fn managed_get_relayer_addr(&self, destination_handle: i32) {
(self.c_func_pointers_ptr.managed_get_relayer_addr_func_ptr)(self.vm_hooks_ptr, destination_handle)
}

fn managed_signal_error(&self, err_handle: i32) {
(self.c_func_pointers_ptr.managed_signal_error_func_ptr)(self.vm_hooks_ptr, err_handle)
}
Expand Down Expand Up @@ -463,6 +471,10 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks {
(self.c_func_pointers_ptr.managed_multi_transfer_esdt_nft_execute_func_ptr)(self.vm_hooks_ptr, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle)
}

fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_multi_transfer_esdt_nft_execute_by_user_func_ptr)(self.vm_hooks_ptr, user_handle, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle)
}

fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
(self.c_func_pointers_ptr.managed_transfer_value_execute_func_ptr)(self.vm_hooks_ptr, dst_handle, value_handle, gas_limit, function_handle, arguments_handle)
}
Expand Down
18 changes: 18 additions & 0 deletions vm-executor-wasmer/src/wasmer_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ fn wasmer_import_managed_caller(env: &VMHooksWrapper, destination_handle: i32) {
env.vm_hooks.managed_caller(destination_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_get_original_caller_addr(env: &VMHooksWrapper, destination_handle: i32) {
env.vm_hooks.managed_get_original_caller_addr(destination_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_get_relayer_addr(env: &VMHooksWrapper, destination_handle: i32) {
env.vm_hooks.managed_get_relayer_addr(destination_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_signal_error(env: &VMHooksWrapper, err_handle: i32) {
env.vm_hooks.managed_signal_error(err_handle)
Expand Down Expand Up @@ -540,6 +550,11 @@ fn wasmer_import_managed_multi_transfer_esdt_nft_execute(env: &VMHooksWrapper, d
env.vm_hooks.managed_multi_transfer_esdt_nft_execute(dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_multi_transfer_esdt_nft_execute_by_user(env: &VMHooksWrapper, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
env.vm_hooks.managed_multi_transfer_esdt_nft_execute_by_user(user_handle, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_transfer_value_execute(env: &VMHooksWrapper, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
env.vm_hooks.managed_transfer_value_execute(dst_handle, value_handle, gas_limit, function_handle, arguments_handle)
Expand Down Expand Up @@ -1386,6 +1401,8 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje
"managedSCAddress" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_sc_address),
"managedOwnerAddress" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_owner_address),
"managedCaller" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_caller),
"managedGetOriginalCallerAddr" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_original_caller_addr),
"managedGetRelayerAddr" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_relayer_addr),
"managedSignalError" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_signal_error),
"managedWriteLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_write_log),
"managedGetOriginalTxHash" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_original_tx_hash),
Expand All @@ -1409,6 +1426,7 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje
"managedExecuteOnSameContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_execute_on_same_context),
"managedExecuteOnDestContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_execute_on_dest_context),
"managedMultiTransferESDTNFTExecute" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_multi_transfer_esdt_nft_execute),
"managedMultiTransferESDTNFTExecuteByUser" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_multi_transfer_esdt_nft_execute_by_user),
"managedTransferValueExecute" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_transfer_value_execute),
"managedIsESDTFrozen" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_is_esdt_frozen),
"managedIsESDTLimitedTransfer" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_is_esdt_limited_transfer),
Expand Down
16 changes: 16 additions & 0 deletions vm-executor/src/vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub trait VMHooks: core::fmt::Debug + 'static {
fn managed_sc_address(&self, destination_handle: i32);
fn managed_owner_address(&self, destination_handle: i32);
fn managed_caller(&self, destination_handle: i32);
fn managed_get_original_caller_addr(&self, destination_handle: i32);
fn managed_get_relayer_addr(&self, destination_handle: i32);
fn managed_signal_error(&self, err_handle: i32);
fn managed_write_log(&self, topics_handle: i32, data_handle: i32);
fn managed_get_original_tx_hash(&self, result_handle: i32);
Expand All @@ -119,6 +121,7 @@ pub trait VMHooks: core::fmt::Debug + 'static {
fn managed_execute_on_same_context(&self, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32;
fn managed_execute_on_dest_context(&self, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32;
fn managed_multi_transfer_esdt_nft_execute(&self, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32;
fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32;
fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32;
fn managed_is_esdt_frozen(&self, address_handle: i32, token_id_handle: i32, nonce: i64) -> i32;
fn managed_is_esdt_limited_transfer(&self, token_id_handle: i32) -> i32;
Expand Down Expand Up @@ -674,6 +677,14 @@ impl VMHooks for VMHooksDefault {
println!("Called: managed_caller");
}

fn managed_get_original_caller_addr(&self, destination_handle: i32) {
println!("Called: managed_get_original_caller_addr");
}

fn managed_get_relayer_addr(&self, destination_handle: i32) {
println!("Called: managed_get_relayer_addr");
}

fn managed_signal_error(&self, err_handle: i32) {
println!("Called: managed_signal_error");
}
Expand Down Expand Up @@ -773,6 +784,11 @@ impl VMHooks for VMHooksDefault {
0
}

fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
println!("Called: managed_multi_transfer_esdt_nft_execute_by_user");
0
}

fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 {
println!("Called: managed_transfer_value_execute");
0
Expand Down

0 comments on commit 62f1314

Please sign in to comment.