Skip to content

Commit b6a3dfd

Browse files
committed
Adjust ProposalProcedure following end-to-end testing.
1 parent c8e3b2f commit b6a3dfd

File tree

5 files changed

+96
-95
lines changed

5 files changed

+96
-95
lines changed

lib/aiken/collection.ak

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// An positive integer, that materializes the position of an element in a
2+
/// collection.
3+
pub type Index =
4+
Int

lib/cardano/certificate.ak

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use cardano/assets.{Lovelace}
2-
use cardano/credential.{
3-
ColdCommitteeCredential, DRepCredential, HotCommitteeCredential, PoolId,
4-
StakeCredential, VerificationKeyHash,
5-
}
2+
use cardano/credential.{Credential,
3+
PoolId, StakeCredential, VerificationKeyHash}
64
use cardano/governance.{Delegatee}
75

86
/// An on-chain certificate attesting of some operation. Publishing
@@ -29,11 +27,11 @@ pub type Certificate {
2927
deposit_amount: Lovelace,
3028
}
3129
// Register a DRep with a deposit value. The optional anchor is omitted.
32-
RegisterDRep { representative: DRepCredential, deposit_amount: Lovelace }
30+
RegisterDRep { representative: Credential, deposit_amount: Lovelace }
3331
// Update a DRep. The optional anchor is omitted.
34-
UpdateDRep { representative: DRepCredential }
32+
UpdateDRep { representative: Credential }
3533
// UnRegister a DRep with mandatory refund value
36-
UnregisterDRep { representative: DRepCredential, refund_amount: Lovelace }
34+
UnregisterDRep { representative: Credential, refund_amount: Lovelace }
3735
// A digest of the PoolParams
3836
PoolRegister {
3937
// poolId
@@ -44,9 +42,6 @@ pub type Certificate {
4442
// The retirement certificate and the Epoch in which the retirement will take place
4543
PoolRetire { pool_id: PoolId, epoch: Int }
4644
// Authorize a Hot credential for a specific Committee member's cold credential
47-
AuthorizeHotCommittee {
48-
cold_memeber: ColdCommitteeCredential,
49-
hot_member: HotCommitteeCredential,
50-
}
51-
ResignColdCommittee { cold_member: ColdCommitteeCredential }
45+
AuthorizeHotCommittee { cold_memeber: Credential, hot_member: Credential }
46+
ResignColdCommittee { cold_member: Credential }
5247
}

lib/cardano/credential.ak

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use aiken/hash.{Blake2b_224, Blake2b_256, Hash}
66
/// Credentials are always one of two kinds: a direct public/private key
77
/// pair, or a script (native or Plutus).
88
pub type Credential {
9-
VerificationKeyCredential(Hash<Blake2b_224, VerificationKey>)
10-
ScriptCredential(Hash<Blake2b_224, Script>)
9+
VerificationKey(VerificationKeyHash)
10+
Script(ScriptHash)
1111
}
1212

1313
/// A Cardano `Address` typically holding one or two credential references.
@@ -23,18 +23,12 @@ pub type Address {
2323

2424
/// Smart-constructor for an [Address](#Address) from a [verification key](#VerificationKey) hash. The resulting address has no delegation rights whatsoever.
2525
pub fn from_verification_key(vk: Hash<Blake2b_224, VerificationKey>) -> Address {
26-
Address {
27-
payment_credential: VerificationKeyCredential(vk),
28-
stake_credential: None,
29-
}
26+
Address { payment_credential: VerificationKey(vk), stake_credential: None }
3027
}
3128

3229
/// Smart-constructor for an [Address](#Address) from a [script](#Script) hash. The address has no delegation rights whatsoever.
3330
pub fn from_script(script: Hash<Blake2b_224, Script>) -> Address {
34-
Address {
35-
payment_credential: ScriptCredential(script),
36-
stake_credential: None,
37-
}
31+
Address { payment_credential: Script(script), stake_credential: None }
3832
}
3933

4034
/// Set (or reset) the delegation part of an [Address](#Address) using a [verification key](#VerificationKey) hash. This is useful when combined with [`from_verification_key`](#from_verification_key) and/or [`from_script`](#from_script).
@@ -44,7 +38,7 @@ pub fn with_delegation_key(
4438
) -> Address {
4539
Address {
4640
payment_credential: self.payment_credential,
47-
stake_credential: Some(Inline(VerificationKeyCredential(vk))),
41+
stake_credential: Some(Inline(VerificationKey(vk))),
4842
}
4943
}
5044

@@ -55,7 +49,7 @@ pub fn with_delegation_script(
5549
) -> Address {
5650
Address {
5751
payment_credential: self.payment_credential,
58-
stake_credential: Some(Inline(ScriptCredential(script))),
52+
stake_credential: Some(Inline(Script(script))),
5953
}
6054
}
6155

@@ -119,15 +113,3 @@ pub type ScriptHash =
119113
// DatumHash is taken as a Datum type so this may just need to change.
120114
pub type DatumHashDigest =
121115
Hash<Blake2b_256, Data>
122-
123-
pub type DRepCredential {
124-
member: Credential,
125-
}
126-
127-
pub type ColdCommitteeCredential {
128-
member: Credential,
129-
}
130-
131-
pub type HotCommitteeCredential {
132-
member: Credential,
133-
}

lib/cardano/governance.ak

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use aiken/collection/dict.{Dict}
1+
use aiken/collection.{Index}
22
use aiken/math/rational.{Rational}
33
use cardano/assets.{Lovelace}
4-
use cardano/credential.{
5-
ColdCommitteeCredential, Credential, DRepCredential, HotCommitteeCredential,
6-
ScriptHash, VerificationKeyHash,
7-
}
4+
use cardano/credential.{Credential, ScriptHash, VerificationKeyHash}
85

96
pub type DRep {
10-
FromCredential(DRepCredential)
7+
FromCredential(Credential)
118
AlwaysAbstain
129
AlwaysNoConfidence
1310
}
@@ -26,64 +23,97 @@ pub type Vote {
2623

2724
pub type GovernanceActionId {
2825
transaction_id: ByteArray,
29-
index: Int,
26+
proposal_procedure: Index,
3027
}
3128

32-
pub type ChangedProtocolParameters {
33-
new_parameters: Data,
34-
}
29+
pub type ProtocolParametersUpdate =
30+
Data
3531

3632
pub type ProtocolVersion {
3733
major: Int,
3834
minor: Int,
3935
}
4036

4137
pub type Constitution {
42-
guardrails_script: Option<ScriptHash>,
38+
guardrails: Option<ScriptHash>,
4339
}
4440

4541
pub type GovernanceAction {
46-
//
47-
ProtocolParametersChange(
48-
Option<GovernanceActionId>,
49-
ChangedProtocolParameters,
50-
// Hash of the constitution script
51-
Option<ScriptHash>,
52-
)
53-
// proposal to update protocol version
54-
HardForkInitiation(Option<GovernanceActionId>, ProtocolVersion)
55-
//
56-
TreasuryWithdrawals(
57-
Dict<Credential, Lovelace>,
58-
// Hash of the constitution script
59-
Option<ScriptHash>,
60-
)
61-
//
62-
NoConfidence(Option<GovernanceActionId>)
63-
//
64-
UpdateCommittee(
65-
Option<GovernanceActionId>,
66-
// Committee members to be removed
67-
List<ColdCommitteeCredential>,
68-
// Committee members to be added
69-
Dict<ColdCommitteeCredential, Int>,
70-
// New quorum
71-
Rational,
72-
)
73-
//
74-
NewConstitution(Option<GovernanceActionId>, Constitution)
75-
//
76-
InfoAction
42+
ProtocolParameters {
43+
/// The last governance action of type 'ProtocolParameters'. They must all
44+
/// form a chain.
45+
ancestor: Option<GovernanceActionId>,
46+
/// The new proposed protocol parameters. Only values set to `Some` are relevant.
47+
new_parameters: ProtocolParametersUpdate,
48+
/// The optional guardrails script defined in the constitution. The script
49+
/// is executed by the ledger in addition to the hard-coded ledger rules.
50+
///
51+
/// It must pass for the new protocol parameters to be deemed valid.
52+
guardrails: Option<ScriptHash>,
53+
}
54+
Hardfork {
55+
/// The last governance action of type `HardFork`. They must all
56+
/// form a chain.
57+
ancestor: Option<GovernanceActionId>,
58+
/// The new proposed version. Few rules apply to proposing new versions:
59+
///
60+
/// - The `major` component, if incremented, must be exactly one more than the current.
61+
/// - The `minor` component, if incremented, must be exactly one more than the current.
62+
/// - If the `major` component is incremented, `minor` must be set to `0`.
63+
/// - Neither `minor` nor `major` can be decremented.
64+
new_version: ProtocolVersion,
65+
}
66+
TreasuryWithdrawal {
67+
/// A collection of beneficiaries, which can be plain verification key
68+
/// hashes or script hashes (e.g. DAO).
69+
beneficiaries: Pairs<Credential, Lovelace>,
70+
/// The optional guardrails script defined in the constitution. The script
71+
/// is executed by the ledger in addition to the hard-coded ledger rules.
72+
///
73+
/// It must pass for the withdrawals to be authorized.
74+
guardrails: Option<ScriptHash>,
75+
}
76+
NoConfidence {
77+
/// The last governance action of type `NoConfidence` or
78+
/// `ConstitutionalCommittee`. They must all / form a chain.
79+
ancestor: Option<GovernanceActionId>,
80+
}
81+
ConstitutionalCommittee {
82+
/// The last governance action of type `NoConfidence` or
83+
/// `ConstitutionalCommittee`. They must all / form a chain.
84+
ancestor: Option<GovernanceActionId>,
85+
/// Constitutional members to be removed.
86+
evicted_members: List<Credential>,
87+
/// Constitutional members to be added.
88+
added_members: Pairs<Credential, Mandate>,
89+
/// The new quorum value, as a ratio of a numerator and a denominator. The
90+
/// quorum specifies the threshold of 'Yes' votes necessary for the
91+
/// constitutional committee to accept a proposal procedure.
92+
quorum: Rational,
93+
}
94+
NewConstitution {
95+
/// The last governance action of type `Constitution` or
96+
/// `ConstitutionalCommittee`. They must all / form a chain.
97+
ancestor: Option<GovernanceActionId>,
98+
/// The new proposed constitution.
99+
constitution: Constitution,
100+
}
101+
NicePoll
77102
}
78103

104+
/// An epoch number after which constitutional committee member
105+
/// mandate expires.
106+
pub type Mandate =
107+
Int
108+
79109
pub type ProposalProcedure {
80110
deposit: Lovelace,
81111
return_address: Credential,
82112
governance_action: GovernanceAction,
83113
}
84114

85115
pub type Voter {
86-
CommitteeVoter(HotCommitteeCredential)
87-
DRepVoter(DRepCredential)
116+
CommitteeVoter(Credential)
117+
DRepVoter(Credential)
88118
StakePoolVoter(VerificationKeyHash)
89119
}

lib/cardano/transaction.ak

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use aiken/builtin
2+
use aiken/collection.{Index}
23
use aiken/collection/dict.{Dict}
34
use aiken/collection/list
45
use aiken/hash.{Blake2b_256, Hash, blake2b_256}
@@ -7,16 +8,11 @@ use aiken/option
78
use cardano/assets.{Lovelace, PolicyId, Value}
89
use cardano/certificate.{Certificate}
910
use cardano/credential.{
10-
Address, DatumHashDigest, ScriptCredential, ScriptHash, StakeCredential,
11-
VerificationKeyCredential, VerificationKeyHash,
11+
Address, DatumHashDigest, Script, ScriptHash, StakeCredential, VerificationKey,
12+
VerificationKeyHash,
1213
}
1314
use cardano/governance.{GovernanceActionId, ProposalProcedure, Vote, Voter}
1415

15-
/// An positive integer, that materializes the position of an element in a
16-
/// collection.
17-
type Index =
18-
Int
19-
2016
/// A context given to a script by the Cardano ledger when being executed.
2117
///
2218
/// The context contains information about the entire transaction that contains
@@ -103,20 +99,15 @@ pub type Transaction {
10399
reference_inputs: List<Input>,
104100
outputs: List<Output>,
105101
fee: Lovelace,
106-
// ^ the fee is now lovelace
107102
mint: Value,
108-
// ^ minted value is now back to a value
109103
certificates: List<Certificate>,
110104
withdrawals: Pairs<StakeCredential, Lovelace>,
111105
validity_range: ValidityRange,
112106
extra_signatories: List<VerificationKeyHash>,
113107
redeemers: Pairs<ScriptPurpose, Redeemer>,
114-
// ^ Pairs and ScriptPurpose are used here
115108
datums: Dict<DatumHashDigest, Data>,
116109
id: Hash<Blake2b_256, Transaction>,
117-
// new fields for v3
118110
votes: Dict<Voter, Dict<GovernanceActionId, Vote>>,
119-
// ^ Does this need to be pairs?
120111
proposal_procedures: List<ProposalProcedure>,
121112
current_treasury_amount: Option<Lovelace>,
122113
treasury_donation: Option<Lovelace>,
@@ -268,9 +259,8 @@ pub fn find_script_outputs(
268259
|> list.filter(
269260
fn(output) {
270261
when output.address.payment_credential is {
271-
ScriptCredential(addr_script_hash) ->
272-
script_hash == addr_script_hash
273-
VerificationKeyCredential(_) -> False
262+
Script(addr_script_hash) -> script_hash == addr_script_hash
263+
VerificationKey(_) -> False
274264
}
275265
},
276266
)

0 commit comments

Comments
 (0)