Skip to content

Commit

Permalink
Merge pull request #31 from sidan-lab/feature/staking
Browse files Browse the repository at this point in the history
Feature/staking
  • Loading branch information
HinsonSIDAN authored Jun 12, 2024
2 parents c495159 + 6b8ed00 commit 533eba5
Show file tree
Hide file tree
Showing 12 changed files with 897 additions and 50 deletions.
4 changes: 2 additions & 2 deletions packages/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sidan-csl-rs"
version = "0.5.1"
version = "0.5.2"
edition = "2021"
license = "Apache-2.0"
description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs"
Expand Down
47 changes: 47 additions & 0 deletions packages/sidan-csl-rs/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ pub fn serialize_tx_body(
&mut mesh_csl,
mesh_tx_builder_body.reference_inputs.clone(),
);
MeshTxBuilderCore::add_all_withdrawals(&mut mesh_csl, mesh_tx_builder_body.withdrawals.clone());
MeshTxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone());
MeshTxBuilderCore::add_all_certificates(
&mut mesh_csl,
mesh_tx_builder_body.certificates.clone(),
);
MeshTxBuilderCore::add_validity_range(
&mut mesh_csl,
mesh_tx_builder_body.validity_range.clone(),
Expand Down Expand Up @@ -138,9 +143,11 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
collaterals: vec![],
required_signatures: JsVecString::new(),
reference_inputs: vec![],
withdrawals: vec![],
mints: vec![],
change_address: "".to_string(),
change_datum: None,
certificates: vec![],
metadata: vec![],
validity_range: ValidityRange {
invalid_before: None,
Expand Down Expand Up @@ -194,6 +201,22 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
}
}

fn add_all_withdrawals(mesh_csl: &mut MeshCSL, withdrawals: Vec<Withdrawal>) {
for withdrawal in withdrawals {
match withdrawal {
Withdrawal::PubKeyWithdrawal(pub_key_withdrawal) => {
mesh_csl.add_pub_key_withdrawal(pub_key_withdrawal)
}
Withdrawal::PlutusScriptWithdrawal(plutus_script_withdrawal) => {
mesh_csl.add_plutus_withdrawal(plutus_script_withdrawal)
}
}
}
mesh_csl
.tx_builder
.set_withdrawals_builder(&mesh_csl.tx_withdrawals_builder);
}

fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec<MintItem>) {
let mut mint_builder = csl::MintBuilder::new();
for (index, mint) in mints.into_iter().enumerate() {
Expand All @@ -206,6 +229,30 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
mesh_csl.tx_builder.set_mint_builder(&mint_builder)
}

fn add_all_certificates(mesh_csl: &mut MeshCSL, certificates: Vec<Certificate>) {
let mut certificates_builder = csl::CertificatesBuilder::new();
for cert in certificates {
match cert {
Certificate::RegisterPool(register_pool) => {
mesh_csl.add_register_pool_cert(&mut certificates_builder, register_pool)
}
Certificate::RegisterStake(register_stake) => {
mesh_csl.add_register_stake_cert(&mut certificates_builder, register_stake)
}
Certificate::DelegateStake(delegate_stake) => {
mesh_csl.add_delegate_stake_cert(&mut certificates_builder, delegate_stake)
}
Certificate::DeregisterStake(deregister_stake) => {
mesh_csl.add_deregister_stake_cert(&mut certificates_builder, deregister_stake)
}
Certificate::RetirePool(retire_pool) => {
mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool)
}
}
}
mesh_csl.tx_builder.set_certs_builder(&certificates_builder)
}

fn add_validity_range(mesh_csl: &mut MeshCSL, validity_range: ValidityRange) {
if validity_range.invalid_before.is_some() {
mesh_csl.add_invalid_before(validity_range.invalid_before.unwrap())
Expand Down
20 changes: 20 additions & 0 deletions packages/sidan-csl-rs/src/builder/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ pub trait IMeshTxBuilderCore {
/// * `ref_inputs` - A vector of reference inputs
fn add_all_reference_inputs(mesh_csl: &mut MeshCSL, ref_inputs: Vec<RefTxIn>);

/// ## Internal method
///
/// Add multiple withdrawals to the MeshTxBuilder instance
///
/// ## Arguments
///
/// * `mesh_csl` - The MeshCSL instance
/// * `withdrawals` - A vector of withdrawals
fn add_all_withdrawals(mesh_csl: &mut MeshCSL, withdrawals: Vec<Withdrawal>);

/// ## Internal method
///
/// Add multiple mints to the MeshTxBuilder instance
Expand All @@ -86,6 +96,16 @@ pub trait IMeshTxBuilderCore {
/// * `mints` - A vector of mints
fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec<MintItem>);

/// ## Internal method
///
/// Add multiple certificates to the MeshTxBuilder instance
///
/// ### Arguments
///
/// * `mesh_csl` - The MeshCSL instance
/// * `certificates` - A vector of certificates
fn add_all_certificates(mesh_csl: &mut MeshCSL, certificates: Vec<Certificate>);

/// ## Internal method
///
/// Add a validity range to the MeshTxBuilder instance
Expand Down
Loading

0 comments on commit 533eba5

Please sign in to comment.