Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/conway government actions #38

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/sidan-csl-rs/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,46 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
Certificate::RetirePool(retire_pool) => {
mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool)?
}
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)?
}
}
}
mesh_csl.tx_builder.set_certs_builder(&certificates_builder);
Expand Down
244 changes: 241 additions & 3 deletions packages/sidan-csl-rs/src/core/builder.rs
Original file line number Diff line number Diff line change
@@ -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<Protocol>) -> Self;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions packages/sidan-csl-rs/src/core/utils/certificates.rs
Original file line number Diff line number Diff line change
@@ -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<csl::DRep, JsError> {
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<csl::Anchor, JsError> {
Ok(csl::Anchor::new(
&csl::URL::new(anchor.anchor_url.clone())?,
&csl::AnchorDataHash::from_hex(&anchor.anchor_data_hash)?,
))
}
2 changes: 2 additions & 0 deletions packages/sidan-csl-rs/src/core/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Loading
Loading