diff --git a/packages/Cargo.lock b/packages/Cargo.lock index a53c41e..a2a42ba 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -2644,7 +2644,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.8.6" +version = "0.8.7" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -3258,7 +3258,7 @@ dependencies = [ [[package]] name = "whisky" -version = "0.8.6" +version = "0.8.7" dependencies = [ "async-trait", "cryptoxide", @@ -3283,7 +3283,7 @@ dependencies = [ [[package]] name = "whisky-examples" -version = "0.8.6" +version = "0.8.7" dependencies = [ "actix-cors", "actix-web", diff --git a/packages/Cargo.toml b/packages/Cargo.toml index c978ccb..5d4fe3a 100644 --- a/packages/Cargo.toml +++ b/packages/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -version = "0.8.6" +version = "0.8.7" resolver = "2" members = [ "sidan-csl-rs", diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index 97dbb61..af000e4 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.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" diff --git a/packages/sidan-csl-rs/src/core/utils/vote.rs b/packages/sidan-csl-rs/src/core/utils/vote.rs index 0122947..26f96fd 100644 --- a/packages/sidan-csl-rs/src/core/utils/vote.rs +++ b/packages/sidan-csl-rs/src/core/utils/vote.rs @@ -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 { 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() { diff --git a/packages/sidan-csl-rs/src/model/tx_builder_types/credential.rs b/packages/sidan-csl-rs/src/model/tx_builder_types/credential.rs new file mode 100644 index 0000000..1ff62e6 --- /dev/null +++ b/packages/sidan-csl-rs/src/model/tx_builder_types/credential.rs @@ -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), +} diff --git a/packages/sidan-csl-rs/src/model/tx_builder_types/mod.rs b/packages/sidan-csl-rs/src/model/tx_builder_types/mod.rs index 0eee3d2..22c44b7 100644 --- a/packages/sidan-csl-rs/src/model/tx_builder_types/mod.rs +++ b/packages/sidan-csl-rs/src/model/tx_builder_types/mod.rs @@ -1,4 +1,5 @@ mod certificate; +mod credential; mod datum; mod metadata; mod mint; @@ -14,6 +15,7 @@ mod vote; mod withdrawal; pub use certificate::*; +pub use credential::*; pub use datum::*; pub use metadata::*; pub use mint::*; diff --git a/packages/sidan-csl-rs/src/model/tx_builder_types/vote.rs b/packages/sidan-csl-rs/src/model/tx_builder_types/vote.rs index a59cfb1..43cb025 100644 --- a/packages/sidan-csl-rs/src/model/tx_builder_types/vote.rs +++ b/packages/sidan-csl-rs/src/model/tx_builder_types/vote.rs @@ -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")] @@ -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), } diff --git a/packages/whisky-examples/Cargo.toml b/packages/whisky-examples/Cargo.toml index cbb8e2b..358d62c 100644 --- a/packages/whisky-examples/Cargo.toml +++ b/packages/whisky-examples/Cargo.toml @@ -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" @@ -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" } diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index 456470f..7fb4a83 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -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" @@ -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"] } diff --git a/packages/whisky/tests/integration_tests.rs b/packages/whisky/tests/integration_tests.rs index 7be7b54..6925e2a 100644 --- a/packages/whisky/tests/integration_tests.rs +++ b/packages/whisky/tests/integration_tests.rs @@ -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] @@ -523,6 +523,7 @@ mod int_tests { .unwrap(); println!("{}", unsigned_tx); + assert!(mesh.core.mesh_csl.tx_hex != *""); } #[test] @@ -550,6 +551,7 @@ mod int_tests { .unwrap(); println!("{}", unsigned_tx); + assert!(mesh.core.mesh_csl.tx_hex != *""); } #[test] @@ -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 != *""); } }