pub struct VMHostFunctions<'a> { /* private fields */ }Expand description
The self-referencing struct.
Implementations§
Source§impl VMHostFunctions<'_>
impl VMHostFunctions<'_>
Sourcepub fn blob_create(&mut self) -> VMLogicResult<u64>
pub fn blob_create(&mut self) -> VMLogicResult<u64>
Creates a new blob for writing.
This initializes a blob upload stream and returns a file descriptor (fd) that
can be used with blob_write and blob_close.
§Returns
A u64 file descriptor for the new blob write handle.
§Errors
HostError::BlobsNotSupportedif the node client is not configured.HostError::TooManyBlobHandlesif the maximum number of handles is exceeded.HostError::IntegerOverflowonu64overflow.
Sourcepub fn blob_write(&mut self, fd: u64, src_data_ptr: u64) -> VMLogicResult<u64>
pub fn blob_write(&mut self, fd: u64, src_data_ptr: u64) -> VMLogicResult<u64>
Writes a chunk of data to a blob.
§Arguments
fd- The file descriptor obtained fromblob_create()operation.src_data_ptr- A pointer to a source-buffersys::Bufferin guest memory containing the data chunk to write.
§Returns
The number of bytes written as u64, which is equal to the length of the input data buffer.
§Errors
HostError::BlobsNotSupportedif the node client is not configured.HostError::InvalidBlobHandleif thefdis invalid or not a write handle.HostError::BlobWriteTooLargeif the data chunk exceedsmax_blob_chunk_size.
Sourcepub fn blob_close(
&mut self,
fd: u64,
dest_blob_id_ptr: u64,
) -> VMLogicResult<u32>
pub fn blob_close( &mut self, fd: u64, dest_blob_id_ptr: u64, ) -> VMLogicResult<u32>
Closes a blob handle and gets the resulting blob ID.
For a write handle, this finalizes the upload and writes the resulting BlobId
into the guest’s memory buffer. For a read handle, it simply closes it.
§Arguments
fd- The file descriptor to close.dest_blob_id_ptr- A pointer to a 32-byte destination buffersys::BufferMutin guest memory where the finalBlobIdwill be written (for write handles).
§Returns
Returns 1 on success.
§Errors
HostError::InvalidMemoryAccessif theblob_id_ptrbuffer is not 32 bytes or if memory access fails for a descriptor buffer.HostError::InvalidBlobHandleif thefdis invalid.HostError::BlobsNotSupportedif the node client is not supported or upload operation fails.
Sourcepub fn blob_announce_to_context(
&mut self,
src_blob_id_ptr: u64,
src_context_id_ptr: u64,
) -> VMLogicResult<u32>
pub fn blob_announce_to_context( &mut self, src_blob_id_ptr: u64, src_context_id_ptr: u64, ) -> VMLogicResult<u32>
Announces a blob to a specific context for network discovery.
§Arguments
src_blob_id_ptr- pointer to a 32-byte source-buffersys::Bufferin guest memory, containing the 32-byteBlobId.src_context_id_ptr- pointer to a 32-byte source-buffersys::Bufferin guest memory, containing the 32-byteContextId.
§Returns
Returns 1 on successful announcement.
§Errors
HostError::BlobsNotSupportedif blob functionality is disabled or a network error occurs.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn blob_open(&mut self, src_blob_id_ptr: u64) -> VMLogicResult<u64>
pub fn blob_open(&mut self, src_blob_id_ptr: u64) -> VMLogicResult<u64>
Opens an existing blob for reading.
§Arguments
src_blob_id_ptr- pointer to a 32-byte source-buffersys::Bufferin guest memory, containing the 32-byteBlobId.
§Returns
A u64 file descriptor for the new blob read handle.
§Errors
HostError::BlobsNotSupportedif the node client is not configured.HostError::TooManyBlobHandlesif the maximum number of handles is exceeded.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Sourcepub fn blob_read(&mut self, fd: u64, dest_data_ptr: u64) -> VMLogicResult<u64>
pub fn blob_read(&mut self, fd: u64, dest_data_ptr: u64) -> VMLogicResult<u64>
Reads a chunk of data from an open blob.
Data is read from the blob and copied into the provided guest memory buffer.
§Arguments
fd- The file descriptor obtained fromblob_open.dest_data_ptr- A pointer to a destination buffersys::BufferMutin guest memory where the read data will be stored
§Returns
The number of bytes actually read as u64. This can be less than the buffer size if the
end of the blob is reached.
§Errors
HostError::BlobsNotSupportedif blob functionality is unavailable.HostError::InvalidBlobHandleif thefdis invalid or not a read handle.HostError::BlobBufferTooLargeif the guest buffer exceedsmax_blob_chunk_size.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Source§impl VMHostFunctions<'_>
impl VMHostFunctions<'_>
Sourcepub fn send_proposal(
&mut self,
src_actions_ptr: u64,
dest_id_ptr: u64,
) -> VMLogicResult<()>
pub fn send_proposal( &mut self, src_actions_ptr: u64, dest_id_ptr: u64, ) -> VMLogicResult<()>
Creates a new governance proposal.
Call the contract’s send_proposal() function through the bridge.
The proposal actions are obtained as raw data and pushed onto a list of proposals to be sent to the host.
Note that multiple actions are received, and the entire batch is pushed onto the proposal list to represent one proposal.
A unique ID for the proposal is generated by the host and written back into
guest memory. The proposal itself is stored in the VMLogic to be included
in the Outcome.
§Arguments
src_actions_ptr- pointer to a source-buffersys::Bufferin guest memory, containing the proposal’s actions.dest_id_ptr- A pointer to a 32-byte destination buffersys::BufferMutin guest memory where the generated proposal ID will be written.
§Errors
HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn approve_proposal(&mut self, src_approval_ptr: u64) -> VMLogicResult<()>
pub fn approve_proposal(&mut self, src_approval_ptr: u64) -> VMLogicResult<()>
Approves a governance proposal.
Adds the given proposal ID to the list of approvals in the VMLogic.
§Arguments
src_approval_ptr- Pointer to a 32-byte source-buffersys::Bufferin guest memory containing the ID of the proposal to approve.
§Errors
HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Source§impl VMHostFunctions<'_>
impl VMHostFunctions<'_>
Sourcepub fn storage_read(
&mut self,
src_key_ptr: u64,
dest_register_id: u64,
) -> VMLogicResult<u32>
pub fn storage_read( &mut self, src_key_ptr: u64, dest_register_id: u64, ) -> VMLogicResult<u32>
Reads a value from the persistent storage.
If the key exists, the corresponding value is copied into the specified register.
§Arguments
src_key_ptr- A pointer to the key source-buffer in guest memory.dest_register_id- The ID of the destination register in host memory where to place the value (if found).
§Returns
- Returns
1if the key was found and the value was recorded into the register. - Returns
0if the key was not found.
§Errors
HostError::KeyLengthOverflowif the key size exceeds the configured limit.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Sourcepub fn storage_remove(
&mut self,
src_key_ptr: u64,
dest_register_id: u64,
) -> VMLogicResult<u32>
pub fn storage_remove( &mut self, src_key_ptr: u64, dest_register_id: u64, ) -> VMLogicResult<u32>
Removes a key-value pair from persistent storage.
If the key exists, the value is copied into the specified host register before removal.
§Arguments
src_key_ptr- A pointer to the key source-buffer in guest memory.dest_register_id- The ID of the destination register in host memory where to place the value (if found).
§Returns
- Returns
1if the key was found and removed. - Returns
0if the key was not found.
§Errors
HostError::KeyLengthOverflowif the key size exceeds the configured limit.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Sourcepub fn storage_write(
&mut self,
src_key_ptr: u64,
src_value_ptr: u64,
dest_register_id: u64,
) -> VMLogicResult<u32>
pub fn storage_write( &mut self, src_key_ptr: u64, src_value_ptr: u64, dest_register_id: u64, ) -> VMLogicResult<u32>
Writes a key-value pair to persistent storage.
If the key already exists, its value is overwritten. The old value is placed into the specified host register.
§Arguments
src_key_ptr- A pointer to the key source-buffer in guest memory.src_value_ptr- A pointer to the value source-buffer in guest memory.dest_register_id- The ID of the destination register in host memory where to place the old value (if found).
§Returns
- Returns
1if a value was evicted (i.e., the key already existed). - Returns
0if a new key was inserted.
§Errors
HostError::KeyLengthOverflowif the key size exceeds the limit.HostError::ValueLengthOverflowif the value size exceeds the limit.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Source§impl VMHostFunctions<'_>
impl VMHostFunctions<'_>
Sourcepub fn panic(&mut self, src_location_ptr: u64) -> VMLogicResult<()>
pub fn panic(&mut self, src_location_ptr: u64) -> VMLogicResult<()>
Host function to handle a simple panic from the guest.
This function is called when the guest code panics without a message. It captures the source location (file, line, column) of the panic and terminates the execution.
§Arguments
src_location_ptr- A pointer in guest memory to asys::Locationstruct, containing file, line, and column information about the panic’s origin.
§Returns/Errors
HostError::Panicif the panic action was successfully executed.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Sourcepub fn panic_utf8(
&mut self,
src_panic_msg_ptr: u64,
src_location_ptr: u64,
) -> VMLogicResult<()>
pub fn panic_utf8( &mut self, src_panic_msg_ptr: u64, src_location_ptr: u64, ) -> VMLogicResult<()>
Host function to handle a panic with a UTF-8 message from the guest.
This function is called when guest code panics with a message. It captures the message and source location, then terminates the execution.
§Arguments
src_panic_msg_ptr- A pointer in guest memory to a source-buffersys::Buffercontaining the UTF-8 panic message.src_location_ptr- A pointer in guest memory to asys::Locationstruct for the panic’s origin.
§Returns/Errors
HostError::Panicif the panic action was successfully executed.HostError::BadUTF8if reading UTF8 string from guest memory fails.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn register_len(&self, register_id: u64) -> VMLogicResult<u64>
pub fn register_len(&self, register_id: u64) -> VMLogicResult<u64>
Sourcepub fn read_register(
&self,
register_id: u64,
dest_data_ptr: u64,
) -> VMLogicResult<u32>
pub fn read_register( &self, register_id: u64, dest_data_ptr: u64, ) -> VMLogicResult<u32>
Reads the data from a register into a guest memory buffer.
§Arguments
register_id- The ID of the register to read from.dest_data_ptr- A pointer in guest memory to a destination buffersys::BufferMutwhere the data should be copied.
§Returns
- Returns
1if the data was successfully read and copied. - Returns
0if the provided guest buffer has a different length than the register’s data.
§Errors
HostError::InvalidRegisterIdif the register does not exist.HostError::InvalidMemoryAccessif memory access fails for a descriptor buffer.
Sourcepub fn context_id(&mut self, dest_register_id: u64) -> VMLogicResult<()>
pub fn context_id(&mut self, dest_register_id: u64) -> VMLogicResult<()>
Sourcepub fn executor_id(&mut self, dest_register_id: u64) -> VMLogicResult<()>
pub fn executor_id(&mut self, dest_register_id: u64) -> VMLogicResult<()>
Sourcepub fn input(&mut self, dest_register_id: u64) -> VMLogicResult<()>
pub fn input(&mut self, dest_register_id: u64) -> VMLogicResult<()>
Sourcepub fn value_return(&mut self, src_value_ptr: u64) -> VMLogicResult<()>
pub fn value_return(&mut self, src_value_ptr: u64) -> VMLogicResult<()>
Sets the final return value of the execution.
This function can be called by the guest to specify a successful result (Ok)
or a custom execution error (Err). This value will be part of the final Outcome.
§Arguments
src_value_ptr- A pointer in guest memory to a source-sys::ValueReturn, which is an enum indicating success or error, along with the data buffer.
§Errors
HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn log_utf8(&mut self, src_log_ptr: u64) -> VMLogicResult<()>
pub fn log_utf8(&mut self, src_log_ptr: u64) -> VMLogicResult<()>
Adds a new log message (UTF-8 encoded string) to the execution log. The message is being obtained from the guest memory.
§Arguments
src_log_ptr- A pointer in guest memory to a source-sys::Buffercontaining the log message.
§Errors
HostError::LogsOverflowif the maximum number of logs has been reached.HostError::BadUTF8if the message is not a valid UTF-8 string.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn emit(&mut self, src_event_ptr: u64) -> VMLogicResult<()>
pub fn emit(&mut self, src_event_ptr: u64) -> VMLogicResult<()>
Emits a structured event that is added to the events log.
Events are recorded and included in the final execution Outcome.
§Arguments
src_event_ptr- A pointer in guest memory to asys::Eventstruct, which contains source-buffers for the eventkindanddata.
§Errors
HostError::EventKindSizeOverflowif the event kind is too long.HostError::EventDataSizeOverflowif the event data is too large.HostError::EventsOverflowif the maximum number of events has been reached.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn emit_with_handler(
&mut self,
src_event_ptr: u64,
src_handler_ptr: u64,
) -> VMLogicResult<()>
pub fn emit_with_handler( &mut self, src_event_ptr: u64, src_handler_ptr: u64, ) -> VMLogicResult<()>
Emits an event with an optional handler name.
This function is similar to emit but includes handler information.
The handler name is read from the provided memory pointer.
§Arguments
src_event_ptr- Pointer to the event data in guest memory.src_handler_ptr- Pointer to the handler name in guest memory (can be 0 for no handler).
§Returns
Ok(())if the event was successfully emitted.
§Errors
HostError::EventKindSizeOverflowif the event kind is too long.HostError::EventDataSizeOverflowif the event data is too large.HostError::EventsOverflowif the maximum number of events has been reached.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn commit(
&mut self,
src_root_hash_ptr: u64,
src_artifact_ptr: u64,
) -> VMLogicResult<()>
pub fn commit( &mut self, src_root_hash_ptr: u64, src_artifact_ptr: u64, ) -> VMLogicResult<()>
Commits the execution state, providing a state root and an artifact.
This function can only be called once per execution.
§Arguments
src_root_hash_ptr- A pointer to a source-buffer in guest memory containing the 32-byte state root hash.src_artifact_ptr- A pointer to a source-buffer in guest memory containing a binary artifact.
§Errors
HostError::InvalidMemoryAccessif this function is called more than once or if memory access fails for descriptor buffers.
Source§impl VMHostFunctions<'_>
impl VMHostFunctions<'_>
Sourcepub fn fetch(
&mut self,
src_url_ptr: u64,
src_method_ptr: u64,
src_headers_ptr: u64,
src_body_ptr: u64,
dest_register_id: u64,
) -> VMLogicResult<u32>
pub fn fetch( &mut self, src_url_ptr: u64, src_method_ptr: u64, src_headers_ptr: u64, src_body_ptr: u64, dest_register_id: u64, ) -> VMLogicResult<u32>
Fetches data from a URL.
Performs an HTTP request. This is a synchronous, blocking operation. The response body is placed into the specified host register.
§Arguments
src_url_ptr- Pointer to the URL string source-buffer in guest memory.src_method_ptr- Pointer to the HTTP method string source-buffer (e.g., “GET”, “POST”) in guest memory.src_headers_ptr- Pointer to a borsh-serializedVec<(String, String)>source-buffer of headers in guest memory.src_body_ptr- Pointer to the request body source-buffer in guest memory.dest_register_id- The ID of the destination register in host memory where to store the response body.
§Returns
- Returns
0on success (HTTP 2xx) - Returns
1on failure. The response body or error message is placed in the host register.
§Errors
HostError::DeserializationErrorif the headers cannot be deserialized.HostError::InvalidMemoryAccessif memory access fails for descriptor buffers.
Sourcepub fn random_bytes(&mut self, dest_ptr: u64) -> VMLogicResult<()>
pub fn random_bytes(&mut self, dest_ptr: u64) -> VMLogicResult<()>
Sourcepub fn time_now(&mut self, dest_ptr: u64) -> VMLogicResult<()>
pub fn time_now(&mut self, dest_ptr: u64) -> VMLogicResult<()>
Gets the current Unix timestamp in nanoseconds.
This function obtains the current time as a nanosecond timestamp, as
SystemTime is not available inside the guest runtime. Therefore the
guest needs to request this from the host.
The result is written into a guest buffer as a u64.
§Arguments
dest_ptr- A pointer to an 8-byte destination buffersys::BufferMutin guest memory where theu64timestamp will be written.
§Errors
HostError::InvalidMemoryAccessif the provided buffer is not exactly 8 bytes long or if memory access fails for a descriptor buffer.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for VMHostFunctions<'a>
impl<'a> !RefUnwindSafe for VMHostFunctions<'a>
impl<'a> !Send for VMHostFunctions<'a>
impl<'a> !Sync for VMHostFunctions<'a>
impl<'a> Unpin for VMHostFunctions<'a>
impl<'a> !UnwindSafe for VMHostFunctions<'a>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> Constraint for T
impl<T> Constraint for T
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more