Add script context translation for new Conway certificates

This commit is contained in:
KtorZ 2024-08-12 02:10:00 +02:00
parent f244b9c496
commit bfc93bf076
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
9 changed files with 2883 additions and 72 deletions

View File

@ -108,17 +108,24 @@ pub fn scripts_needed(tx: &MintedTx, utxos: &[ResolvedInput]) -> Result<ScriptsN
.map(|m| { .map(|m| {
m.iter() m.iter()
.enumerate() .enumerate()
.filter_map(|(ix, cert)| { .filter_map(|(ix, cert)| match cert {
// only Dereg and Deleg certs can require scripts Certificate::StakeDeregistration(StakeCredential::Scripthash(h))
match cert { | Certificate::UnReg(StakeCredential::Scripthash(h), _)
Certificate::StakeDeregistration(StakeCredential::Scripthash(h)) => { | Certificate::VoteDeleg(StakeCredential::Scripthash(h), _)
Some((ScriptPurpose::Certifying(ix, cert.clone()), *h)) | Certificate::VoteRegDeleg(StakeCredential::Scripthash(h), _, _)
} | Certificate::StakeVoteDeleg(StakeCredential::Scripthash(h), _, _)
Certificate::StakeDelegation(StakeCredential::Scripthash(h), _) => { | Certificate::StakeRegDeleg(StakeCredential::Scripthash(h), _, _)
| Certificate::StakeVoteRegDeleg(StakeCredential::Scripthash(h), _, _, _)
| Certificate::RegDRepCert(StakeCredential::Scripthash(h), _, _)
| Certificate::UnRegDRepCert(StakeCredential::Scripthash(h), _)
| Certificate::UpdateDRepCert(StakeCredential::Scripthash(h), _)
| Certificate::AuthCommitteeHot(StakeCredential::Scripthash(h), _)
| Certificate::ResignCommitteeCold(StakeCredential::Scripthash(h), _)
| Certificate::StakeDelegation(StakeCredential::Scripthash(h), _) => {
Some((ScriptPurpose::Certifying(ix, cert.clone()), *h)) Some((ScriptPurpose::Certifying(ix, cert.clone()), *h))
} }
_ => None, _ => None,
}
}) })
.collect::<ScriptsNeeded>() .collect::<ScriptsNeeded>()
}) })

View File

