pub struct Session { /* private fields */ }Expand description
A running mutation to a state.
Sessions are spawned using a VM instance, and can be used to call
contracts with to modify their state. A sequence of these calls may then be
commited to, or discarded by simply allowing the session to drop.
New contracts are to be deployed in the context of a session.
Implementations§
source§impl Session
impl Session
sourcepub fn deploy<'a, A, D, const N: usize>(
&mut self,
bytecode: &[u8],
deploy_data: D,
points_limit: u64
) -> Result<ContractId, Error>where
A: 'a + for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>,
D: Into<ContractData<'a, A, N>>,
pub fn deploy<'a, A, D, const N: usize>( &mut self, bytecode: &[u8], deploy_data: D, points_limit: u64 ) -> Result<ContractId, Error>where A: 'a + for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>, D: Into<ContractData<'a, A, N>>,
Deploy a contract, returning its ContractId. The ID is computed
using a blake3 hash of the bytecode.
Since a deployment may execute some contract initialization code, that
code will be metered and executed with the given points_limit.
Errors
It is possible that a collision between contract IDs occurs, even for
different contract IDs. This is due to the fact that all contracts have
to fit into a sparse merkle tree with 2^32 positions, and as such
a 256-bit number has to be mapped into a 32-bit number.
If such a collision occurs, PersistenceError will be returned.
sourcepub fn call<A, R>(
&mut self,
contract: ContractId,
fn_name: &str,
fn_arg: &A,
points_limit: u64
) -> Result<CallReceipt<R>, Error>where
A: for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>,
R: Archive,
R::Archived: Deserialize<R, Infallible> + for<'b> CheckBytes<DefaultValidator<'b>>,
pub fn call<A, R>( &mut self, contract: ContractId, fn_name: &str, fn_arg: &A, points_limit: u64 ) -> Result<CallReceipt<R>, Error>where A: for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>, R: Archive, R::Archived: Deserialize<R, Infallible> + for<'b> CheckBytes<DefaultValidator<'b>>,
Execute a call on the current state of this session.
Calls are atomic, meaning that on failure their execution doesn’t modify
the state. They are also metered, and will execute with the given
points_limit.
Errors
The call may error during execution for a wide array of reasons, the most common ones being running against the point limit and a contract panic. Calling the ‘init’ method is not allowed except for when called from the deploy method.
sourcepub fn call_raw<V: Into<Vec<u8>>>(
&mut self,
contract: ContractId,
fn_name: &str,
fn_arg: V,
points_limit: u64
) -> Result<CallReceipt<Vec<u8>>, Error>
pub fn call_raw<V: Into<Vec<u8>>>( &mut self, contract: ContractId, fn_name: &str, fn_arg: V, points_limit: u64 ) -> Result<CallReceipt<Vec<u8>>, Error>
Execute a raw call on the current state of this session.
Raw calls do not specify the type of the argument or of the return. The
caller is responsible for serializing the argument as the target
contract expects.
For more information about calls see call.
sourcepub fn feeder_call<A, R>(
&mut self,
contract: ContractId,
fn_name: &str,
fn_arg: &A,
feeder: Sender<Vec<u8>>
) -> Result<CallReceipt<R>, Error>where
A: for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>,
R: Archive,
R::Archived: Deserialize<R, Infallible> + for<'b> CheckBytes<DefaultValidator<'b>>,
pub fn feeder_call<A, R>( &mut self, contract: ContractId, fn_name: &str, fn_arg: &A, feeder: Sender<Vec<u8>> ) -> Result<CallReceipt<R>, Error>where A: for<'b> Serialize<CompositeSerializer<BufferSerializer<&'b mut [u8]>, BufferScratch<&'b mut [u8; 64]>>>, R: Archive, R::Archived: Deserialize<R, Infallible> + for<'b> CheckBytes<DefaultValidator<'b>>,
Execute a feeder call on the current state of this session.
Feeder calls are used to have the contract be able to report larger amounts of data to the host via the channel included in this call.
These calls are always performed with the maximum amount of points, since the contracts may spend quite a large amount in an effort to report data.
sourcepub fn feeder_call_raw<V: Into<Vec<u8>>>(
&mut self,
contract: ContractId,
fn_name: &str,
fn_arg: V,
feeder: Sender<Vec<u8>>
) -> Result<CallReceipt<Vec<u8>>, Error>
pub fn feeder_call_raw<V: Into<Vec<u8>>>( &mut self, contract: ContractId, fn_name: &str, fn_arg: V, feeder: Sender<Vec<u8>> ) -> Result<CallReceipt<Vec<u8>>, Error>
Execute a raw feeder call on the current state of this session.
See feeder_call and call_raw for more information of this type
of call.
pub fn initialize( &mut self, contract: ContractId, arg: Vec<u8>, points_limit: u64 ) -> Result<(), Error>
sourcepub fn root(&self) -> [u8; 32]
pub fn root(&self) -> [u8; 32]
Return the state root of the current state of the session.
The state root is the root of a merkle tree whose leaves are the hashes of the state of of each contract, ordered by their contract ID.
It also doubles as the ID of a commit - the commit root.
sourcepub fn commit(self) -> Result<[u8; 32], Error>
pub fn commit(self) -> Result<[u8; 32], Error>
Commits the given session to disk, consuming the session and returning its state root.
pub fn with_debug<C, R>(&self, c: C) -> Rwhere C: FnOnce(&[String]) -> R,
pub fn serialize_data<V>(value: &V) -> Result<Vec<u8>, Error>where V: for<'a> Serialize<CompositeSerializer<BufferSerializer<&'a mut [u8]>, BufferScratch<&'a mut [u8; 64]>>>,
pub fn contract_metadata( &self, contract_id: &ContractId ) -> Option<&ContractMetadata>
Trait Implementations§
source§impl Drop for Session
impl Drop for Session
A session is created by leaking an using Box::leak on a SessionInner.
Therefore, the memory needs to be recovered.