diff --git a/near-sdk/src/environment/env.rs b/near-sdk/src/environment/env.rs index 34c3be99c..4ce04f0a1 100644 --- a/near-sdk/src/environment/env.rs +++ b/near-sdk/src/environment/env.rs @@ -456,7 +456,7 @@ pub fn promise_create( ) -> PromiseIndex { let account_id = account_id.as_bytes(); unsafe { - sys::promise_create( + PromiseIndex(sys::promise_create( account_id.len() as _, account_id.as_ptr() as _, function_name.len() as _, @@ -465,7 +465,7 @@ pub fn promise_create( arguments.as_ptr() as _, &amount as *const Balance as _, gas.0, - ) + )) } } @@ -480,8 +480,8 @@ pub fn promise_then( ) -> PromiseIndex { let account_id = account_id.as_bytes(); unsafe { - sys::promise_then( - promise_idx, + PromiseIndex(sys::promise_then( + promise_idx.0, account_id.len() as _, account_id.as_ptr() as _, function_name.len() as _, @@ -490,7 +490,7 @@ pub fn promise_then( arguments.as_ptr() as _, &amount as *const Balance as _, gas.0, - ) + )) } } @@ -499,31 +499,37 @@ pub fn promise_and(promise_indices: &[PromiseIndex]) -> PromiseIndex { let mut data = vec![0u8; size_of_val(promise_indices)]; for i in 0..promise_indices.len() { data[i * size_of::()..(i + 1) * size_of::()] - .copy_from_slice(&promise_indices[i].to_le_bytes()); + .copy_from_slice(&promise_indices[i].0.to_le_bytes()); } - unsafe { sys::promise_and(data.as_ptr() as _, promise_indices.len() as _) } + unsafe { PromiseIndex(sys::promise_and(data.as_ptr() as _, promise_indices.len() as _)) } } pub fn promise_batch_create(account_id: &AccountId) -> PromiseIndex { let account_id = account_id.as_ref(); - unsafe { sys::promise_batch_create(account_id.len() as _, account_id.as_ptr() as _) } + unsafe { + PromiseIndex(sys::promise_batch_create(account_id.len() as _, account_id.as_ptr() as _)) + } } pub fn promise_batch_then(promise_index: PromiseIndex, account_id: &AccountId) -> PromiseIndex { let account_id: &str = account_id.as_ref(); unsafe { - sys::promise_batch_then(promise_index, account_id.len() as _, account_id.as_ptr() as _) + PromiseIndex(sys::promise_batch_then( + promise_index.0, + account_id.len() as _, + account_id.as_ptr() as _, + )) } } pub fn promise_batch_action_create_account(promise_index: PromiseIndex) { - unsafe { sys::promise_batch_action_create_account(promise_index) } + unsafe { sys::promise_batch_action_create_account(promise_index.0) } } -pub fn promise_batch_action_deploy_contract(promise_index: u64, code: &[u8]) { +pub fn promise_batch_action_deploy_contract(promise_index: PromiseIndex, code: &[u8]) { unsafe { sys::promise_batch_action_deploy_contract( - promise_index, + promise_index.0, code.len() as _, code.as_ptr() as _, ) @@ -539,7 +545,7 @@ pub fn promise_batch_action_function_call( ) { unsafe { sys::promise_batch_action_function_call( - promise_index, + promise_index.0, function_name.len() as _, function_name.as_ptr() as _, arguments.len() as _, @@ -560,7 +566,7 @@ pub fn promise_batch_action_function_call_weight( ) { unsafe { sys::promise_batch_action_function_call_weight( - promise_index, + promise_index.0, function_name.len() as _, function_name.as_ptr() as _, arguments.len() as _, @@ -573,7 +579,7 @@ pub fn promise_batch_action_function_call_weight( } pub fn promise_batch_action_transfer(promise_index: PromiseIndex, amount: Balance) { - unsafe { sys::promise_batch_action_transfer(promise_index, &amount as *const Balance as _) } + unsafe { sys::promise_batch_action_transfer(promise_index.0, &amount as *const Balance as _) } } pub fn promise_batch_action_stake( @@ -583,7 +589,7 @@ pub fn promise_batch_action_stake( ) { unsafe { sys::promise_batch_action_stake( - promise_index, + promise_index.0, &amount as *const Balance as _, public_key.as_bytes().len() as _, public_key.as_bytes().as_ptr() as _, @@ -597,7 +603,7 @@ pub fn promise_batch_action_add_key_with_full_access( ) { unsafe { sys::promise_batch_action_add_key_with_full_access( - promise_index, + promise_index.0, public_key.as_bytes().len() as _, public_key.as_bytes().as_ptr() as _, nonce, @@ -645,7 +651,7 @@ pub fn promise_batch_action_add_key_allowance_with_function_call( }; unsafe { sys::promise_batch_action_add_key_with_function_call( - promise_index, + promise_index.0, public_key.as_bytes().len() as _, public_key.as_bytes().as_ptr() as _, nonce, @@ -660,7 +666,7 @@ pub fn promise_batch_action_add_key_allowance_with_function_call( pub fn promise_batch_action_delete_key(promise_index: PromiseIndex, public_key: &PublicKey) { unsafe { sys::promise_batch_action_delete_key( - promise_index, + promise_index.0, public_key.as_bytes().len() as _, public_key.as_bytes().as_ptr() as _, ) @@ -674,7 +680,7 @@ pub fn promise_batch_action_delete_account( let beneficiary_id: &str = beneficiary_id.as_ref(); unsafe { sys::promise_batch_action_delete_account( - promise_index, + promise_index.0, beneficiary_id.len() as _, beneficiary_id.as_ptr() as _, ) @@ -709,7 +715,7 @@ pub(crate) fn promise_result_internal(result_idx: u64) -> Result<(), PromiseErro /// Consider the execution result of promise under `promise_idx` as execution result of this /// function. pub fn promise_return(promise_idx: PromiseIndex) { - unsafe { sys::promise_return(promise_idx) } + unsafe { sys::promise_return(promise_idx.0) } } // ############### diff --git a/near-sdk/src/types/vm_types.rs b/near-sdk/src/types/vm_types.rs index 84bdf12ea..9f6d714c4 100644 --- a/near-sdk/src/types/vm_types.rs +++ b/near-sdk/src/types/vm_types.rs @@ -3,7 +3,9 @@ pub use near_vm_logic::types::{PromiseResult as VmPromiseResult, ReturnData}; //* Types from near_vm_logic /// Promise index that is computed only once. -pub type PromiseIndex = u64; +#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Copy, Clone)] +pub struct PromiseIndex(pub(crate) u64); + /// An index of Receipt to append an action #[deprecated(since = "4.1.0", note = "type not used within SDK, use u64 directly or another alias")] pub type ReceiptIndex = u64;