miden_tx/executor/data_store.rs
1use alloc::collections::BTreeSet;
2
3use miden_objects::account::{AccountId, PartialAccount, StorageMapWitness};
4use miden_objects::asset::{AssetVaultKey, AssetWitness};
5use miden_objects::block::{BlockHeader, BlockNumber};
6use miden_objects::note::NoteScript;
7use miden_objects::transaction::{AccountInputs, PartialBlockchain};
8use miden_processor::{FutureMaybeSend, MastForestStore, Word};
9
10use crate::DataStoreError;
11
12// DATA STORE TRAIT
13// ================================================================================================
14
15/// The [DataStore] trait defines the interface that transaction objects use to fetch data
16/// required for transaction execution.
17pub trait DataStore: MastForestStore {
18 /// Returns all the data required to execute a transaction against the account with the
19 /// specified ID and consuming input notes created in blocks in the input `ref_blocks` set.
20 ///
21 /// The highest block number in `ref_blocks` will be the transaction reference block. In
22 /// general, it is recommended that the reference corresponds to the latest block available
23 /// in the data store.
24 ///
25 /// # Errors
26 /// Returns an error if:
27 /// - The account with the specified ID could not be found in the data store.
28 /// - The block with the specified number could not be found in the data store.
29 /// - The combination of specified inputs resulted in a transaction input error.
30 /// - The data store encountered some internal error
31 fn get_transaction_inputs(
32 &self,
33 account_id: AccountId,
34 ref_blocks: BTreeSet<BlockNumber>,
35 ) -> impl FutureMaybeSend<Result<(PartialAccount, BlockHeader, PartialBlockchain), DataStoreError>>;
36
37 /// Returns a partial foreign account state together with a witness, proving its validity in the
38 /// specified transaction reference block.
39 fn get_foreign_account_inputs(
40 &self,
41 foreign_account_id: AccountId,
42 ref_block: BlockNumber,
43 ) -> impl FutureMaybeSend<Result<AccountInputs, DataStoreError>>;
44
45 /// Returns a witness for an asset in the requested account's vault with the requested vault
46 /// root.
47 ///
48 /// This is the witness that needs to be added to the advice provider's merkle store and advice
49 /// map to make access to the specified asset possible.
50 fn get_vault_asset_witness(
51 &self,
52 account_id: AccountId,
53 vault_root: Word,
54 vault_key: AssetVaultKey,
55 ) -> impl FutureMaybeSend<Result<AssetWitness, DataStoreError>>;
56
57 /// Returns a witness for a storage map item identified by `map_key` in the requested account's
58 /// storage with the requested storage `map_root`.
59 ///
60 /// Note that the `map_key` needs to be hashed in order to get the actual key into the storage
61 /// map.
62 ///
63 /// This is the witness that needs to be added to the advice provider's merkle store and advice
64 /// map to make access to the specified storage map item possible.
65 fn get_storage_map_witness(
66 &self,
67 account_id: AccountId,
68 map_root: Word,
69 map_key: Word,
70 ) -> impl FutureMaybeSend<Result<StorageMapWitness, DataStoreError>>;
71
72 /// Returns a note script with the specified root.
73 ///
74 /// This method will try to find a note script with the specified root in the data store,
75 /// and if not found, return an error.
76 ///
77 /// # Errors
78 /// Returns an error if:
79 /// - The note script with the specified root could not be found in the data store.
80 /// - The data store encountered some internal error.
81 fn get_note_script(
82 &self,
83 script_root: Word,
84 ) -> impl FutureMaybeSend<Result<NoteScript, DataStoreError>>;
85}