radix_engine_interface/blueprints/transaction_processor/
invocations.rs

1use crate::internal_prelude::*;
2use radix_common::data::scrypto::{scrypto_decode, ScryptoDecode};
3use sbor::rust::prelude::*;
4
5pub const TRANSACTION_PROCESSOR_BLUEPRINT: &str = "TransactionProcessor";
6
7pub const TRANSACTION_PROCESSOR_RUN_IDENT: &str = "run";
8
9#[derive(Debug, Eq, PartialEq, ScryptoSbor)]
10pub struct TransactionProcessorRunInput {
11    pub manifest_encoded_instructions: Vec<u8>,
12    pub global_address_reservations: Vec<GlobalAddressReservation>,
13    pub references: Vec<Reference>, // Required so that the kernel passes the references to the processor frame
14    pub blobs: IndexMap<Hash, Vec<u8>>,
15}
16
17#[derive(Debug, Eq, PartialEq, ManifestSbor)]
18pub struct TransactionProcessorRunManifestInput {
19    pub manifest_encoded_instructions: Vec<u8>,
20    pub global_address_reservations: Vec<ManifestAddressReservation>,
21    pub references: Vec<GlobalAddress>, // Required so that the kernel passes the references to the processor frame
22    pub blobs: IndexMap<Hash, Vec<u8>>,
23}
24
25// This needs to match the above, but is easily encodable to avoid cloning from the transaction payload to encode
26#[derive(Debug, Eq, PartialEq, ScryptoEncode)]
27pub struct TransactionProcessorRunInputEfficientEncodable<'a> {
28    pub manifest_encoded_instructions: &'a [u8],
29    pub global_address_reservations: &'a [GlobalAddressReservation],
30    pub references: &'a IndexSet<Reference>,
31    pub blobs: &'a IndexMap<Hash, Vec<u8>>,
32}
33
34pub type TransactionProcessorRunOutput = Vec<InstructionOutput>;
35
36#[derive(Debug, Clone, Sbor, Eq, PartialEq)]
37pub enum InstructionOutput {
38    CallReturn(Vec<u8>),
39    None,
40}
41
42impl InstructionOutput {
43    pub fn expect_return_value<V: ScryptoDecode + Eq + Debug>(&self, expected: &V) {
44        match self {
45            Self::CallReturn(buf) => {
46                let actual: V = scrypto_decode(buf).expect("Value does not decode to type");
47                if !expected.eq(&actual) {
48                    panic!("Expected: {:?} but was: {:?}", expected, actual)
49                }
50            }
51            Self::None => {
52                panic!("Expected: {:?} but was None", expected);
53            }
54        }
55    }
56}