sui_move_natives_v1/
object.rsuse crate::{object_runtime::ObjectRuntime, NativesCostTable};
use move_binary_format::errors::PartialVMResult;
use move_core_types::{account_address::AccountAddress, gas_algebra::InternalGas};
use move_vm_runtime::{native_charge_gas_early_exit, native_functions::NativeContext};
use move_vm_types::{
loaded_data::runtime_types::Type,
natives::function::NativeResult,
pop_arg,
values::{StructRef, Value},
};
use smallvec::smallvec;
use std::collections::VecDeque;
#[derive(Clone)]
pub struct BorrowUidCostParams {
pub object_borrow_uid_cost_base: InternalGas,
}
pub fn borrow_uid(
context: &mut NativeContext,
ty_args: Vec<Type>,
mut args: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
debug_assert!(ty_args.len() == 1);
debug_assert!(args.len() == 1);
let borrow_uid_cost_params = context
.extensions_mut()
.get::<NativesCostTable>()
.borrow_uid_cost_params
.clone();
native_charge_gas_early_exit!(context, borrow_uid_cost_params.object_borrow_uid_cost_base);
let obj = pop_arg!(args, StructRef);
let id_field = obj.borrow_field(0)?;
Ok(NativeResult::ok(context.gas_used(), smallvec![id_field]))
}
#[derive(Clone)]
pub struct DeleteImplCostParams {
pub object_delete_impl_cost_base: InternalGas,
}
pub fn delete_impl(
context: &mut NativeContext,
ty_args: Vec<Type>,
mut args: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
debug_assert!(ty_args.is_empty());
debug_assert!(args.len() == 1);
let delete_impl_cost_params = context
.extensions_mut()
.get::<NativesCostTable>()
.delete_impl_cost_params
.clone();
native_charge_gas_early_exit!(
context,
delete_impl_cost_params.object_delete_impl_cost_base
);
let uid_bytes = pop_arg!(args, AccountAddress);
let obj_runtime: &mut ObjectRuntime = context.extensions_mut().get_mut();
obj_runtime.delete_id(uid_bytes.into())?;
Ok(NativeResult::ok(context.gas_used(), smallvec![]))
}
#[derive(Clone)]
pub struct RecordNewIdCostParams {
pub object_record_new_uid_cost_base: InternalGas,
}
pub fn record_new_uid(
context: &mut NativeContext,
ty_args: Vec<Type>,
mut args: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
debug_assert!(ty_args.is_empty());
debug_assert!(args.len() == 1);
let record_new_id_cost_params = context
.extensions_mut()
.get::<NativesCostTable>()
.record_new_id_cost_params
.clone();
native_charge_gas_early_exit!(
context,
record_new_id_cost_params.object_record_new_uid_cost_base
);
let uid_bytes = pop_arg!(args, AccountAddress);
let obj_runtime: &mut ObjectRuntime = context.extensions_mut().get_mut();
obj_runtime.new_id(uid_bytes.into())?;
Ok(NativeResult::ok(context.gas_used(), smallvec![]))
}