unc_vm_runner/logic/context.rs
1use super::types::PublicKey;
2use unc_primitives_core::config::ViewConfig;
3use unc_primitives_core::types::{AccountId, Balance, BlockHeight, EpochHeight, Gas, StorageUsage};
4
5#[derive(Clone)]
6/// Context for the contract execution.
7pub struct VMContext {
8 /// The account id of the current contract that we are executing.
9 pub current_account_id: AccountId,
10 /// The account id of that signed the original transaction that led to this
11 /// execution.
12 pub signer_account_id: AccountId,
13 /// The public key that was used to sign the original transaction that led to
14 /// this execution.
15 pub signer_account_pk: PublicKey,
16 /// If this execution is the result of cross-contract call or a callback then
17 /// predecessor is the account that called it.
18 /// If this execution is the result of direct execution of transaction then it
19 /// is equal to `signer_account_id`.
20 pub predecessor_account_id: AccountId,
21 /// The input to the contract call.
22 /// Encoded as base64 string to be able to pass input in borsh binary format.
23 pub input: Vec<u8>,
24 /// The current block height.
25 pub block_height: BlockHeight,
26 /// The current block timestamp (number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC).
27 pub block_timestamp: u64,
28 /// The current epoch height.
29 pub epoch_height: EpochHeight,
30
31 /// The balance attached to the given account. Excludes the `attached_deposit` that was
32 /// attached to the transaction.
33 pub account_balance: Balance,
34 /// The balance of pledging tokens on the given account.
35 pub account_locked_balance: Balance,
36 /// The account's storage usage before the contract execution
37 pub storage_usage: StorageUsage,
38 /// The balance that was attached to the call that will be immediately deposited before the
39 /// contract execution starts.
40 pub attached_deposit: Balance,
41 /// The gas attached to the call that can be used to pay for the gas fees.
42 pub prepaid_gas: Gas,
43 /// Initial seed for randomness
44 pub random_seed: Vec<u8>,
45 /// If Some, it means that execution is made in a view mode and defines its configuration.
46 /// View mode means that only read-only operations are allowed.
47 pub view_config: Option<ViewConfig>,
48 /// How many `DataReceipt`'s should receive this execution result. This should be empty if
49 /// this function call is a part of a batch and it is not the last action.
50 pub output_data_receivers: Vec<AccountId>,
51}
52
53impl VMContext {
54 pub fn is_view(&self) -> bool {
55 self.view_config.is_some()
56 }
57}