pub struct ExecutionContext<'vm, 'state, 'a> {
pub protocol_config: &'a ProtocolConfig,
pub metrics: Arc<LimitsMetrics>,
pub vm: &'vm MoveVM,
pub state_view: &'state dyn ExecutionState,
pub tx_context: &'a mut TxContext,
pub gas_charger: &'a mut GasCharger,
pub session: Session<'state, 'vm, LinkageView<'state>>,
/* private fields */
}
Expand description
Maintains all runtime state specific to programmable transactions
Fields§
§protocol_config: &'a ProtocolConfig
The protocol config
metrics: Arc<LimitsMetrics>
Metrics for reporting exceeded limits
vm: &'vm MoveVM
The MoveVM
state_view: &'state dyn ExecutionState
The global state, used for resolving packages
tx_context: &'a mut TxContext
A shared transaction context, contains transaction digest information and manages the creation of new object IDs
gas_charger: &'a mut GasCharger
The gas charger used for metering
session: Session<'state, 'vm, LinkageView<'state>>
The session used for interacting with Move types and calls
Implementations§
Source§impl<'vm, 'state, 'a> ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> ExecutionContext<'vm, 'state, 'a>
pub fn new( protocol_config: &'a ProtocolConfig, metrics: Arc<LimitsMetrics>, vm: &'vm MoveVM, state_view: &'state dyn ExecutionState, tx_context: &'a mut TxContext, gas_charger: &'a mut GasCharger, inputs: Vec<CallArg>, ) -> Result<Self, ExecutionError>
Sourcepub fn fresh_id(&mut self) -> Result<ObjectID, ExecutionError>
pub fn fresh_id(&mut self) -> Result<ObjectID, ExecutionError>
Create a new ID and update the state
Sourcepub fn delete_id(&mut self, object_id: ObjectID) -> Result<(), ExecutionError>
pub fn delete_id(&mut self, object_id: ObjectID) -> Result<(), ExecutionError>
Delete an ID and update the state
Sourcepub fn set_link_context(
&mut self,
package_id: ObjectID,
) -> Result<AccountAddress, ExecutionError>
pub fn set_link_context( &mut self, package_id: ObjectID, ) -> Result<AccountAddress, ExecutionError>
Set the link context for the session from the linkage information in the MovePackage found
at package_id
. Returns the runtime ID of the link context package on success.
Sourcepub fn set_linkage(
&mut self,
package: &MovePackage,
) -> Result<AccountAddress, ExecutionError>
pub fn set_linkage( &mut self, package: &MovePackage, ) -> Result<AccountAddress, ExecutionError>
Set the link context for the session from the linkage information in the package
. Returns
the runtime ID of the link context package on success.
Sourcepub fn reset_linkage(&mut self)
pub fn reset_linkage(&mut self)
Turn off linkage information, so that the next use of the session will need to set linkage information to succeed.
Sourcepub fn steal_linkage(&mut self) -> Option<SavedLinkage>
pub fn steal_linkage(&mut self) -> Option<SavedLinkage>
Reset the linkage context, and save it (if one exists)
Sourcepub fn restore_linkage(
&mut self,
saved: Option<SavedLinkage>,
) -> Result<(), ExecutionError>
pub fn restore_linkage( &mut self, saved: Option<SavedLinkage>, ) -> Result<(), ExecutionError>
Restore a previously stolen/saved link context.
Sourcepub fn load_type(&mut self, type_tag: &TypeTag) -> VMResult<Type>
pub fn load_type(&mut self, type_tag: &TypeTag) -> VMResult<Type>
Load a type using the context’s current session.
Sourcepub fn take_user_events(
&mut self,
module_id: &ModuleId,
function: FunctionDefinitionIndex,
last_offset: CodeOffset,
) -> Result<(), ExecutionError>
pub fn take_user_events( &mut self, module_id: &ModuleId, function: FunctionDefinitionIndex, last_offset: CodeOffset, ) -> Result<(), ExecutionError>
Takes the user events from the runtime and tags them with the Move module of the function that was invoked for the command
Sourcepub fn by_value_arg<V: TryFromValue>(
&mut self,
command_kind: CommandKind<'_>,
arg_idx: usize,
arg: Argument,
) -> Result<V, ExecutionError>
pub fn by_value_arg<V: TryFromValue>( &mut self, command_kind: CommandKind<'_>, arg_idx: usize, arg: Argument, ) -> Result<V, ExecutionError>
Get the argument value. Cloning the value if it is copyable, and setting its value to None if it is not (making it unavailable). Errors if out of bounds, if the argument is borrowed, if it is unavailable (already taken), or if it is an object that cannot be taken by value (shared or immutable)
Sourcepub fn borrow_arg_mut<V: TryFromValue>(
&mut self,
arg_idx: usize,
arg: Argument,
) -> Result<V, ExecutionError>
pub fn borrow_arg_mut<V: TryFromValue>( &mut self, arg_idx: usize, arg: Argument, ) -> Result<V, ExecutionError>
Mimic a mutable borrow by taking the argument value, setting its value to None, making it unavailable. The value will be marked as borrowed and must be returned with restore_arg Errors if out of bounds, if the argument is borrowed, if it is unavailable (already taken), or if it is an object that cannot be mutably borrowed (immutable)
Sourcepub fn borrow_arg<V: TryFromValue>(
&mut self,
arg_idx: usize,
arg: Argument,
) -> Result<V, ExecutionError>
pub fn borrow_arg<V: TryFromValue>( &mut self, arg_idx: usize, arg: Argument, ) -> Result<V, ExecutionError>
Mimics an immutable borrow by cloning the argument value without setting its value to None Errors if out of bounds, if the argument is mutably borrowed, or if it is unavailable (already taken)
Sourcepub fn restore_arg<Mode: ExecutionMode>(
&mut self,
updates: &mut Mode::ArgumentUpdates,
arg: Argument,
value: Value,
) -> Result<(), ExecutionError>
pub fn restore_arg<Mode: ExecutionMode>( &mut self, updates: &mut Mode::ArgumentUpdates, arg: Argument, value: Value, ) -> Result<(), ExecutionError>
Restore an argument after being mutably borrowed
Sourcepub fn transfer_object(
&mut self,
obj: ObjectValue,
addr: SuiAddress,
) -> Result<(), ExecutionError>
pub fn transfer_object( &mut self, obj: ObjectValue, addr: SuiAddress, ) -> Result<(), ExecutionError>
Transfer the object to a new owner
Sourcepub fn new_package<'p>(
&self,
modules: &[CompiledModule],
dependencies: impl IntoIterator<Item = &'p MovePackage>,
) -> Result<Object, ExecutionError>
pub fn new_package<'p>( &self, modules: &[CompiledModule], dependencies: impl IntoIterator<Item = &'p MovePackage>, ) -> Result<Object, ExecutionError>
Create a new package
Sourcepub fn upgrade_package<'p>(
&self,
storage_id: ObjectID,
previous_package: &MovePackage,
new_modules: &[CompiledModule],
dependencies: impl IntoIterator<Item = &'p MovePackage>,
) -> Result<Object, ExecutionError>
pub fn upgrade_package<'p>( &self, storage_id: ObjectID, previous_package: &MovePackage, new_modules: &[CompiledModule], dependencies: impl IntoIterator<Item = &'p MovePackage>, ) -> Result<Object, ExecutionError>
Create a package upgrade from previous_package
with new_modules
and dependencies
Sourcepub fn write_package(&mut self, package: Object) -> Result<(), ExecutionError>
pub fn write_package(&mut self, package: Object) -> Result<(), ExecutionError>
Add a newly created package to write as an effect of the transaction
Sourcepub fn push_command_results(
&mut self,
results: Vec<Value>,
) -> Result<(), ExecutionError>
pub fn push_command_results( &mut self, results: Vec<Value>, ) -> Result<(), ExecutionError>
Finish a command: clearing the borrows and adding the results to the result vector
Sourcepub fn finish<Mode: ExecutionMode>(
self,
) -> Result<ExecutionResults, ExecutionError>
pub fn finish<Mode: ExecutionMode>( self, ) -> Result<ExecutionResults, ExecutionError>
Determine the object changes and collect all user events
Sourcepub fn convert_vm_error(&self, error: VMError) -> ExecutionError
pub fn convert_vm_error(&self, error: VMError) -> ExecutionError
Convert a VM Error to an execution one
Sourcepub fn convert_type_argument_error(
&self,
idx: usize,
error: VMError,
) -> ExecutionError
pub fn convert_type_argument_error( &self, idx: usize, error: VMError, ) -> ExecutionError
Special case errors for type arguments to Move functions
Trait Implementations§
Source§impl TypeTagResolver for ExecutionContext<'_, '_, '_>
impl TypeTagResolver for ExecutionContext<'_, '_, '_>
fn get_type_tag(&self, type_: &Type) -> Result<TypeTag, ExecutionError>
Auto Trait Implementations§
impl<'vm, 'state, 'a> !Freeze for ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> !RefUnwindSafe for ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> !Send for ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> !Sync for ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> Unpin for ExecutionContext<'vm, 'state, 'a>
impl<'vm, 'state, 'a> !UnwindSafe for ExecutionContext<'vm, 'state, 'a>
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self
to type T
. The semantics of numeric casting with the as
operator are followed, so <T as As>::as_::<U>
can be used in the same way as T as U
for numeric conversions. Read more§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a Request
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered
].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.