Skip to content

Commit

Permalink
Merge pull request #91 from sidan-lab/feature-update/cc-vote
Browse files Browse the repository at this point in the history
Feature update/cc vote
  • Loading branch information
twwu123 authored Oct 7, 2024
2 parents 6b2efbb + 98db61e commit 10fecf5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 20 deletions.
6 changes: 3 additions & 3 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/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
version = "0.8.6"
version = "0.8.7"
resolver = "2"
members = [
"sidan-csl-rs",
Expand Down
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.8.6"
version = "0.8.7"
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
21 changes: 13 additions & 8 deletions packages/sidan-csl-rs/src/core/utils/vote.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use cardano_serialization_lib::{self as csl, JsError};

use crate::model::{VoteKind, Voter};
use crate::model::{Credential, VoteKind, Voter};

pub fn to_csl_voter(voter: Voter) -> Result<csl::Voter, JsError> {
match voter {
Voter::ConstitutionalCommitteeHotAddress(reward_address) => {
Ok(csl::Voter::new_constitutional_committee_hot_credential(
&csl::RewardAddress::from_address(&csl::Address::from_bech32(&reward_address)?)
.unwrap()
.payment_cred(),
))
}
Voter::ConstitutionalCommitteeHotCred(cred) => match cred {
Credential::KeyHash(key_hash) => {
Ok(csl::Voter::new_constitutional_committee_hot_credential(
&csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex(&key_hash)?),
))
}
Credential::ScriptHash(script_hash) => {
Ok(csl::Voter::new_constitutional_committee_hot_credential(
&csl::Credential::from_scripthash(&csl::ScriptHash::from_hex(&script_hash)?),
))
}
},
Voter::DRepId(drep_id) => {
let drep = csl::DRep::from_bech32(&drep_id).unwrap();
let drep_credential = if drep.to_script_hash().is_some() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Credential {
ScriptHash(String),
KeyHash(String),
}
2 changes: 2 additions & 0 deletions packages/sidan-csl-rs/src/model/tx_builder_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod certificate;
mod credential;
mod datum;
mod metadata;
mod mint;
Expand All @@ -14,6 +15,7 @@ mod vote;
mod withdrawal;

pub use certificate::*;
pub use credential::*;
pub use datum::*;
pub use metadata::*;
pub use mint::*;
Expand Down
4 changes: 2 additions & 2 deletions packages/sidan-csl-rs/src/model/tx_builder_types/vote.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use super::{Anchor, Redeemer, RefTxIn, ScriptSource, SimpleScriptSource};
use super::{Anchor, Credential, Redeemer, RefTxIn, ScriptSource, SimpleScriptSource};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct VoteType {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Voter {
ConstitutionalCommitteeHotAddress(String),
ConstitutionalCommitteeHotCred(Credential),
DRepId(String),
StakingPoolKeyHash(String),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/whisky-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "whisky-examples"
version = "0.8.6"
version = "0.8.7"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -13,4 +13,4 @@ path = "src/server.rs"
actix-cors = "0.7.0"
actix-web = "4.9.0"
serde = "1.0.209"
whisky = { version = "=0.8.6", path = "../whisky" }
whisky = { version = "=0.8.7", path = "../whisky" }
4 changes: 2 additions & 2 deletions packages/whisky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "whisky"
version = "0.8.6"
version = "0.8.7"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -24,7 +24,7 @@ pallas-codec = { version = "0.30.1", features = ["num-bigint"] }
pallas-primitives = "0.30.1"
pallas-traverse = "0.30.1"
maestro-rust-sdk = "1.1.3"
sidan-csl-rs = { version = "=0.8.6", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.8.7", path = "../sidan-csl-rs" }
reqwest = "0.12.5"
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }

Expand Down
41 changes: 40 additions & 1 deletion packages/whisky/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod int_tests {
};
use whisky::{
builder::{ TxBuilder, TxBuilderParam, WData::{self, JSON}, WRedeemer},
core::utils::merge_vkey_witnesses_to_transaction, model::{Anchor, DRep, RefTxIn, VoteKind, Voter, VotingProcedure},
core::utils::merge_vkey_witnesses_to_transaction, model::{Anchor, Credential, DRep, RefTxIn, VoteKind, Voter, VotingProcedure},
};

#[test]
Expand Down Expand Up @@ -523,6 +523,7 @@ mod int_tests {
.unwrap();

println!("{}", unsigned_tx);
assert!(mesh.core.mesh_csl.tx_hex != *"");
}

#[test]
Expand Down Expand Up @@ -550,6 +551,7 @@ mod int_tests {
.unwrap();

println!("{}", unsigned_tx);
assert!(mesh.core.mesh_csl.tx_hex != *"");
}

#[test]
Expand Down Expand Up @@ -585,5 +587,42 @@ mod int_tests {
.unwrap();

println!("{}", unsigned_tx);
assert!(mesh.core.mesh_csl.tx_hex != *"");
}

#[test]
fn test_cc_vote() {
let mut mesh = TxBuilder::new(TxBuilderParam {
evaluator: None,
fetcher: None,
submitter: None,
params: None,
});

let unsigned_tx = mesh
.change_address("addr_test1qpsmz8q2xj43wg597pnpp0ffnlvr8fpfydff0wcsyzqyrxguk5v6wzdvfjyy8q5ysrh8wdxg9h0u4ncse4cxhd7qhqjqk8pse6")
.tx_in(
"2cb57168ee66b68bd04a0d595060b546edf30c04ae1031b883c9ac797967dd85",
3,
&[Asset::new_from_str("lovelace", "9891607895")],
"addr_test1vru4e2un2tq50q4rv6qzk7t8w34gjdtw3y2uzuqxzj0ldrqqactxh",
)
.vote(&Voter::ConstitutionalCommitteeHotCred(Credential::KeyHash("e3a4c41d67592a1b8d87c62e5c5d73f7e8db836171945412d13f40f8".to_string())), &RefTxIn {
tx_hash: "2cb57168ee66b68bd04a0d595060b546edf30c04ae1031b883c9ac797967dd85".to_string(),
tx_index: 2
}, &VotingProcedure {
vote_kind: VoteKind::Abstain,
anchor: Some(Anchor {
anchor_url: "https://raw.githubusercontent.com/HinsonSIDAN/cardano-drep/main/HinsonSIDAN.jsonld".to_string(),
anchor_data_hash: "2aef51273a566e529a2d5958d981d7f0b3c7224fc2853b6c4922e019657b5060".to_string()
})
})
.complete_sync(None)
.unwrap()
.complete_signing()
.unwrap();

println!("{}", unsigned_tx);
assert!(mesh.core.mesh_csl.tx_hex != *"");
}
}

0 comments on commit 10fecf5

Please sign in to comment.