@ -1,7 +1,9 @@
use super::{to_plutus_data::MintValue, Error}; use super::{to_plutus_data::MintValue, Error};
use itertools::Itertools; use itertools::Itertools;
use pallas_addresses::{Address, StakePayload}; use pallas_addresses::{Address, StakePayload};
use pallas_codec::utils::{KeyValuePairs, NonEmptyKeyValuePairs, NonEmptySet, Nullable}; use pallas_codec::utils::{
KeyValuePairs, NonEmptyKeyValuePairs, NonEmptySet, Nullable, PositiveCoin,
};
use pallas_crypto::hash::Hash; use pallas_crypto::hash::Hash;
use pallas_primitives::{ use pallas_primitives::{
alonzo, alonzo,
@ -310,10 +312,10 @@ pub struct TxInfoV3 {
pub data: KeyValuePairs<DatumHash, PlutusData>, pub data: KeyValuePairs<DatumHash, PlutusData>,
pub proposal_procedures: Vec<ProposalProcedure>, pub proposal_procedures: Vec<ProposalProcedure>,
pub id: Hash<32>, pub id: Hash<32>,
pub current_treasury_amount: Option<Coin>,
pub treasury_donation: Option<PositiveCoin>,
// TODO: // TODO:
// votes : KeyValuePairs<Voter, KeyValuePairs<GovernanceActionId, Vote>> // votes : KeyValuePairs<Voter, KeyValuePairs<GovernanceActionId, Vote>>
// currentTreasuryAmount : Option<Coin>
// treasuryDonation : Option<Coin>
} }
impl TxInfoV3 { impl TxInfoV3 {
@ -366,6 +368,10 @@ impl TxInfoV3 {
data: KeyValuePairs::from(get_data_info(&tx.transaction_witness_set)), data: KeyValuePairs::from(get_data_info(&tx.transaction_witness_set)),
redeemers, redeemers,
proposal_procedures, proposal_procedures,
current_treasury_amount: get_current_treasury_amount_info(
&tx.transaction_body.treasury_value,
),
treasury_donation: get_treasury_donation_info(&tx.transaction_body.donation),
id: tx.transaction_body.original_hash(), id: tx.transaction_body.original_hash(),
})) }))
} }
@ -594,6 +600,14 @@ pub fn get_fee_info(fee: &Coin) -> Coin {
*fee *fee
} }
pub fn get_current_treasury_amount_info(amount: &Option<Coin>) -> Option<Coin> {
*amount
}
pub fn get_treasury_donation_info(amount: &Option<PositiveCoin>) -> Option<PositiveCoin> {
*amount
}
pub fn get_certificates_info(certificates: &Option<NonEmptySet<Certificate>>) -> Vec<Certificate> { pub fn get_certificates_info(certificates: &Option<NonEmptySet<Certificate>>) -> Vec<Certificate> {
certificates.clone().map(|s| s.to_vec()).unwrap_or_default() certificates.clone().map(|s| s.to_vec()).unwrap_or_default()
} }
@ -807,20 +821,26 @@ pub fn find_script(
.get(redeemer.index as usize) .get(redeemer.index as usize)
.ok_or(Error::MissingScriptForRedeemer) .ok_or(Error::MissingScriptForRedeemer)
.and_then(|cert| match cert { .and_then(|cert| match cert {
Certificate::StakeDeregistration(stake_credential) => match stake_credential { Certificate::StakeDeregistration(stake_credential)
| Certificate::UnReg(stake_credential, _)
| Certificate::VoteDeleg(stake_credential, _)
| Certificate::VoteRegDeleg(stake_credential, _, _)
| Certificate::StakeVoteDeleg(stake_credential, _, _)
| Certificate::StakeRegDeleg(stake_credential, _, _)
| Certificate::StakeVoteRegDeleg(stake_credential, _, _, _)
| Certificate::RegDRepCert(stake_credential, _, _)
| Certificate::UnRegDRepCert(stake_credential, _)
| Certificate::UpdateDRepCert(stake_credential, _)
| Certificate::AuthCommitteeHot(stake_credential, _)
| Certificate::ResignCommitteeCold(stake_credential, _)
| Certificate::StakeDelegation(stake_credential, _) => match stake_credential {
StakeCredential::Scripthash(hash) => Ok(hash), StakeCredential::Scripthash(hash) => Ok(hash),
_ => Err(Error::NonScriptStakeCredential), _ => Err(Error::NonScriptStakeCredential),
}, },
Certificate::StakeDelegation(stake_credential, _) => match stake_credential { Certificate::StakeRegistration { .. }
StakeCredential::Scripthash(hash) => Ok(hash), | Certificate::PoolRetirement { .. }
_ => Err(Error::NonScriptStakeCredential), | Certificate::Reg { .. }
}, | Certificate::PoolRegistration { .. } => Err(Error::UnsupportedCertificateType),
Certificate::PoolRetirement { .. } | Certificate::PoolRegistration { .. } => {
Err(Error::UnsupportedCertificateType)
}
_ => {
todo!("remaining certificate types")
}
}) })
.and_then(lookup_script), .and_then(lookup_script),
@ -1256,4 +1276,74 @@ mod tests {
// from the Haskell ledger / cardano node. // from the Haskell ledger / cardano node.
insta::assert_debug_snapshot!(script_context.to_plutus_data()); insta::assert_debug_snapshot!(script_context.to_plutus_data());
} }
#[test]
fn script_context_certificates() {
let redeemer = Redeemer {
tag: RedeemerTag::Cert,
index: 20,
data: Data::constr(0, vec![]),
ex_units: ExUnits {
mem: 1000000,
steps: 100000000,
},
};
// NOTE: The transaction also contains treasury donation and current treasury amount
let script_context = fixture_tx_info(
"84a6008182582000000000000000000000000000000000000000000000000000\
00000000000000000180049582008201581c2222222222222222222222222222\
222222222222222222222222222282008200581c000000000000000000000000\
0000000000000000000000000000000082018200581c00000000000000000000\
0000000000000000000000000000000000008a03581c11111111111111111111\
1111111111111111111111111111111111115820999999999999999999999999\
99999999999999999999999999999999999999991a000f4240190154d81e8201\
1864581de0000000000000000000000000000000000000000000000000000000\
00d901028080f68304581c111111111111111111111111111111111111111111\
1111111111111119053983078200581c00000000000000000000000000000000\
0000000000000000000000001a002dc6c083088200581c000000000000000000\
000000000000000000000000000000000000001a002dc6c083098200581c0000\
00000000000000000000000000000000000000000000000000008200581c0000\
000000000000000000000000000000000000000000000000000083098200581c\
000000000000000000000000000000000000000000000000000000008201581c\
0000000000000000000000000000000000000000000000000000000083098200\
581c000000000000000000000000000000000000000000000000000000008102\
83098200581c0000000000000000000000000000000000000000000000000000\
00008103840a8200581c00000000000000000000000000000000000000000000\
000000000000581c111111111111111111111111111111111111111111111111\
111111118103840b8200581c0000000000000000000000000000000000000000\
0000000000000000581c11111111111111111111111111111111111111111111\
1111111111111a002dc6c0840c8200581c000000000000000000000000000000\
0000000000000000000000000081031a002dc6c0850d8200581c000000000000\
00000000000000000000000000000000000000000000581c1111111111111111\
111111111111111111111111111111111111111181031a002dc6c0830e820058\
1c00000000000000000000000000000000000000000000000000000000820058\
1c22222222222222222222222222222222222222222222222222222222830f82\
00581c00000000000000000000000000000000000000000000000000000000f6\
84108200581c0000000000000000000000000000000000000000000000000000\
00001a002dc6c0f683118200581c000000000000000000000000000000000000\
000000000000000000001a002dc6c083128200581c0000000000000000000000\
0000000000000000000000000000000000f683028201581c9b24324046544393\
443e1fb35c8b72c3c39e18a516a95df5f6654101581c11111111111111111111\
11111111111111111111111111111111111102182a151a00989680160ea20581\
840214d87980821a000f42401a05f5e1000781587d587b010100323232323232\
3225333333008001153330033370e900018029baa00115333007300637540022\
4a66600894452615330054911856616c696461746f722072657475726e656420\
66616c73650013656002002002002002002153300249010b5f746d70313a2056\
6f696400165734ae7155ceaab9e5573eae91f5f6",
"8182582000000000000000000000000000000000000000000000000000000000\
0000000000",
"81a200581d600000000000000000000000000000000000000000000000000000\
0000011a000f4240",
)
.into_script_context(&redeemer, None)
.unwrap();
// NOTE: The initial snapshot has been generated using the Haskell
// implementation of the ledger library for that same serialized
// transactions. It is meant to control that our construction of the
// script context and its serialization matches exactly those
// from the Haskell ledger / cardano node.
insta::assert_debug_snapshot!(script_context.to_plutus_data());
}
} }

