Struct workspaces::Worker
source · pub struct Worker<T: ?Sized> { /* 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§
source§impl<T: ?Sized> Worker<T>where
T: NetworkClient,
impl<T: ?Sized> Worker<T>where
T: NetworkClient,
sourcepub fn call(
&self,
signer: &InMemorySigner,
contract_id: &AccountId,
function: &str
) -> CallTransaction<'_>
pub fn call(
&self,
signer: &InMemorySigner,
contract_id: &AccountId,
function: &str
) -> CallTransaction<'_>
Call into a contract’s change function. Returns a CallTransaction
object
that we will make use to populate the rest of the call details. The signer
will be used to sign the transaction.
sourcepub fn view(
&self,
contract_id: &AccountId,
function: &str
) -> Query<'_, ViewFunction>
pub fn view(
&self,
contract_id: &AccountId,
function: &str
) -> Query<'_, ViewFunction>
Call into a contract’s view function. Returns a Query
which allows us
to specify further details like the arguments of the view call, or at what
point in the chain we want to view.
sourcepub fn view_code(&self, contract_id: &AccountId) -> Query<'_, ViewCode>
pub fn view_code(&self, contract_id: &AccountId) -> Query<'_, ViewCode>
View the WASM code bytes of a contract on the network.
sourcepub fn view_state(&self, contract_id: &AccountId) -> Query<'_, ViewState>
pub fn view_state(&self, contract_id: &AccountId) -> Query<'_, ViewState>
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 fn view_block(&self) -> Query<'_, ViewBlock>
pub fn view_block(&self) -> Query<'_, ViewBlock>
View the block from the network. Supply additional parameters such as block_height
or block_hash
to get the block.
sourcepub fn view_chunk(&self) -> QueryChunk<'_>
pub fn view_chunk(&self) -> QueryChunk<'_>
View the chunk from the network once awaited. Supply additional parameters such as
block_hash_and_shard
, block_height_and_shard
or chunk_hash
to get the
chunk at a specific reference point. If none of those are supplied, the default
reference point will be used, which will be the latest block_hash with a shard_id
of 0.
sourcepub fn view_access_key(
&self,
id: &AccountId,
pk: &PublicKey
) -> Query<'_, ViewAccessKey>
pub fn view_access_key(
&self,
id: &AccountId,
pk: &PublicKey
) -> Query<'_, ViewAccessKey>
sourcepub fn view_access_keys(&self, id: &AccountId) -> Query<'_, ViewAccessKeyList>
pub fn view_access_keys(&self, id: &AccountId) -> Query<'_, ViewAccessKeyList>
sourcepub async fn transfer_near(
&self,
signer: &InMemorySigner,
receiver_id: &AccountId,
amount_yocto: Balance
) -> Result<ExecutionFinalResult>
pub async fn transfer_near(
&self,
signer: &InMemorySigner,
receiver_id: &AccountId,
amount_yocto: Balance
) -> Result<ExecutionFinalResult>
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<ExecutionFinalResult>
pub async fn delete_account(
&self,
account_id: &AccountId,
signer: &InMemorySigner,
beneficiary_id: &AccountId
) -> Result<ExecutionFinalResult>
Deletes an account from the network. The beneficiary will receive the balance of the account deleted.
sourcepub fn view_account(&self, account_id: &AccountId) -> Query<'_, ViewAccount>
pub fn view_account(&self, account_id: &AccountId) -> Query<'_, ViewAccount>
View account details of a specific account on the network.
pub fn gas_price(&self) -> Query<'_, GasPrice>
source§impl Worker<Sandbox>
impl Worker<Sandbox>
pub fn root_account(&self) -> Result<Account>
sourcepub fn import_contract<'a>(
&self,
id: &'a AccountId,
worker: &Worker<impl Network + 'static>
) -> ImportContractTransaction<'a>
pub fn import_contract<'a>(
&self,
id: &'a AccountId,
worker: &Worker<impl Network + 'static>
) -> ImportContractTransaction<'a>
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.