ActorRuntime

Struct ActorRuntime 

Source
pub struct ActorRuntime<S: Syscalls, BS: Blockstore> {
    pub syscalls: S,
    pub blockstore: BS,
}
Expand description

ActorRuntime provides access to system resources via Syscalls and the Blockstore.

It provides higher level utilities than raw syscalls for actors to use to interact with the IPLD layer and the FVM runtime (e.g. messaging other actors).

Fields§

§syscalls: S§blockstore: BS

Implementations§

Source§

impl<S: Syscalls + Clone, BS: Blockstore + Clone> ActorRuntime<S, BS>

Source§

impl<S: Syscalls, BS: Blockstore> ActorRuntime<S, BS>

Source

pub fn new(syscalls: S, blockstore: BS) -> ActorRuntime<S, BS>

Source

pub fn new_test_runtime() -> ActorRuntime<FakeSyscalls, MemoryBlockstore>

Creates a runtime suitable for tests, using mock syscalls and a memory blockstore.

Source

pub fn new_shared_test_runtime() -> ActorRuntime<FakeSyscalls, SharedMemoryBlockstore>

Creates a runtime suitable for more complex tests, using mock syscalls and a memory blockstore.

Clones of this runtime will reference the same blockstore.

Source

pub fn actor_id(&self) -> ActorID

Returns the address of the current actor as an ActorID.

Source

pub fn caller(&self) -> ActorID

Source

pub fn send( &self, to: &Address, method: MethodNum, params: Option<IpldBlock>, value: TokenAmount, ) -> MessagingResult<Response>

Sends a message to an actor.

Source

pub fn resolve_id(&self, address: &Address) -> MessagingResult<ActorID>

Attempts to resolve the given address to its ID address form.

Returns MessagingError::AddressNotResolved if the address could not be resolved.

Source

pub fn resolve_or_init(&self, address: &Address) -> MessagingResult<ActorID>

Resolves an address to an ID address, sending a message to initialize an account there if it doesn’t exist.

If the account cannot be created, this function returns MessagingError::AddressNotInitialized.

Source

pub fn initialize_account(&self, address: &Address) -> MessagingResult<ActorID>

Source

pub fn root_cid(&self) -> Result<Cid, ActorError>

Get the root cid of the actor’s state.

Source

pub fn set_root(&self, cid: &Cid) -> Result<(), ActorError>

Set the root cid of the actor’s state.

Source

pub fn same_address(&self, address_a: &Address, address_b: &Address) -> bool

Attempts to compare two addresses, seeing if they would resolve to the same Actor without actually instantiating accounts for them.

If a and b are of the same type, simply do an equality check. Otherwise, attempt to resolve to an ActorID and compare.

Source

pub fn bs(&self) -> &BS

Trait Implementations§

Source§

impl<S: Syscalls, BS: Blockstore> Blockstore for ActorRuntime<S, BS>

Convenience impl encapsulating the blockstore functionality.

Source§

fn get(&self, k: &Cid) -> Result<Option<Vec<u8>>>

Gets the block from the blockstore.
Source§

fn put_keyed(&self, k: &Cid, block: &[u8]) -> Result<()>

Put a block with a pre-computed cid. Read more
Source§

fn has(&self, k: &Cid<64>) -> Result<bool, Error>

Checks if the blockstore has the specified block.
Source§

fn put<D>(&self, mh_code: Code, block: &Block<D>) -> Result<Cid<64>, Error>
where Self: Sized, D: AsRef<[u8]>,

Puts the block into the blockstore, computing the hash with the specified multicodec. Read more
Source§

fn put_many<D, I>(&self, blocks: I) -> Result<(), Error>
where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Code, Block<D>)>,

Bulk put blocks into the blockstore. Read more
Source§

fn put_many_keyed<D, I>(&self, blocks: I) -> Result<(), Error>
where Self: Sized, D: AsRef<[u8]>, I: IntoIterator<Item = (Cid<64>, D)>,

Bulk-put pre-keyed blocks into the blockstore. Read more
Source§

impl<S: Clone + Syscalls, BS: Clone + Blockstore> Clone for ActorRuntime<S, BS>

Source§

fn clone(&self) -> ActorRuntime<S, BS>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + Syscalls, BS: Debug + Blockstore> Debug for ActorRuntime<S, BS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Syscalls, BS: Blockstore> Messaging for ActorRuntime<S, BS>

Source§

fn send( &self, to: &Address, method: MethodNum, params: Option<IpldBlock>, value: TokenAmount, ) -> Result<Response>

Sends a message to an actor.

Auto Trait Implementations§

§

impl<S, BS> Freeze for ActorRuntime<S, BS>
where S: Freeze, BS: Freeze,

§

impl<S, BS> RefUnwindSafe for ActorRuntime<S, BS>

§

impl<S, BS> Send for ActorRuntime<S, BS>
where S: Send, BS: Send,

§

impl<S, BS> Sync for ActorRuntime<S, BS>
where S: Sync, BS: Sync,

§

impl<S, BS> Unpin for ActorRuntime<S, BS>
where S: Unpin, BS: Unpin,

§

impl<S, BS> UnwindSafe for ActorRuntime<S, BS>
where S: UnwindSafe, BS: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CborStore for T
where T: Blockstore,

Source§

fn get_cbor<T>(&self, cid: &Cid<64>) -> Result<Option<T>, Error>

Get typed object from block store by Cid.
Source§

fn put_cbor<S>(&self, obj: &S, code: Code) -> Result<Cid<64>, Error>
where S: Serialize,

Put an object in the block store and return the Cid identifier.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.