Skip to content

Commit

Permalink
Feature/vote delegation (#87)
Browse files Browse the repository at this point in the history
* update drep to use drep_id

* add vote delegation test

* bump ver
  • Loading branch information
twwu123 authored Sep 12, 2024
1 parent ec78ae9 commit e4cdc8d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 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.4"
version = "0.8.5"
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.4"
version = "0.8.5"
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
2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/json-gen/Cargo.lock

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

7 changes: 1 addition & 6 deletions packages/sidan-csl-rs/src/core/utils/certificates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ use super::to_bignum;

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::DRepId(drep_id) => Ok(csl::DRep::from_bech32(&drep_id)?),
DRep::AlwaysAbstain => Ok(csl::DRep::new_always_abstain()),
DRep::AlwaysNoConfidence => Ok(csl::DRep::new_always_no_confidence()),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ pub struct VoteDelegation {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum DRep {
KeyHash(String),
ScriptHash(String),
DRepId(String),
AlwaysAbstain,
AlwaysNoConfidence,
}
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.4"
version = "0.8.5"
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.4", path = "../whisky" }
whisky = { version = "=0.8.5", 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.4"
version = "0.8.5"
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.4", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.8.5", path = "../sidan-csl-rs" }
reqwest = "0.12.5"
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }

Expand Down
29 changes: 28 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,
core::utils::merge_vkey_witnesses_to_transaction, model::{Anchor, DRep},
};

#[test]
Expand Down Expand Up @@ -524,4 +524,31 @@ mod int_tests {

println!("{}", unsigned_tx);
}

#[test]
fn test_vote_delegation() {
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_delegation_certificate("stake_test1uzdx8vwxvz5wy45fwdrwk2l85ax7j5wtr4cee6a8xc632cc3p6psh", &DRep::DRepId("drep1j6257gz2swty9ut46lspyvujkt02pd82am2zq97p7p9pv2euzs7".to_string()))
.complete_sync(None)
.unwrap()
.complete_signing()
.unwrap();

println!("{}", unsigned_tx);
}
}

0 comments on commit e4cdc8d

Please sign in to comment.