1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0

//! Types related to the Transaction Snark Work
#![allow(missing_docs)]

use crate::types::*;
use mina_crypto::hash::*;
use mina_serialization_types::json::*;
use mina_serialization_types_macros::AutoFrom;
use proof_systems::mina_signer::CompressedPubKey;
use versioned::*;

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::TransactionSnarkWork)]
pub struct TransactionSnarkWork {
    pub fee: Amount,
    pub proofs: OneORTwo,
    pub prover: CompressedPubKey,
}

impl_from_with_proxy!(
    TransactionSnarkWork,
    mina_serialization_types::snark_work::TransactionSnarkWork,
    TransactionSnarkWorkJson
);

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::OneORTwo)]
pub enum OneORTwo {
    // Versioned 1 byte
    One(Box<TransactionSnark>),
    Two(Box<TransactionSnark>, Box<TransactionSnark>),
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::TransactionSnark)]
pub struct TransactionSnark {
    pub statement: Statement,
    pub transaction_snark_proof: ProtocolStateProof,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::Statement)]
pub struct Statement {
    pub source: StateHash,
    pub target: StateHash,
    pub supply_increase: Amount,
    pub pending_coinbase_stack_state: PendingCoinbaseStackState,
    pub fee_excess: FeeExcessPair,
    pub next_available_token_before: TokenId,
    pub next_available_token_after: TokenId,
    pub sok_digest: ByteVec,
}

impl_from_with_proxy!(
    Statement,
    mina_serialization_types::snark_work::Statement,
    StatementJson
);

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::PendingCoinbaseStackState)]
pub struct PendingCoinbaseStackState {
    pub source: PendingCoinbase,
    pub target: PendingCoinbase,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::PendingCoinbase)]
pub struct PendingCoinbase {
    pub data_stack: StateHash,
    pub state_stack: StateStack,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::StateStack)]
pub struct StateStack {
    pub init: StateHash,
    pub curr: StateHash,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::FeeExcessPair)]
pub struct FeeExcessPair(pub FeeExcess, pub FeeExcess);

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::FeeExcess)]
pub struct FeeExcess {
    pub token: TokenId,
    pub amount: Signed,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::Signed)]
pub struct Signed {
    pub magnitude: Amount,
    pub sgn: SgnType,
}

#[derive(Clone, Debug, Eq, PartialEq, AutoFrom)]
#[auto_from(mina_serialization_types::snark_work::SgnType)]
pub enum SgnType {
    Pos,
    Neg,
}