Struct workspaces::Worker
source · [−]pub struct Worker<T> { /* private fields */ }Expand description
The Worker type allows us to interact with any NEAR related networks, such
as mainnet and testnet. This controls where the environment the worker is
running on top of is. Refer to this for all network related actions such as
deploying a contract, or interacting with transactions.
Implementations
sourceimpl<T> Worker<T> where
T: NetworkClient,
impl<T> Worker<T> where
T: NetworkClient,
sourcepub async fn call(
&self,
contract: &Contract,
function: &str,
args: Vec<u8>,
gas: Option<Gas>,
deposit: Option<Balance>
) -> Result<CallExecutionDetails>
pub async fn call(
&self,
contract: &Contract,
function: &str,
args: Vec<u8>,
gas: Option<Gas>,
deposit: Option<Balance>
) -> Result<CallExecutionDetails>
Call into a contract’s change function.
sourcepub async fn view(
&self,
contract_id: &AccountId,
function: &str,
args: Vec<u8>
) -> Result<ViewResultDetails>
pub async fn view(
&self,
contract_id: &AccountId,
function: &str,
args: Vec<u8>
) -> Result<ViewResultDetails>
Call into a contract’s view function.
sourcepub async fn view_code(&self, contract_id: &AccountId) -> Result<Vec<u8>>
pub async fn view_code(&self, contract_id: &AccountId) -> Result<Vec<u8>>
View the WASM code bytes of a contract on the network.
sourcepub async fn view_state(
&self,
contract_id: &AccountId,
prefix: Option<&[u8]>
) -> Result<HashMap<Vec<u8>, Vec<u8>>>
pub async fn view_state(
&self,
contract_id: &AccountId,
prefix: Option<&[u8]>
) -> Result<HashMap<Vec<u8>, Vec<u8>>>
View the state of a account/contract on the network. This will return the internal state of the account in the form of a map of key-value pairs; where STATE contains info on a contract’s internal data.
sourcepub async fn view_latest_block(&self) -> Result<Block>
pub async fn view_latest_block(&self) -> Result<Block>
View the latest block from the network
sourcepub async fn transfer_near(
&self,
signer: &InMemorySigner,
receiver_id: &AccountId,
amount_yocto: Balance
) -> Result<CallExecutionDetails>
pub async fn transfer_near(
&self,
signer: &InMemorySigner,
receiver_id: &AccountId,
amount_yocto: Balance
) -> Result<CallExecutionDetails>
Transfer tokens from one account to another. The signer is the account that will be used to to send from.
sourcepub async fn delete_account(
&self,
account_id: &AccountId,
signer: &InMemorySigner,
beneficiary_id: &AccountId
) -> Result<CallExecutionDetails>
pub async fn delete_account(
&self,
account_id: &AccountId,
signer: &InMemorySigner,
beneficiary_id: &AccountId
) -> Result<CallExecutionDetails>
Deletes an account from the network. The beneficiary will receive the balance of the account deleted.
sourcepub async fn view_account(
&self,
account_id: &AccountId
) -> Result<AccountDetails>
pub async fn view_account(
&self,
account_id: &AccountId
) -> Result<AccountDetails>
View account details of a specific account on the network.
sourceimpl Worker<Sandbox>
impl Worker<Sandbox>
pub fn root_account(&self) -> Result<Account>
sourcepub fn import_contract<'a, 'b>(
&'b self,
id: &AccountId,
worker: &'a Worker<impl Network>
) -> ImportContractTransaction<'a, 'b>
pub fn import_contract<'a, 'b>(
&'b self,
id: &AccountId,
worker: &'a Worker<impl Network>
) -> ImportContractTransaction<'a, 'b>
Import a contract from the the given network, and return us a [ImportContractTransaction]
which allows to specify further details, such as being able to import contract data and
how far back in time we wanna grab the contract.
sourcepub async fn patch_state(
&self,
contract_id: &AccountId,
key: &[u8],
value: &[u8]
) -> Result<()>
pub async fn patch_state(
&self,
contract_id: &AccountId,
key: &[u8],
value: &[u8]
) -> Result<()>
Patch state into the sandbox network, given a key and value. This will allow us to set state that we have acquired in some manner. This allows us to test random cases that are hard to come up naturally as state evolves.
sourcepub async fn fast_forward(&self, delta_height: u64) -> Result<()>
pub async fn fast_forward(&self, delta_height: u64) -> Result<()>
Fast forward to a point in the future. The delta block height is supplied to tell the network to advanced a certain amount of blocks. This comes with the advantage only having to wait a fraction of the time it takes to produce the same number of blocks.
Estimate as to how long it takes: if our delta_height crosses X epochs, then it would
roughly take X * 5 seconds for the fast forward request to be processed.
Trait Implementations
sourceimpl<T> NetworkInfo for Worker<T> where
T: NetworkInfo,
impl<T> NetworkInfo for Worker<T> where
T: NetworkInfo,
sourceimpl<T> TopLevelAccountCreator for Worker<T> where
T: TopLevelAccountCreator + Send + Sync,
impl<T> TopLevelAccountCreator for Worker<T> where
T: TopLevelAccountCreator + Send + Sync,
fn create_tla<'life0, 'async_trait>(
&'life0 self,
id: AccountId,
sk: SecretKey
) -> Pin<Box<dyn Future<Output = Result<CallExecution<Account>>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn create_tla_and_deploy<'life0, 'life1, 'async_trait>(
&'life0 self,
id: AccountId,
sk: SecretKey,
wasm: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<CallExecution<Contract>>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
impl<T> AllowDevAccountCreation for Worker<T> where
T: AllowDevAccountCreation,
Auto Trait Implementations
impl<T> RefUnwindSafe for Worker<T> where
T: RefUnwindSafe,
impl<T> Send for Worker<T> where
T: Send + Sync,
impl<T> Sync for Worker<T> where
T: Send + Sync,
impl<T> Unpin for Worker<T>
impl<T> UnwindSafe for Worker<T> where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more