View File

@ -10,11 +10,13 @@ use num_integer::Integer;
use pallas_addresses::{ use pallas_addresses::{
Address, ShelleyDelegationPart, ShelleyPaymentPart, StakeAddress, StakePayload, Address, ShelleyDelegationPart, ShelleyPaymentPart, StakeAddress, StakePayload,
}; };
use pallas_codec::utils::{AnyUInt, Bytes, Int, KeyValuePairs, NonEmptyKeyValuePairs, Nullable}; use pallas_codec::utils::{
AnyUInt, Bytes, Int, KeyValuePairs, NonEmptyKeyValuePairs, Nullable, PositiveCoin,
};
use pallas_crypto::hash::Hash; use pallas_crypto::hash::Hash;
use pallas_primitives::conway::{ use pallas_primitives::conway::{
AssetName, BigInt, Certificate, Coin, Constitution, Constr, DRepVotingThresholds, DatumOption, AssetName, BigInt, Certificate, Coin, Constitution, Constr, DRep, DRepVotingThresholds,
ExUnitPrices, ExUnits, GovAction, GovActionId, Mint, PlutusData, PolicyId, DatumOption, ExUnitPrices, ExUnits, GovAction, GovActionId, Mint, PlutusData, PolicyId,
PoolVotingThresholds, ProposalProcedure, ProtocolParamUpdate, PseudoScript, RationalNumber, PoolVotingThresholds, ProposalProcedure, ProtocolParamUpdate, PseudoScript, RationalNumber,
Redeemer, ScriptRef, StakeCredential, TransactionInput, TransactionOutput, Value, Redeemer, ScriptRef, StakeCredential, TransactionInput, TransactionOutput, Value,
}; };
@ -47,6 +49,8 @@ struct WithOptionDatum<'a, T>(&'a T);
struct WithArrayRational<'a, T>(&'a T); struct WithArrayRational<'a, T>(&'a T);
struct WithPartialCertificates<'a, T>(&'a T);
pub trait ToPlutusData { pub trait ToPlutusData {
fn to_plutus_data(&self) -> PlutusData; fn to_plutus_data(&self) -> PlutusData;
} }
@ -268,6 +272,12 @@ impl ToPlutusData for usize {
} }
} }
impl ToPlutusData for PositiveCoin {
fn to_plutus_data(&self) -> PlutusData {
u64::from(self).to_plutus_data()
}
}
impl<'a> ToPlutusData for WithZeroAdaAsset<'a, Value> { impl<'a> ToPlutusData for WithZeroAdaAsset<'a, Value> {
fn to_plutus_data(&self) -> PlutusData { fn to_plutus_data(&self) -> PlutusData {
match self.0 { match self.0 {
@ -487,15 +497,27 @@ impl ToPlutusData for StakeCredential {
} }
} }
impl ToPlutusData for Certificate { impl<'a> ToPlutusData for WithPartialCertificates<'a, Vec<Certificate>> {
fn to_plutus_data(&self) -> PlutusData { fn to_plutus_data(&self) -> PlutusData {
match self { self.0
.iter()
.map(WithPartialCertificates)
.collect::<Vec<_>>()
.to_plutus_data()
}
}
impl<'a> ToPlutusData for WithPartialCertificates<'a, Certificate> {
fn to_plutus_data(&self) -> PlutusData {
match self.0 {
Certificate::StakeRegistration(stake_credential) => { Certificate::StakeRegistration(stake_credential) => {
wrap_with_constr(0, stake_credential.to_plutus_data()) wrap_with_constr(0, stake_credential.to_plutus_data())
} }
Certificate::StakeDeregistration(stake_credential) => { Certificate::StakeDeregistration(stake_credential) => {
wrap_with_constr(1, stake_credential.to_plutus_data()) wrap_with_constr(1, stake_credential.to_plutus_data())
} }
Certificate::StakeDelegation(stake_credential, pool_keyhash) => { Certificate::StakeDelegation(stake_credential, pool_keyhash) => {
wrap_multiple_with_constr( wrap_multiple_with_constr(
2, 2,
@ -505,6 +527,7 @@ impl ToPlutusData for Certificate {
], ],
) )
} }
Certificate::PoolRegistration { Certificate::PoolRegistration {
operator, operator,
vrf_keyhash, vrf_keyhash,
@ -519,22 +542,181 @@ impl ToPlutusData for Certificate {
3, 3,
vec![operator.to_plutus_data(), vrf_keyhash.to_plutus_data()], vec![operator.to_plutus_data(), vrf_keyhash.to_plutus_data()],
), ),
Certificate::PoolRetirement(pool_keyhash, epoch) => wrap_multiple_with_constr( Certificate::PoolRetirement(pool_keyhash, epoch) => wrap_multiple_with_constr(
4, 4,
vec![pool_keyhash.to_plutus_data(), epoch.to_plutus_data()], vec![pool_keyhash.to_plutus_data(), epoch.to_plutus_data()],
), ),
_ => todo!("other certificates"), // Reg(StakeCredential, Coin),
// UnReg(StakeCredential, Coin), certificate => unreachable!("unexpected in V1/V2 script context: {certificate:?}"),
// VoteDeleg(StakeCredential, DRep), }
// StakeVoteDeleg(StakeCredential, PoolKeyhash, DRep), }
// StakeRegDeleg(StakeCredential, PoolKeyhash, Coin), }
// VoteRegDeleg(StakeCredential, DRep, Coin),
// StakeVoteRegDeleg(StakeCredential, PoolKeyhash, DRep, Coin), impl ToPlutusData for Certificate {
// AuthCommitteeHot(CommitteeColdCredential, CommitteeHotCredential), fn to_plutus_data(&self) -> PlutusData {
// ResignCommitteeCold(CommitteeColdCredential, Nullable<Anchor>), match self {
// RegDRepCert(DRepCredential, Coin, Nullable<Anchor>), Certificate::StakeRegistration(stake_credential) => wrap_multiple_with_constr(
// UnRegDRepCert(DRepCredential, Coin), 0,
// UpdateDRepCert(StakeCredential, Nullable<Anchor>), vec![
stake_credential.to_plutus_data(),
None::<PlutusData>.to_plutus_data(),
],
),
Certificate::Reg(stake_credential, deposit) => wrap_multiple_with_constr(
0,
vec![
stake_credential.to_plutus_data(),
Some(*deposit).to_plutus_data(),
],
),
Certificate::StakeDeregistration(stake_credential) => wrap_multiple_with_constr(
1,
vec![
stake_credential.to_plutus_data(),
None::<PlutusData>.to_plutus_data(),
],
),
Certificate::UnReg(stake_credential, deposit) => wrap_multiple_with_constr(
1,
vec![
stake_credential.to_plutus_data(),
Some(*deposit).to_plutus_data(),
],
),
Certificate::StakeDelegation(stake_credential, pool_id) => wrap_multiple_with_constr(
2,
vec![
stake_credential.to_plutus_data(),
wrap_with_constr(0, pool_id.to_plutus_data()),
],
),
Certificate::VoteDeleg(stake_credential, drep) => wrap_multiple_with_constr(
2,
vec![
stake_credential.to_plutus_data(),
wrap_with_constr(1, drep.to_plutus_data()),
],
),
Certificate::StakeVoteDeleg(stake_credential, pool_id, drep) => {
wrap_multiple_with_constr(
2,
vec![
stake_credential.to_plutus_data(),
wrap_multiple_with_constr(
2,
vec![pool_id.to_plutus_data(), drep.to_plutus_data()],
),
],
)
}
Certificate::StakeRegDeleg(stake_credential, pool_id, deposit) => {
wrap_multiple_with_constr(
3,
vec![
stake_credential.to_plutus_data(),
wrap_multiple_with_constr(0, vec![pool_id.to_plutus_data()]),
deposit.to_plutus_data(),
],
)
}
Certificate::VoteRegDeleg(stake_credential, drep, deposit) => {
wrap_multiple_with_constr(
3,
vec![
stake_credential.to_plutus_data(),
wrap_multiple_with_constr(1, vec![drep.to_plutus_data()]),
deposit.to_plutus_data(),
],
)
}
Certificate::StakeVoteRegDeleg(stake_credential, pool_id, drep, deposit) => {
wrap_multiple_with_constr(
3,
vec![
stake_credential.to_plutus_data(),
wrap_multiple_with_constr(
2,
vec![pool_id.to_plutus_data(), drep.to_plutus_data()],
),
deposit.to_plutus_data(),
],
)
}
Certificate::RegDRepCert(drep_credential, deposit, _anchor) => {
wrap_multiple_with_constr(
4,
vec![drep_credential.to_plutus_data(), deposit.to_plutus_data()],
)
}
Certificate::UpdateDRepCert(drep_credential, _anchor) => {
wrap_multiple_with_constr(5, vec![drep_credential.to_plutus_data()])
}
Certificate::UnRegDRepCert(drep_credential, deposit) => wrap_multiple_with_constr(
6,
vec![drep_credential.to_plutus_data(), deposit.to_plutus_data()],
),
Certificate::PoolRegistration {
operator,
vrf_keyhash,
pledge: _,
cost: _,
margin: _,
reward_account: _,
pool_owners: _,
relays: _,
pool_metadata: _,
} => wrap_multiple_with_constr(
7,
vec![operator.to_plutus_data(), vrf_keyhash.to_plutus_data()],
),
Certificate::PoolRetirement(pool_keyhash, epoch) => wrap_multiple_with_constr(
8,
vec![pool_keyhash.to_plutus_data(), epoch.to_plutus_data()],
),
Certificate::AuthCommitteeHot(cold_credential, hot_credential) => {
wrap_multiple_with_constr(
9,
vec![
cold_credential.to_plutus_data(),
hot_credential.to_plutus_data(),
],
)
}
Certificate::ResignCommitteeCold(cold_credential, _anchor) => {
wrap_multiple_with_constr(10, vec![cold_credential.to_plutus_data()])
}
}
}
}
impl ToPlutusData for DRep {
fn to_plutus_data(&self) -> PlutusData {
match self {
DRep::Key(hash) => {
wrap_with_constr(0, StakeCredential::AddrKeyhash(*hash).to_plutus_data())
}
DRep::Script(hash) => {
wrap_with_constr(0, StakeCredential::Scripthash(*hash).to_plutus_data())
}
DRep::Abstain => empty_constr(1),
DRep::NoConfidence => empty_constr(2),
} }
} }
} }
@ -1147,7 +1329,7 @@ impl ToPlutusData for TxInfo {
WithOptionDatum(&WithZeroAdaAsset(&tx_info.outputs)).to_plutus_data(), WithOptionDatum(&WithZeroAdaAsset(&tx_info.outputs)).to_plutus_data(),
WithZeroAdaAsset(&tx_info.fee).to_plutus_data(), WithZeroAdaAsset(&tx_info.fee).to_plutus_data(),
WithZeroAdaAsset(&tx_info.mint).to_plutus_data(), WithZeroAdaAsset(&tx_info.mint).to_plutus_data(),
tx_info.certificates.to_plutus_data(), WithPartialCertificates(&tx_info.certificates).to_plutus_data(),
WithWrappedStakeCredential(&tx_info.withdrawals).to_plutus_data(), WithWrappedStakeCredential(&tx_info.withdrawals).to_plutus_data(),
tx_info.valid_range.to_plutus_data(), tx_info.valid_range.to_plutus_data(),
tx_info.signatories.to_plutus_data(), tx_info.signatories.to_plutus_data(),
@ -1164,7 +1346,7 @@ impl ToPlutusData for TxInfo {
WithZeroAdaAsset(&tx_info.outputs).to_plutus_data(), WithZeroAdaAsset(&tx_info.outputs).to_plutus_data(),
WithZeroAdaAsset(&tx_info.fee).to_plutus_data(), WithZeroAdaAsset(&tx_info.fee).to_plutus_data(),
WithZeroAdaAsset(&tx_info.mint).to_plutus_data(), WithZeroAdaAsset(&tx_info.mint).to_plutus_data(),
tx_info.certificates.to_plutus_data(), WithPartialCertificates(&tx_info.certificates).to_plutus_data(),
WithWrappedStakeCredential(&tx_info.withdrawals).to_plutus_data(), WithWrappedStakeCredential(&tx_info.withdrawals).to_plutus_data(),
tx_info.valid_range.to_plutus_data(), tx_info.valid_range.to_plutus_data(),
tx_info.signatories.to_plutus_data(), tx_info.signatories.to_plutus_data(),
@ -1190,8 +1372,8 @@ impl ToPlutusData for TxInfo {
tx_info.id.to_plutus_data(), tx_info.id.to_plutus_data(),
Data::map(vec![]), // TODO tx_info.votes :: Map Voter (Map GovernanceActionId Vote) Data::map(vec![]), // TODO tx_info.votes :: Map Voter (Map GovernanceActionId Vote)
tx_info.proposal_procedures.to_plutus_data(), tx_info.proposal_procedures.to_plutus_data(),
empty_constr(1), // TODO tx_info.current_treasury_amount :: Haskell.Maybe V2.Lovelace tx_info.current_treasury_amount.to_plutus_data(),
empty_constr(1), // TODO tx_info.treasury_donation :: Haskell.Maybe V2.Lovelace tx_info.treasury_donation.to_plutus_data(),
], ],
), ),
} }

