Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add managed get esdt token type hook #55

Merged
merged 5 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions c-api/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ typedef struct {
void (*managed_get_back_transfers_func_ptr)(void *context, int32_t esdt_transfers_value_handle, int32_t egld_value_handle);
void (*managed_get_esdt_balance_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t value_handle);
void (*managed_get_esdt_token_data_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t value_handle, int32_t properties_handle, int32_t hash_handle, int32_t name_handle, int32_t attributes_handle, int32_t creator_handle, int32_t royalties_handle, int32_t uris_handle);
void (*managed_get_esdt_token_type_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t type_handle);
void (*managed_async_call_func_ptr)(void *context, int32_t dest_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle);
int32_t (*managed_create_async_call_func_ptr)(void *context, int32_t dest_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle, int32_t success_offset, int32_t success_length, int32_t error_offset, int32_t error_length, int64_t gas, int64_t extra_gas_for_callback, int32_t callback_closure_handle);
void (*managed_get_callback_closure_func_ptr)(void *context, int32_t callback_closure_handle);
Expand Down
1 change: 1 addition & 0 deletions c-api/src/capi_vm_hook_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct vm_exec_vm_hook_c_func_pointers {
pub managed_get_back_transfers_func_ptr: extern "C" fn(context: *mut c_void, esdt_transfers_value_handle: i32, egld_value_handle: i32),
pub managed_get_esdt_balance_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32),
pub managed_get_esdt_token_data_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32, properties_handle: i32, hash_handle: i32, name_handle: i32, attributes_handle: i32, creator_handle: i32, royalties_handle: i32, uris_handle: i32),
pub managed_get_esdt_token_type_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64, type_handle: i32),
pub managed_async_call_func_ptr: extern "C" fn(context: *mut c_void, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32),
pub managed_create_async_call_func_ptr: extern "C" fn(context: *mut c_void, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, success_offset: i32, success_length: i32, error_offset: i32, error_length: i32, gas: i64, extra_gas_for_callback: i64, callback_closure_handle: i32) -> i32,
pub managed_get_callback_closure_func_ptr: extern "C" fn(context: *mut c_void, callback_closure_handle: i32),
Expand Down
4 changes: 4 additions & 0 deletions c-api/src/capi_vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks {
(self.c_func_pointers_ptr.managed_get_esdt_token_data_func_ptr)(self.vm_hooks_ptr, address_handle, token_id_handle, nonce, value_handle, properties_handle, hash_handle, name_handle, attributes_handle, creator_handle, royalties_handle, uris_handle)
}

fn managed_get_esdt_token_type(&self, address_handle: i32, token_id_handle: i32, nonce: i64, type_handle: i32) {
(self.c_func_pointers_ptr.managed_get_esdt_token_type_func_ptr)(self.vm_hooks_ptr, address_handle, token_id_handle, nonce, type_handle)
}

fn managed_async_call(&self, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32) {
(self.c_func_pointers_ptr.managed_async_call_func_ptr)(self.vm_hooks_ptr, dest_handle, value_handle, function_handle, arguments_handle)
}
Expand Down
6 changes: 6 additions & 0 deletions vm-executor-wasmer/src/wasmer_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ fn wasmer_import_managed_get_esdt_token_data(env: &VMHooksWrapper, address_handl
env.vm_hooks.managed_get_esdt_token_data(address_handle, token_id_handle, nonce, value_handle, properties_handle, hash_handle, name_handle, attributes_handle, creator_handle, royalties_handle, uris_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_get_esdt_token_type(env: &VMHooksWrapper, address_handle: i32, token_id_handle: i32, nonce: i64, type_handle: i32) {
env.vm_hooks.managed_get_esdt_token_type(address_handle, token_id_handle, nonce, type_handle)
}

#[rustfmt::skip]
fn wasmer_import_managed_async_call(env: &VMHooksWrapper, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32) {
env.vm_hooks.managed_async_call(dest_handle, value_handle, function_handle, arguments_handle)
Expand Down Expand Up @@ -1485,6 +1490,7 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje
"managedGetBackTransfers" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_back_transfers),
"managedGetESDTBalance" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_esdt_balance),
"managedGetESDTTokenData" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_esdt_token_data),
"managedGetESDTTokenType" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_esdt_token_type),
"managedAsyncCall" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_async_call),
"managedCreateAsyncCall" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_create_async_call),
"managedGetCallbackClosure" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_callback_closure),
Expand Down
5 changes: 5 additions & 0 deletions vm-executor/src/vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub trait VMHooks: core::fmt::Debug + 'static {
fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, egld_value_handle: i32);
fn managed_get_esdt_balance(&self, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32);
fn managed_get_esdt_token_data(&self, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32, properties_handle: i32, hash_handle: i32, name_handle: i32, attributes_handle: i32, creator_handle: i32, royalties_handle: i32, uris_handle: i32);
fn managed_get_esdt_token_type(&self, address_handle: i32, token_id_handle: i32, nonce: i64, type_handle: i32);
fn managed_async_call(&self, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32);
fn managed_create_async_call(&self, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, success_offset: MemPtr, success_length: MemLength, error_offset: MemPtr, error_length: MemLength, gas: i64, extra_gas_for_callback: i64, callback_closure_handle: i32) -> i32;
fn managed_get_callback_closure(&self, callback_closure_handle: i32);
Expand Down Expand Up @@ -771,6 +772,10 @@ impl VMHooks for VMHooksDefault {
println!("Called: managed_get_esdt_token_data");
}

fn managed_get_esdt_token_type(&self, address_handle: i32, token_id_handle: i32, nonce: i64, type_handle: i32) {
println!("Called: managed_get_esdt_token_type");
}

fn managed_async_call(&self, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32) {
println!("Called: managed_async_call");
}
Expand Down
Loading