near_vm_logic/
context.rs

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