View File

@ -23,7 +23,7 @@ for convenience.
- [x] spend - [x] spend
- [x] mint - [x] mint
- [ ] withdraw - [ ] withdraw
- [ ] publish - [x] publish
- [ ] voting - [ ] voting
- [x] proposing - [x] proposing
@ -41,20 +41,20 @@ for convenience.
- [x] none - [x] none
- some - some
- Register credential - Register credential
- [ ] no deposit - [x] no deposit
- [ ] with deposit - [x] with deposit
- Unregister credential - Unregister credential
- [ ] no deposit - [x] no deposit
- [ ] with deposit - [x] with deposit
- [ ] Delegate - [x] Delegate
- [ ] Register & delegate credential - [x] Register & delegate credential
- [ ] Register drep - [x] Register drep
- [ ] Unregister drep - [x] Unregister drep
- [ ] Update drep - [x] Update drep
- [ ] Register pool - [x] Register pool
- [ ] Retire pool - [x] Retire pool
- [ ] Delegate CC - [x] Delegate CC
- [ ] Retire CC - [x] Retire CC
- withdrawals - withdrawals
- [x] none - [x] none
- [ ] some - [ ] some
@ -71,10 +71,10 @@ for convenience.
- [x] none - [x] none
- [x] some - [x] some
- current treasury - current treasury
- [ ] with - [x] with
- [x] without - [x] without
- treasury donation - treasury donation
- [ ] with - [x] with
- [x] without - [x] without
- Address - Address
@ -102,8 +102,8 @@ for convenience.
- Governance Action - Governance Action
- parameter change - parameter change
- [ ] with action id - [x] with action id
- [ ] without action id - [x] without action id
- hardfork initiation - hardfork initiation
- [x] with action id - [x] with action id
- [x] without action id - [x] without action id
@ -172,15 +172,15 @@ for convenience.
- [x] script - [x] script
- Delegatee - Delegatee
- [ ] pool - [x] pool
- [ ] drep - [x] drep
- [ ] pool + drep - [x] pool + drep
- DRep - DRep
- [ ] key - [x] key
- [ ] script - [x] script
- [ ] abstain - [x] abstain
- [ ] no confidence - [x] no confidence
- Boundary - Boundary
- [ ] closed - [ ] closed

