plutus_ledger_api/v3/
transaction.rs

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//! Types related to Cardano transactions.

#[cfg(feature = "lbf")]
use lbr_prelude::json::Json;
use num_bigint::BigInt;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

pub use crate::v2::transaction::{
    DCert, POSIXTime, POSIXTimeRange, TransactionHash, TransactionInput, TransactionOutput,
    TxInInfo,
};
use crate::{
    self as plutus_ledger_api,
    plutus_data::{IsPlutusData, PlutusData},
    v2::{
        address::{Credential, StakingCredential},
        assoc_map::AssocMap,
        crypto::{PaymentPubKeyHash, StakePubKeyHash},
        datum::{Datum, DatumHash},
        redeemer::Redeemer,
        script::ScriptHash,
        value::{CurrencySymbol, Lovelace, Value},
    },
};

use super::ratio::Rational;

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Newtype"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct ColdCommitteeCredential(pub Credential);

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Newtype"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct HotCommitteeCredential(pub Credential);

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Newtype"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct DRepCredential(pub Credential);

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum DRep {
    DRep(DRepCredential),
    AlwaysAbstain,
    AlwaysNoConfidence,
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum Delegatee {
    Stake(StakePubKeyHash),
    Vote(DRep),
    StakeVote(StakePubKeyHash, DRep),
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum TxCert {
    /// Register staking credential with an optional deposit amount
    RegStaking(StakingCredential, Option<Lovelace>),
    /// Un-Register staking credential with an optional refund amount
    UnRegStaking(StakingCredential, Option<Lovelace>),
    /// Delegate staking credential to a Delegatee
    DelegStaking(StakingCredential, Delegatee),
    /// Register and delegate staking credential to a Delegatee in one certificate. Note that deposit is mandatory.
    RegDeleg(StakingCredential, Delegatee, Lovelace),
    /// Register a DRep with a deposit value. The optional anchor is omitted.
    RegDRep(DRepCredential, Lovelace),
    /// Update a DRep. The optional anchor is omitted.
    UpdateDRep(DRepCredential),
    /// UnRegister a DRep with mandatory refund value
    UnRegDRep(DRepCredential, Lovelace),
    /// A digest of the PoolParams
    PoolRegister(
        /// pool id
        PaymentPubKeyHash,
        // pool vrf
        PaymentPubKeyHash,
    ),
    /// The retirement certificate and the Epoch in which the retirement will take place
    PoolRetire(PaymentPubKeyHash, BigInt),
    /// Authorize a Hot credential for a specific Committee member's cold credential
    AuthHotCommittee(ColdCommitteeCredential, HotCommitteeCredential),
    ResignColdCommittee(ColdCommitteeCredential),
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum Voter {
    CommitteeVoter(HotCommitteeCredential),
    DRepVoter(DRepCredential),
    StakePoolVoter(PaymentPubKeyHash),
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum Vote {
    VoteNo,
    VoteYes,
    Abstain,
}

/// Similar to TransactionInput, but for GovernanceAction.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct GovernanceActionId {
    pub tx_id: TransactionHash,
    pub gov_action_id: BigInt,
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct Committee {
    /// Committee members with epoch number when each of them expires
    pub members: AssocMap<ColdCommitteeCredential, BigInt>,
    /// Quorum of the committee that is necessary for a successful vote
    pub quorum: Rational,
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct Constitution {
    /// Optional guardrail script
    pub constitution_script: Option<ScriptHash>,
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct ProtocolVersion {
    pub major: BigInt,
    pub minor: BigInt,
}

// TODO(chfanghr): check invariant according to https://github.com/IntersectMBO/plutus/blob/bb33f082d26f8b6576d3f0d423be53eddfb6abd8/plutus-ledger-api/src/PlutusLedgerApi/V3/Contexts.hs#L338-L364
/// A Plutus Data object containing proposed parameter changes.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Newtype"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct ChangeParameters(pub PlutusData);

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum GovernanceAction {
    /// Propose to change the protocol parameters
    ParameterChange(
        Option<GovernanceActionId>,
        ChangeParameters,
        // The hash of the constitution script
        Option<ScriptHash>,
    ),
    /// Propose to update protocol version
    HardForkInitiation(Option<GovernanceActionId>, ProtocolVersion),
    /// Propose to withdraw from the cardano treasury
    TreasuryWithdrawals(
        AssocMap<Credential, Lovelace>,
        // The hash of the constitution script
        Option<ScriptHash>,
    ),
    /// Propose to create a state of no-confidence in the current constitutional committee
    NoConfidence(Option<GovernanceActionId>),
    /// Propose to update the members of the constitutional committee and/or its signature threshold and/or terms
    UpdateCommittee(
        Option<GovernanceActionId>,
        /// Committee members to be removed
        Vec<ColdCommitteeCredential>,
        /// Committee members to be added
        AssocMap<ColdCommitteeCredential, BigInt>,
        /// New quorum
        Rational,
    ),
    /// Propose to modify the constitution or its guardrail script
    NewConstitution(Option<GovernanceActionId>, Constitution),
    InfoAction,
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct ProtocolProcedure {
    pub deposit: Lovelace,
    pub return_addr: Credential,
    pub governance_action: GovernanceAction,
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum ScriptPurpose {
    Minting(CurrencySymbol),
    Spending(TransactionInput),
    Rewarding(Credential),
    Certifying(
        /// 0-based index of the given `TxCert` in `the `tx_certs` field of the `TransactionInfo`
        BigInt,
        TxCert,
    ),
    Voting(Voter),
    Proposing(
        /// 0-based index of the given `ProposalProcedure` in `protocol_procedures` field of the `TransactionInfo`
        BigInt,
        ProtocolProcedure,
    ),
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub enum ScriptInfo {
    Minting(CurrencySymbol),
    Spending(TransactionInput, Option<Datum>),
    Rewarding(Credential),
    Certifying(BigInt, TxCert),
    Voting(Voter),
    Proposing(BigInt, ProtocolProcedure),
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct TransactionInfo {
    pub inputs: Vec<TxInInfo>,
    pub reference_inputs: Vec<TxInInfo>,
    pub outputs: Vec<TransactionOutput>,
    pub fee: Lovelace,
    pub mint: Value,
    pub tx_certs: Vec<TxCert>,
    pub wdrl: AssocMap<StakingCredential, BigInt>,
    pub valid_range: POSIXTimeRange,
    pub signatories: Vec<PaymentPubKeyHash>,
    pub redeemers: AssocMap<ScriptPurpose, Redeemer>,
    pub datums: AssocMap<DatumHash, Datum>,
    pub id: TransactionHash,
    pub votes: AssocMap<Voter, AssocMap<GovernanceActionId, Vote>>,
    pub protocol_procedures: Vec<ProtocolProcedure>,
    pub current_treasury_amount: Option<Lovelace>,
    pub treasury_donation: Option<Lovelace>,
}

#[derive(Clone, Debug, PartialEq, Eq, IsPlutusData)]
#[is_plutus_data_derive_strategy = "Constr"]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "lbf", derive(Json))]
pub struct ScriptContext {
    pub tx_info: TransactionInfo,
    pub redeemer: Redeemer,
    pub script_info: ScriptInfo,
}