Skip to main content

moonproof_contracts/
tx_model.rs

1//! Data shapes flowing between the unproven-tx builders
2//! (`create_unproven_deploy_tx`, `create_unproven_call_tx`), the
3//! submit-tx pipeline (`submit_tx`), and the high-level
4//! `deploy_contract` / `find_deployed_contract` / `call` entry points.
5//!
6//! Private state and circuit return values are typed as
7//! [`RuntimeValue`] uniformly — the IR descriptors carry shape
8//! information; values are dynamically typed at this layer.
9
10use moonproof_ledger::coin_structure::coin::Info as ShieldedCoinInfo;
11use moonproof_ledger::coin_structure::contract::ContractAddress;
12use moonproof_ledger::onchain_runtime::state::ContractState;
13use moonproof_ledger::signatures::SigningKey;
14use moonproof_ledger::storage::db::InMemoryDB;
15use moonproof_runtime_ir::RuntimeValue;
16
17use crate::tx_phase::UnprovenTx;
18use crate::types::{CallResult, FinalizedTxData};
19use crate::utils::zswap_utils::CompactZswapLocalState;
20
21/// Data relevant to any unsubmitted transaction: the typed unproven
22/// ledger transaction + the list of new coins it creates so the
23/// wallet can start watching for them.
24#[derive(Debug, Clone)]
25pub struct UnsubmittedTxData {
26    /// The pre-prove transaction. Goes straight into the proof
27    /// provider's `prove_tx` — no serialize/deserialize hop needed.
28    pub unproven_tx: UnprovenTx,
29    /// Shielded coins that the transaction produces. The wallet
30    /// should track these so they become spendable after the tx lands.
31    pub new_coins: Vec<ShieldedCoinInfo>,
32}
33
34// =====================================================================
35// Deploy tx
36// =====================================================================
37
38/// Public portion of a deploy tx (shared between unsubmitted +
39/// finalized shapes).
40#[derive(Debug, Clone)]
41pub struct UnsubmittedDeployTxPublicData {
42    /// The deterministic address the deploy will produce on-chain.
43    pub contract_address: ContractAddress,
44    /// The initial contract state the deploy installs.
45    pub initial_contract_state: ContractState<InMemoryDB>,
46}
47
48/// Private portion of a deploy tx — signing key, initial private
49/// state, the unproven tx (until it's submitted), shielded new coins,
50/// and the constructor's initial zswap local state.
51#[derive(Debug, Clone)]
52pub struct UnsubmittedDeployTxPrivateData {
53    /// The signing key the deploy added as the contract's
54    /// maintenance authority. The deployer keeps this locally.
55    pub signing_key: SigningKey,
56    /// The initial private state the constructor was run against.
57    /// Persisted locally if the tx succeeds.
58    pub initial_private_state: RuntimeValue,
59    /// The constructor's initial zswap local state.
60    pub initial_zswap_local_state: CompactZswapLocalState,
61    /// The pre-prove deploy tx. `None` on the find path: a contract
62    /// connected via [`crate::find_deployed_contract`] doesn't carry
63    /// a fresh unproven deploy — the deploy already happened.
64    pub unproven_tx: Option<UnprovenTx>,
65    /// Shielded coins the constructor produced.
66    pub new_coins: Vec<ShieldedCoinInfo>,
67}
68
69/// Unsubmitted deploy tx data — output of [`crate::create_unproven_deploy_tx`].
70#[derive(Debug, Clone)]
71pub struct UnsubmittedDeployTxData {
72    pub public: UnsubmittedDeployTxPublicData,
73    pub private: UnsubmittedDeployTxPrivateData,
74}
75
76/// Public data on a finalized deploy — combines the finalized-tx
77/// observation with the deploy's own public fields
78/// (`contract_address`, `initial_contract_state`).
79#[derive(Debug, Clone)]
80pub struct FinalizedDeployTxPublicData {
81    pub finalized: FinalizedTxData,
82    pub contract_address: ContractAddress,
83    pub initial_contract_state: ContractState<InMemoryDB>,
84}
85
86/// Finalized deploy tx data — adds the finalized-tx observation to
87/// [`UnsubmittedDeployTxData`].
88#[derive(Debug, Clone)]
89pub struct FinalizedDeployTxData {
90    pub public: FinalizedDeployTxPublicData,
91    pub private: UnsubmittedDeployTxPrivateData,
92}
93
94// =====================================================================
95// Call tx
96// =====================================================================
97
98/// Unsubmitted call tx data — the output of `create_unproven_call_tx`.
99#[derive(Debug, Clone)]
100pub struct UnsubmittedCallTxData {
101    /// Public + private halves of the circuit execution.
102    pub result: CallResult,
103    /// Plus the ledger tx + new coins.
104    pub tx: UnsubmittedTxData,
105}
106
107/// Finalized call tx data — adds the finalized-tx observation to the
108/// unsubmitted form.
109#[derive(Debug, Clone)]
110pub struct FinalizedCallTxData {
111    pub result: CallResult,
112    pub tx: UnsubmittedTxData,
113    pub finalized: FinalizedTxData,
114}
115
116/// Async (fire-and-forget) call-tx submission result.
117#[derive(Debug, Clone)]
118pub struct SubmittedCallTx {
119    /// The transaction id the node assigned, returned immediately
120    /// after submission.
121    pub tx_id: crate::types::TransactionId,
122    /// The full unsubmitted call-tx data — private state etc.,
123    /// preserved for the caller so they can advance their local state
124    /// before the tx lands.
125    pub call_tx_data: UnsubmittedCallTxData,
126}