View File

@ -0,0 +1,5 @@
[
{ 0: h'6000000000000000000000000000000000000000000000000000000000'
, 1: 1000000
}
]

View File

@ -0,0 +1,118 @@
[
{ 0:
[ [h'0000000000000000000000000000000000000000000000000000000000000000', 0]
]
, 1:
[]
, 4:
[ [0, [1, h'22222222222222222222222222222222222222222222222222222222' ] ]
, [0, [0, h'00000000000000000000000000000000000000000000000000000000' ] ]
, [1, [0, h'00000000000000000000000000000000000000000000000000000000' ] ]
, [ 3
, h'11111111111111111111111111111111111111111111111111111111'
, h'9999999999999999999999999999999999999999999999999999999999999999'
, 1000000
, 340
, 30([1, 100])
, h'E000000000000000000000000000000000000000000000000000000000'
, 258([])
, []
, null
]
, [ 4
, h'11111111111111111111111111111111111111111111111111111111'
, 1337
]
, [ 7
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, 3000000
]
, [ 8
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, 3000000
]
, [ 9
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
]
, [ 9
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [1, h'00000000000000000000000000000000000000000000000000000000' ]
]
, [ 9
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [ 2 ]
]
, [ 9
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [ 3 ]
]
, [ 10
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, h'11111111111111111111111111111111111111111111111111111111'
, [ 3 ]
]
, [ 11
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, h'11111111111111111111111111111111111111111111111111111111'
, 3000000
]
, [ 12
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [ 3 ]
, 3000000
]
, [ 13
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, h'11111111111111111111111111111111111111111111111111111111'
, [ 3 ]
, 3000000
]
, [ 14
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, [0, h'22222222222222222222222222222222222222222222222222222222' ]
]
, [ 15
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, null
]
, [ 16
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, 3000000
, null
]
, [ 17
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, 3000000
]
, [ 18
, [0, h'00000000000000000000000000000000000000000000000000000000' ]
, null
]
, [ 2
, [ 1
, h'{{ certificates.script.hash }}'
]
, h'11111111111111111111111111111111111111111111111111111111'
]
]
, 2: 42
, 21: 10000000
, 22: 14
},
{ 5: [[2, 20, 121([]), [1000000, 100000000]]]
, 7: [h'{{ certificates.script.cbor }}']
},
true,
null
]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,207 @@
use aiken/collection/list
use cardano/certificate.{
AlwaysAbstain, AlwaysNoConfidence, AuthorizeConstitutionalCommitteeProxy,
DelegateBlockProduction, DelegateBoth, DelegateCredential, DelegateVote,
RegisterAndDelegateCredential, RegisterCredential,
RegisterDelegateRepresentative, RegisterStakePool, Registered,
RetireFromConstitutionalCommittee, RetireStakePool, UnregisterCredential,
UnregisterDelegateRepresentative, UpdateDelegateRepresentative,
}
use cardano/credential.{Script, VerificationKey}
use cardano/transaction.{Publishing, ScriptContext, ScriptInfo}
const only0s = #"00000000000000000000000000000000000000000000000000000000"
const only1s = #"11111111111111111111111111111111111111111111111111111111"
const only2s = #"22222222222222222222222222222222222222222222222222222222"
const only9s =
#"9999999999999999999999999999999999999999999999999999999999999999"
validator {
fn script(_tmp1: Void, ctx: ScriptContext) -> Bool {
assert_script_info(ctx.info)
let certificates = ctx.transaction.certificates
expect Some(10_000_000) = ctx.transaction.current_treasury_amount
expect Some(14) = ctx.transaction.treasury_donation
expect
Some(RegisterCredential { credential: Script(only2s), deposit: None }) == list.at(
certificates,
0,
)
expect
Some(
RegisterCredential {
credential: VerificationKey(only0s),
deposit: None,
},
) == list.at(certificates, 1)
expect
Some(
UnregisterCredential {
credential: VerificationKey(only0s),
refund: None,
},
) == list.at(certificates, 2)
expect
Some(RegisterStakePool { stake_pool: only1s, vrf: only9s }) == list.at(
certificates,
3,
)
expect
Some(RetireStakePool { stake_pool: only1s, at_epoch: 1337 }) == list.at(
certificates,
4,
)
expect
Some(
RegisterCredential {
credential: VerificationKey(only0s),
deposit: Some(3_000_000),
},
) == list.at(certificates, 5)
expect
Some(
UnregisterCredential {
credential: VerificationKey(only0s),
refund: Some(3_000_000),
},
) == list.at(certificates, 6)
expect
Some(
DelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateVote(Registered(VerificationKey(only0s))),
},
) == list.at(certificates, 7)
expect
Some(
DelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateVote(Registered(Script(only0s))),
},
) == list.at(certificates, 8)
expect
Some(
DelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateVote(AlwaysAbstain),
},
) == list.at(certificates, 9)
expect
Some(
DelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateVote(AlwaysNoConfidence),
},
) == list.at(certificates, 10)
expect
Some(
DelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateBoth {
stake_pool: only1s,
delegate_representative: AlwaysNoConfidence,
},
},
) == list.at(certificates, 11)
expect
Some(
RegisterAndDelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateBlockProduction(only1s),
deposit: 3_000_000,
},
) == list.at(certificates, 12)
expect
Some(
RegisterAndDelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateVote(AlwaysNoConfidence),
deposit: 3_000_000,
},
) == list.at(certificates, 13)
expect
Some(
RegisterAndDelegateCredential {
credential: VerificationKey(only0s),
delegate: DelegateBoth {
stake_pool: only1s,
delegate_representative: AlwaysNoConfidence,
},
deposit: 3_000_000,
},
) == list.at(certificates, 14)
expect
Some(
AuthorizeConstitutionalCommitteeProxy {
constitutional_committee_member: VerificationKey(only0s),
proxy: VerificationKey(only2s),
},
) == list.at(certificates, 15)
expect
Some(
RetireFromConstitutionalCommittee {
constitutional_committee_member: VerificationKey(only0s),
},
) == list.at(certificates, 16)
expect
Some(
RegisterDelegateRepresentative {
delegate_representative: VerificationKey(only0s),
deposit: 3_000_000,
},
) == list.at(certificates, 17)
expect
Some(
UnregisterDelegateRepresentative {
delegate_representative: VerificationKey(only0s),
refund: 3_000_000,
},
) == list.at(certificates, 18)
expect
Some(
UpdateDelegateRepresentative {
delegate_representative: VerificationKey(only0s),
},
) == list.at(certificates, 19)
expect Some(DelegateCredential {
credential: Script(..),
delegate: DelegateBlockProduction(..),
}) = list.at(certificates, 20)
True
}
}
fn assert_script_info(info: ScriptInfo) {
expect Publishing(20, DelegateCredential { credential, delegate }) = info
expect DelegateBlockProduction { stake_pool: only1s } == delegate
expect Script(..) = credential
Void
}