From 01caa7866a2cdbe5b5932a19391e8795e0799092 Mon Sep 17 00:00:00 2001 From: twwu123 Date: Sat, 22 Jun 2024 22:18:41 +0800 Subject: [PATCH 1/4] add types for government actions --- packages/sidan-csl-rs/src/builder/core.rs | 3 + packages/sidan-csl-rs/src/model/mod.rs | 106 +++++++++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/packages/sidan-csl-rs/src/builder/core.rs b/packages/sidan-csl-rs/src/builder/core.rs index 132662d..d3d2dca 100644 --- a/packages/sidan-csl-rs/src/builder/core.rs +++ b/packages/sidan-csl-rs/src/builder/core.rs @@ -247,6 +247,9 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { } Certificate::RetirePool(retire_pool) => { mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool) + }, + _ => { + // TODO: implement government actions } } } diff --git a/packages/sidan-csl-rs/src/model/mod.rs b/packages/sidan-csl-rs/src/model/mod.rs index 6341e2a..7839d66 100644 --- a/packages/sidan-csl-rs/src/model/mod.rs +++ b/packages/sidan-csl-rs/src/model/mod.rs @@ -211,11 +211,21 @@ pub struct Metadata { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub enum Certificate { - RegisterPool(RegisterPool), RegisterStake(RegisterStake), - DelegateStake(DelegateStake), DeregisterStake(DeregisterStake), + DelegateStake(DelegateStake), + RegisterPool(RegisterPool), RetirePool(RetirePool), + VoteDelegation(VoteDelegation), + StakeAndVoteDelegation(StakeAndVoteDelegation), + StakeRegistrationAndDelegation(StakeRegistrationAndDelegation), + VoteRegistrationAndDelegation(VoteRegistrationAndDelegation), + StakeVoteRegistrationAndDelegation(StakeVoteRegistrationAndDelegation), + CommitteeHotAuth(CommitteeHotAuth), + CommitteeColdResign(CommitteeColdResign), + DRepRegistration(DRepRegistration), + DRepDeregistration(DRepDeregistration), + DRepUpdate(DRepUpdate), } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -300,6 +310,98 @@ pub struct RetirePool { pub epoch: u32, } +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct VoteDelegation { + pub stake_key_hash: String, + pub drep: DRep, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum DRep { + KeyHash(String), + ScriptHash(String), + AlwaysAbstain, + AlwaysNoConfidence, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StakeAndVoteDelegation { + pub stake_key_hash: String, + pub pool_key_hash: String, + pub drep: DRep, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StakeRegistrationAndDelegation { + pub stake_key_hash: String, + pub pool_key_hash: String, + pub coin: u64, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct VoteRegistrationAndDelegation { + pub stake_key_hash: String, + pub drep: DRep, + pub coin: u64, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct StakeVoteRegistrationAndDelegation { + pub stake_key_hash: String, + pub pool_key_hash: String, + pub drep: DRep, + pub coin: u64, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CommitteeHotAuth { + pub committee_cold_key_hash: String, + pub committee_hot_key_hash: String, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CommitteeColdResign { + pub committee_cold_key_hash: String, + pub anchor: Option, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Anchor { + anchor_url: String, + anchor_data_hash: String, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DRepRegistration { + voting_key_hash: String, + coin: u64, + anchor: Option, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DRepDeregistration { + voting_key_hash: String, + coin: u64, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DRepUpdate { + voting_key_hash: String, + anchor: Option, +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Datum { From f55c4879f13e79044bd44730cd3f81d976de96e9 Mon Sep 17 00:00:00 2001 From: twwu123 Date: Sun, 23 Jun 2024 21:14:19 +0800 Subject: [PATCH 2/4] implement government actions on mesh csl --- packages/sidan-csl-rs/src/builder/core.rs | 41 ++- packages/sidan-csl-rs/src/core/builder.rs | 244 +++++++++++++++++- .../src/core/utils/certificates.rs | 25 ++ packages/sidan-csl-rs/src/core/utils/mod.rs | 2 + packages/sidan-csl-rs/src/model/mod.rs | 18 +- 5 files changed, 316 insertions(+), 14 deletions(-) create mode 100644 packages/sidan-csl-rs/src/core/utils/certificates.rs diff --git a/packages/sidan-csl-rs/src/builder/core.rs b/packages/sidan-csl-rs/src/builder/core.rs index f39dda7..87cf361 100644 --- a/packages/sidan-csl-rs/src/builder/core.rs +++ b/packages/sidan-csl-rs/src/builder/core.rs @@ -273,8 +273,45 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { Certificate::RetirePool(retire_pool) => { mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool)? } - _ => { - // TODO: implement government actions + Certificate::VoteDelegation(vote_delegation) => { + mesh_csl.add_vote_delegation_cert(&mut certificates_builder, vote_delegation)? + } + Certificate::StakeAndVoteDelegation(stake_and_vote_delegation) => mesh_csl + .add_stake_and_vote_delegation_cert( + &mut certificates_builder, + stake_and_vote_delegation, + )?, + Certificate::StakeRegistrationAndDelegation(stake_registration_and_delegation) => { + mesh_csl.add_stake_registration_and_delegation_cert( + &mut certificates_builder, + stake_registration_and_delegation, + )? + } + Certificate::VoteRegistrationAndDelegation(vote_registration_and_delegation) => { + mesh_csl.add_vote_registration_and_delgation_cert( + &mut certificates_builder, + vote_registration_and_delegation, + )? + } + Certificate::StakeVoteRegistrationAndDelegation( + stake_vote_registration_and_delegation, + ) => mesh_csl.add_stake_vote_registration_and_delegation_cert( + &mut certificates_builder, + stake_vote_registration_and_delegation, + )?, + Certificate::CommitteeHotAuth(committee_hot_auth) => mesh_csl + .add_committee_hot_auth_cert(&mut certificates_builder, committee_hot_auth)?, + Certificate::CommitteeColdResign(commitee_cold_resign) => mesh_csl + .add_commitee_cold_resign_cert( + &mut certificates_builder, + commitee_cold_resign, + )?, + Certificate::DRepRegistration(drep_registration) => mesh_csl + .add_drep_registration_cert(&mut certificates_builder, drep_registration)?, + Certificate::DRepDeregistration(drep_deregistration) => mesh_csl + .add_drep_deregistration_cert(&mut certificates_builder, drep_deregistration)?, + Certificate::DRepUpdate(drep_update) => { + mesh_csl.add_drep_update_cert(&mut certificates_builder, drep_update)? } } } diff --git a/packages/sidan-csl-rs/src/core/builder.rs b/packages/sidan-csl-rs/src/core/builder.rs index eebcf9f..0739eb7 100644 --- a/packages/sidan-csl-rs/src/core/builder.rs +++ b/packages/sidan-csl-rs/src/core/builder.rs @@ -1,10 +1,11 @@ use std::net::{Ipv4Addr, Ipv6Addr}; -use cardano_serialization_lib::JsError; - use crate::{csl, model::*}; +use cardano_serialization_lib::{Credential, JsError}; -use super::{utils::build_tx_builder, utils::sign_transaction, utils::to_bignum, utils::to_value}; +use super::utils::{ + build_tx_builder, sign_transaction, to_bignum, to_csl_anchor, to_csl_drep, to_value, +}; pub trait IMeshCSL { fn new(params: Option) -> Self; @@ -55,6 +56,56 @@ pub trait IMeshCSL { certificates_builder: &mut csl::CertificatesBuilder, retire_pool: RetirePool, ) -> Result<(), JsError>; + fn add_vote_delegation_cert( + &mut self, + certificates_builder: &mut csl::CertificatesBuilder, + vote_delegation: VoteDelegation, + ) -> Result<(), JsError>; + fn add_stake_and_vote_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_and_vote_delegation: StakeAndVoteDelegation, + ) -> Result<(), JsError>; + fn add_stake_registration_and_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_registration_and_delegation: StakeRegistrationAndDelegation, + ) -> Result<(), JsError>; + fn add_vote_registration_and_delgation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + vote_registration_and_delgation: VoteRegistrationAndDelegation, + ) -> Result<(), JsError>; + fn add_stake_vote_registration_and_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_vote_registration_and_delegation: StakeVoteRegistrationAndDelegation, + ) -> Result<(), JsError>; + fn add_committee_hot_auth_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + committee_hot_auth: CommitteeHotAuth, + ) -> Result<(), JsError>; + fn add_commitee_cold_resign_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + committee_cold_resign: CommitteeColdResign, + ) -> Result<(), JsError>; + fn add_drep_registration_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_registration: DRepRegistration, + ) -> Result<(), JsError>; + fn add_drep_deregistration_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_deregistration: DRepDeregistration, + ) -> Result<(), JsError>; + fn add_drep_update_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_update: DRepUpdate, + ) -> Result<(), JsError>; fn add_invalid_before(&mut self, invalid_before: u64); fn add_invalid_hereafter(&mut self, invalid_hereafter: u64); fn add_change( @@ -525,6 +576,193 @@ impl IMeshCSL for MeshCSL { Ok(()) } + fn add_vote_delegation_cert( + &mut self, + certificates_builder: &mut csl::CertificatesBuilder, + vote_delegation: VoteDelegation, + ) -> Result<(), JsError> { + certificates_builder.add(&csl::Certificate::new_vote_delegation( + &csl::VoteDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &vote_delegation.stake_key_hash, + )?), + &to_csl_drep(&vote_delegation.drep)?, + ), + ))?; + Ok(()) + } + + fn add_stake_and_vote_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_and_vote_delegation: StakeAndVoteDelegation, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_stake_and_vote_delegation( + &csl::StakeAndVoteDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &stake_and_vote_delegation.stake_key_hash, + )?), + &csl::Ed25519KeyHash::from_hex(&stake_and_vote_delegation.pool_key_hash)?, + &to_csl_drep(&stake_and_vote_delegation.drep)?, + ), + ))?; + Ok(()) + } + + fn add_stake_registration_and_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_registration_and_delegation: StakeRegistrationAndDelegation, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_stake_registration_and_delegation( + &csl::StakeRegistrationAndDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &stake_registration_and_delegation.stake_key_hash, + )?), + &csl::Ed25519KeyHash::from_hex(&stake_registration_and_delegation.pool_key_hash)?, + &to_bignum(stake_registration_and_delegation.coin), + ), + ))?; + Ok(()) + } + + fn add_vote_registration_and_delgation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + vote_registration_and_delgation: VoteRegistrationAndDelegation, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_vote_registration_and_delegation( + &csl::VoteRegistrationAndDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &vote_registration_and_delgation.stake_key_hash, + )?), + &to_csl_drep(&vote_registration_and_delgation.drep)?, + &to_bignum(vote_registration_and_delgation.coin), + ), + ))?; + Ok(()) + } + + fn add_stake_vote_registration_and_delegation_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + stake_vote_registration_and_delegation: StakeVoteRegistrationAndDelegation, + ) -> Result<(), JsError> { + certificate_builder.add( + &csl::Certificate::new_stake_vote_registration_and_delegation( + &csl::StakeVoteRegistrationAndDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &stake_vote_registration_and_delegation.stake_key_hash, + )?), + &csl::Ed25519KeyHash::from_hex( + &stake_vote_registration_and_delegation.pool_key_hash, + )?, + &to_csl_drep(&stake_vote_registration_and_delegation.drep)?, + &to_bignum(stake_vote_registration_and_delegation.coin), + ), + ), + ) + } + + fn add_committee_hot_auth_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + committee_hot_auth: CommitteeHotAuth, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_committee_hot_auth( + &csl::CommitteeHotAuth::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &committee_hot_auth.committee_cold_key_hash, + )?), + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &committee_hot_auth.committee_hot_key_hash, + )?), + ), + ))?; + Ok(()) + } + + fn add_commitee_cold_resign_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + committee_cold_resign: CommitteeColdResign, + ) -> Result<(), JsError> { + let committee_cold_key = &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &committee_cold_resign.committee_cold_key_hash, + )?); + match committee_cold_resign.anchor { + Some(anchor) => { + certificate_builder.add(&csl::Certificate::new_committee_cold_resign( + &csl::CommitteeColdResign::new_with_anchor( + committee_cold_key, + &to_csl_anchor(&anchor)?, + ), + ))?; + } + None => { + certificate_builder.add(&csl::Certificate::new_committee_cold_resign( + &csl::CommitteeColdResign::new(committee_cold_key), + ))?; + } + } + Ok(()) + } + + fn add_drep_registration_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_registration: DRepRegistration, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_drep_registration( + &csl::DrepRegistration::new( + &Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &drep_registration.voting_key_hash, + )?), + &to_bignum(drep_registration.coin), + ), + ))?; + Ok(()) + } + + fn add_drep_deregistration_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_deregistration: DRepDeregistration, + ) -> Result<(), JsError> { + certificate_builder.add(&csl::Certificate::new_drep_deregistration( + &csl::DrepDeregistration::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &drep_deregistration.voting_key_hash, + )?), + &to_bignum(drep_deregistration.coin), + ), + ))?; + Ok(()) + } + + fn add_drep_update_cert( + &mut self, + certificate_builder: &mut csl::CertificatesBuilder, + drep_update: DRepUpdate, + ) -> Result<(), JsError> { + match drep_update.anchor { + Some(anchor) => certificate_builder.add(&csl::Certificate::new_drep_update( + &csl::DrepUpdate::new_with_anchor( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &drep_update.voting_key_hash, + )?), + &to_csl_anchor(&anchor)?, + ), + )), + None => certificate_builder.add(&csl::Certificate::new_drep_update( + &csl::DrepUpdate::new(&csl::Credential::from_keyhash( + &csl::Ed25519KeyHash::from_hex(&drep_update.voting_key_hash)?, + )), + )), + }?; + Ok(()) + } + fn add_invalid_before(&mut self, invalid_before: u64) { self.tx_builder .set_validity_start_interval_bignum(to_bignum(invalid_before)); diff --git a/packages/sidan-csl-rs/src/core/utils/certificates.rs b/packages/sidan-csl-rs/src/core/utils/certificates.rs new file mode 100644 index 0000000..56b0af8 --- /dev/null +++ b/packages/sidan-csl-rs/src/core/utils/certificates.rs @@ -0,0 +1,25 @@ +use cardano_serialization_lib as csl; +use csl::JsError; +use model::{Anchor, DRep}; + +use crate::*; + +pub fn to_csl_drep(drep: &DRep) -> Result { + match drep { + DRep::KeyHash(key_hash) => Ok(csl::DRep::new_key_hash(&csl::Ed25519KeyHash::from_hex( + &key_hash, + )?)), + DRep::ScriptHash(script_hash) => Ok(csl::DRep::new_script_hash( + &csl::ScriptHash::from_hex(&script_hash)?, + )), + DRep::AlwaysAbstain => Ok(csl::DRep::new_always_abstain()), + DRep::AlwaysNoConfidence => Ok(csl::DRep::new_always_no_confidence()), + } +} + +pub fn to_csl_anchor(anchor: &Anchor) -> Result { + Ok(csl::Anchor::new( + &csl::URL::new(anchor.anchor_url.clone())?, + &csl::AnchorDataHash::from_hex(&anchor.anchor_data_hash)?, + )) +} diff --git a/packages/sidan-csl-rs/src/core/utils/mod.rs b/packages/sidan-csl-rs/src/core/utils/mod.rs index e6f1d6a..5cb98b5 100644 --- a/packages/sidan-csl-rs/src/core/utils/mod.rs +++ b/packages/sidan-csl-rs/src/core/utils/mod.rs @@ -1,11 +1,13 @@ mod address; mod aiken; +mod certificates; mod script; mod transaction; mod ungroup; pub use address::*; pub use aiken::*; +pub use certificates::*; pub use script::*; pub use transaction::*; pub use ungroup::*; diff --git a/packages/sidan-csl-rs/src/model/mod.rs b/packages/sidan-csl-rs/src/model/mod.rs index 7839d66..e07c8e0 100644 --- a/packages/sidan-csl-rs/src/model/mod.rs +++ b/packages/sidan-csl-rs/src/model/mod.rs @@ -376,30 +376,30 @@ pub struct CommitteeColdResign { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Anchor { - anchor_url: String, - anchor_data_hash: String, + pub anchor_url: String, + pub anchor_data_hash: String, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DRepRegistration { - voting_key_hash: String, - coin: u64, - anchor: Option, + pub voting_key_hash: String, + pub coin: u64, + pub anchor: Option, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DRepDeregistration { - voting_key_hash: String, - coin: u64, + pub voting_key_hash: String, + pub coin: u64, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct DRepUpdate { - voting_key_hash: String, - anchor: Option, + pub voting_key_hash: String, + pub anchor: Option, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] From b83424c54c3c5d26544325fa46b27f273268ef1d Mon Sep 17 00:00:00 2001 From: twwu123 Date: Mon, 24 Jun 2024 12:16:16 +0800 Subject: [PATCH 3/4] add methods to build government actions on mesh tx builder body --- packages/whisky/src/builder/core.rs | 163 +++++++++++++++++++- packages/whisky/src/builder/interface.rs | 184 ++++++++++++++++++++++- 2 files changed, 340 insertions(+), 7 deletions(-) diff --git a/packages/whisky/src/builder/core.rs b/packages/whisky/src/builder/core.rs index 91fb7e7..89fde2a 100644 --- a/packages/whisky/src/builder/core.rs +++ b/packages/whisky/src/builder/core.rs @@ -5,11 +5,15 @@ use sidan_csl_rs::{ core::{algo::select_utxos, builder::IMeshCSL, utils::build_tx_builder}, csl, model::{ - Asset, Certificate, Datum, DatumSource, DelegateStake, DeregisterStake, InlineDatumSource, - InlineScriptSource, LanguageVersion, MeshTxBuilderBody, Metadata, MintItem, Output, - PlutusScriptWithdrawal, PoolParams, ProvidedDatumSource, ProvidedScriptSource, PubKeyTxIn, - PubKeyWithdrawal, Redeemer, RefTxIn, RegisterPool, RegisterStake, RetirePool, ScriptSource, - ScriptTxIn, ScriptTxInParameter, TxIn, TxInParameter, UTxO, Value, Withdrawal, + Anchor, Asset, Certificate, CommitteeColdResign, CommitteeHotAuth, DRep, + DRepDeregistration, DRepRegistration, DRepUpdate, Datum, DatumSource, DelegateStake, + DeregisterStake, InlineDatumSource, InlineScriptSource, LanguageVersion, MeshTxBuilderBody, + Metadata, MintItem, Output, PlutusScriptWithdrawal, PoolParams, ProvidedDatumSource, + ProvidedScriptSource, PubKeyTxIn, PubKeyWithdrawal, Redeemer, RefTxIn, RegisterPool, + RegisterStake, RetirePool, ScriptSource, ScriptTxIn, ScriptTxInParameter, + StakeAndVoteDelegation, StakeRegistrationAndDelegation, StakeVoteRegistrationAndDelegation, + TxIn, TxInParameter, UTxO, Value, VoteDelegation, VoteRegistrationAndDelegation, + Withdrawal, }, }; @@ -632,6 +636,155 @@ impl IMeshTxBuilder for MeshTxBuilder { self } + fn vote_delegation_certificate(&mut self, stake_key_hash: &str, drep: DRep) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::VoteDelegation(VoteDelegation { + stake_key_hash: stake_key_hash.to_string(), + drep, + })); + self + } + + fn stake_and_vote_delegation_certificate( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + drep: DRep, + ) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::StakeAndVoteDelegation( + StakeAndVoteDelegation { + stake_key_hash: stake_key_hash.to_string(), + pool_key_hash: pool_key_hash.to_string(), + drep, + }, + )); + self + } + + fn stake_registration_and_delegation( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + coin: u64, + ) -> &mut Self { + self.core.mesh_tx_builder_body.certificates.push( + Certificate::StakeRegistrationAndDelegation(StakeRegistrationAndDelegation { + stake_key_hash: stake_key_hash.to_string(), + pool_key_hash: pool_key_hash.to_string(), + coin, + }), + ); + self + } + + fn vote_registration_and_delegation( + &mut self, + stake_key_hash: &str, + drep: DRep, + coin: u64, + ) -> &mut Self { + self.core.mesh_tx_builder_body.certificates.push( + Certificate::VoteRegistrationAndDelegation(VoteRegistrationAndDelegation { + stake_key_hash: stake_key_hash.to_string(), + drep, + coin, + }), + ); + self + } + + fn stake_vote_registration_and_delegation( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + drep: DRep, + coin: u64, + ) -> &mut Self { + self.core.mesh_tx_builder_body.certificates.push( + Certificate::StakeVoteRegistrationAndDelegation(StakeVoteRegistrationAndDelegation { + stake_key_hash: stake_key_hash.to_string(), + pool_key_hash: pool_key_hash.to_string(), + drep, + coin, + }), + ); + self + } + + fn committee_hot_auth( + &mut self, + committee_cold_key_hash: &str, + committee_hot_key_hash: &str, + ) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::CommitteeHotAuth(CommitteeHotAuth { + committee_cold_key_hash: committee_cold_key_hash.to_string(), + committee_hot_key_hash: committee_hot_key_hash.to_string(), + })); + self + } + + fn commitee_cold_resign( + &mut self, + committee_cold_key_hash: &str, + anchor: Option, + ) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::CommitteeColdResign(CommitteeColdResign { + committee_cold_key_hash: committee_cold_key_hash.to_string(), + anchor, + })); + self + } + + fn drep_registration( + &mut self, + voting_key_hash: &str, + coin: u64, + anchor: Option, + ) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::DRepRegistration(DRepRegistration { + voting_key_hash: voting_key_hash.to_string(), + coin, + anchor, + })); + self + } + + fn drep_deregistration(&mut self, voting_key_hash: &str, coin: u64) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::DRepDeregistration(DRepDeregistration { + voting_key_hash: voting_key_hash.to_string(), + coin, + })); + self + } + + fn drep_update(&mut self, voting_key_hash: &str, anchor: Option) -> &mut Self { + self.core + .mesh_tx_builder_body + .certificates + .push(Certificate::DRepUpdate(DRepUpdate { + voting_key_hash: voting_key_hash.to_string(), + anchor, + })); + self + } + fn change_address(&mut self, address: &str) -> &mut Self { self.core.mesh_tx_builder_body.change_address = address.to_string(); self diff --git a/packages/whisky/src/builder/interface.rs b/packages/whisky/src/builder/interface.rs index 0a5d515..c0de628 100644 --- a/packages/whisky/src/builder/interface.rs +++ b/packages/whisky/src/builder/interface.rs @@ -3,8 +3,8 @@ use cardano_serialization_lib::JsError; use sidan_csl_rs::{ builder::MeshTxBuilderCore, model::{ - Asset, LanguageVersion, MeshTxBuilderBody, MintItem, Output, PoolParams, Protocol, - PubKeyTxIn, Redeemer, TxIn, UTxO, Withdrawal, + Anchor, Asset, DRep, LanguageVersion, MeshTxBuilderBody, MintItem, Output, PoolParams, + Protocol, PubKeyTxIn, Redeemer, TxIn, UTxO, Withdrawal, }, }; @@ -583,6 +583,186 @@ pub trait IMeshTxBuilder { /// * `Self` - The MeshTxBuilder instance fn retire_pool_certificate(&mut self, pool_id: &str, epoch: u32) -> &mut Self; + /// ## Transaction building method + /// + /// Add a vote delegation certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `stake_key_hash` - Hash of the stake key + /// * `drep` - The drep that will be voted for, or always abstain / always no confidence + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn vote_delegation_certificate(&mut self, stake_key_hash: &str, drep: DRep) -> &mut Self; + + /// ## Transaction building method + /// + /// Add a stake and vote delegation certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `stake_key_hash` - Hash of the stake key + /// * `pool_key_hash` - Hash of pool key that will be delegated to, same as pool id + /// * `drep` - The drep that will be voted for, or always abstain / always no confidence + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn stake_and_vote_delegation_certificate( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + drep: DRep, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add a stake registration and delegation certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `stake_key_hash` - Hash of the stake key + /// * `pool_key_hash` - Hash of pool key that will be delegated to, same as pool id + /// * `coin` - Deposit for certificate registration + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn stake_registration_and_delegation( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + coin: u64, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add a vote registration and delegation certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `stake_key_hash` - Hash of the stake key + /// * `drep` - The drep that will be voted for, or always abstain / always no confidence + /// * `coin` - Deposit for certificate registration + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn vote_registration_and_delegation( + &mut self, + stake_key_hash: &str, + drep: DRep, + coin: u64, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add a stake vote registration and delegation certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `stake_key_hash` - Hash of the stake key + /// * `pool_key_hash` - Hash of pool key that will be delegated to, same as pool id + /// * `drep` - The drep that will be voted for, or always abstain / always no confidence + /// * `coin` - Deposit for certificate registration + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn stake_vote_registration_and_delegation( + &mut self, + stake_key_hash: &str, + pool_key_hash: &str, + drep: DRep, + coin: u64, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add commitee hot auth certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `committee_cold_key_hash` - Hash of the committee cold key + /// * `committee_hot_key_hash` - Hash of the commitee hot key + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn committee_hot_auth( + &mut self, + committee_cold_key_hash: &str, + committee_hot_key_hash: &str, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add commitee cold resign certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `committee_cold_key_hash` - Hash of the committee cold key + /// * `anchor` - The Anchor, this is a URL and a hash of the doc at this URL + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn commitee_cold_resign( + &mut self, + committee_cold_key_hash: &str, + anchor: Option, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add DRep registration certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `voting_key_hash` - Hash of the voting key + /// * `coin` - Deposit for certificate registration + /// * `anchor` - The Anchor, this is a URL and a hash of the doc at this URL + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn drep_registration( + &mut self, + voting_key_hash: &str, + coin: u64, + anchor: Option, + ) -> &mut Self; + + /// ## Transaction building method + /// + /// Add DRep deregistration certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `voting_key_hash` - Hash of the voting key + /// * `coin` - Deposit for certificate registration + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn drep_deregistration(&mut self, voting_key_hash: &str, coin: u64) -> &mut Self; + + /// ## Transaction building method + /// + /// Add DRep update certificate to the MeshTxBuilder instance + /// + /// ### Arguments + /// + /// * `voting_key_hash` - Hash of the voting key + /// * `anchor` - The Anchor, this is a URL and a hash of the doc at this URL + /// + /// ### Returns + /// + /// * `Self` - The MeshTxBuilder instance + fn drep_update(&mut self, voting_key_hash: &str, anchor: Option) -> &mut Self; + /// ## Transaction building method /// /// Change the address in the MeshTxBuilder instance From 2bb732a4bb2ba7d12a28e2951ae0d311dca0029c Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Mon, 24 Jun 2024 14:41:53 +0800 Subject: [PATCH 4/4] feat: bumping ver --- packages/Cargo.lock | 4 ++-- packages/sidan-csl-rs/Cargo.toml | 2 +- packages/whisky/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/Cargo.lock b/packages/Cargo.lock index 331d7d4..068dbec 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -1184,7 +1184,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.5.5" +version = "0.5.6" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -1487,7 +1487,7 @@ dependencies = [ [[package]] name = "whisky" -version = "0.5.5" +version = "0.5.6" dependencies = [ "async-trait", "cardano-serialization-lib", diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index 1403e3b..f82f6ca 100644 --- a/packages/sidan-csl-rs/Cargo.toml +++ b/packages/sidan-csl-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.5.5" +version = "0.5.6" edition = "2021" license = "Apache-2.0" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs" diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index 317e4b5..d0dedf5 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky" -version = "0.5.5" +version = "0.5.6" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -24,7 +24,7 @@ noop_proc_macro = "0.3.0" pallas-codec = "0.22.0" pallas-primitives = "0.22.0" pallas-traverse = "0.22.0" -sidan-csl-rs = { version = "=0.5.5", path = "../sidan-csl-rs" } +sidan-csl-rs = { version = "=0.5.6", path = "../sidan-csl-rs" } [profile.release] # Tell `rustc` to optimize for small code size.