near_sdk/types/
vm_types.rs

1#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))]
2pub use near_vm_runner::logic::types::{PromiseResult as VmPromiseResult, ReturnData};
3
4//* Types from near_vm_logic
5/// Promise index that is computed only once. It is an internal index that identifies a specific promise (or a sequence of promises) created during the execution of a smart contract.
6/// Returned by [`promise_create`](crate::env::promise_create) and can be used to refer this promise in `promise_then`, `promise_batch_create`, and other functions.
7/// Example:
8/// ```no_run
9/// use near_sdk::{env, Gas, AccountId, NearToken};
10/// use std::str::FromStr;
11///
12/// let promise_id = env::promise_create(
13///     AccountId::from_str("a.near").unwrap(), "new", b"{}", NearToken::from_yoctonear(0),
14///     Gas::from_tgas(1)
15/// );
16/// env::promise_then(
17///     promise_id, AccountId::from_str("b.near").unwrap(), "callback", b"{}", NearToken::from_yoctonear(0),
18///     Gas::from_tgas(1)
19/// );
20/// ```
21#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Hash, Copy, Clone)]
22pub struct PromiseIndex(pub(crate) u64);
23
24/// An index of Receipt to append an action
25#[deprecated(since = "4.1.0", note = "type not used within SDK, use u64 directly or another alias")]
26pub type ReceiptIndex = u64;
27#[deprecated(since = "4.1.0", note = "type not used within SDK, use u64 directly or another alias")]
28pub type IteratorIndex = u64;
29
30/// When there is a callback attached to one or more contract calls the execution results of these
31/// calls are available to the contract invoked through the callback.
32#[derive(Debug, PartialEq, Eq)]
33pub enum PromiseResult {
34    Successful(Vec<u8>),
35    Failed,
36}
37
38#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))]
39impl From<PromiseResult> for VmPromiseResult {
40    fn from(p: PromiseResult) -> Self {
41        match p {
42            PromiseResult::Successful(v) => Self::Successful(v.into_boxed_slice().into()),
43            PromiseResult::Failed => Self::Failed,
44        }
45    }
46}
47
48/// All error variants which can occur with promise results.
49#[non_exhaustive]
50#[derive(Debug, PartialEq, Eq)]
51pub enum PromiseError {
52    /// Promise result failed.
53    Failed,
54}