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

feat: adding script stake key to parse #34

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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.2"
version = "0.5.3"
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
42 changes: 34 additions & 8 deletions packages/sidan-csl-rs/src/core/utils/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ pub fn serialize_bech32_address(bech32_addr: String) -> SerializedAddress {
.to_keyhash()
.map(|stake_key_hash| stake_key_hash.to_hex());

let csl_stake_key_script_hash = address
.stake_cred()
.to_scripthash()
.map(|stake_key_script_hash| stake_key_script_hash.to_hex());

SerializedAddress::new(
csl_key_hash.unwrap_or("".to_string()),
csl_script_hash.unwrap_or("".to_string()),
csl_stake_key_hash.unwrap_or("".to_string()),
csl_stake_key_script_hash.unwrap_or("".to_string()),
)
}
None => {
Expand All @@ -75,6 +81,7 @@ pub fn serialize_bech32_address(bech32_addr: String) -> SerializedAddress {
csl_key_hash.unwrap_or("".to_string()),
csl_script_hash.unwrap_or("".to_string()),
"".to_string(),
"".to_string(),
)
}
}
Expand Down Expand Up @@ -115,14 +122,33 @@ pub fn parse_plutus_address_obj_to_bech32(plutus_data_address_obj: &str, network
["bytes"]
.as_str()
.unwrap();
csl::BaseAddress::new(
network_id,
&csl_payment_credential,
&csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex(stake_key_hash).unwrap()),
)
.to_address()
.to_bech32(None)
.unwrap()
if plutus_data_stake_key_obj["fields"][0]["fields"][0]["constructor"]
.as_u64()
.unwrap()
== 0
{
csl::BaseAddress::new(
network_id,
&csl_payment_credential,
&csl::Credential::from_keyhash(
&csl::Ed25519KeyHash::from_hex(stake_key_hash).unwrap(),
),
)
.to_address()
.to_bech32(None)
.unwrap()
} else {
csl::BaseAddress::new(
network_id,
&csl_payment_credential,
&csl::Credential::from_scripthash(
&csl::ScriptHash::from_hex(stake_key_hash).unwrap(),
),
)
.to_address()
.to_bech32(None)
.unwrap()
}
} else {
csl::EnterpriseAddress::new(network_id, &csl_payment_credential)
.to_address()
Expand Down
13 changes: 12 additions & 1 deletion packages/sidan-csl-rs/src/model/serialized_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ pub struct SerializedAddress {
pub_key_hash: String,
script_hash: String,
stake_key_hash: String,
stake_key_script_hash: String,
}

#[wasm_bindgen]
impl SerializedAddress {
pub fn new(pub_key_hash: String, script_hash: String, stake_key_hash: String) -> Self {
pub fn new(
pub_key_hash: String,
script_hash: String,
stake_key_hash: String,
stake_key_script_hash: String,
) -> Self {
Self {
pub_key_hash,
script_hash,
stake_key_hash,
stake_key_script_hash,
}
}

Expand All @@ -29,4 +36,8 @@ impl SerializedAddress {
pub fn get_stake_key_hash(&self) -> String {
self.stake_key_hash.clone()
}

pub fn get_stake_key_script_hash(&self) -> String {
self.stake_key_script_hash.clone()
}
}
24 changes: 20 additions & 4 deletions packages/sidan-csl-rs/tests/address_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ mod address_tests {
== SerializedAddress::new(
"8f2ac4b2a57a90feb7717c7361c7043af6c3646e9db2b0e616482f73".to_string(),
"".to_string(),
"039506b8e57e150bb66f6134f3264d50c3b70ce44d052f4485cf388f".to_string()
"039506b8e57e150bb66f6134f3264d50c3b70ce44d052f4485cf388f".to_string(),
"".to_string(),
)
);

Expand All @@ -42,7 +43,8 @@ mod address_tests {
== SerializedAddress::new(
"".to_string(),
"25b86eea84a44a3cf98bf470e2dafa02a8d95b81028c51583610297e".to_string(),
"5ca749261aa3b17aa2cd4b026bc6566c4b14421d6083edce64ffe5cb".to_string()
"5ca749261aa3b17aa2cd4b026bc6566c4b14421d6083edce64ffe5cb".to_string(),
"".to_string(),
)
);

Expand All @@ -53,6 +55,7 @@ mod address_tests {
== SerializedAddress::new(
"5ca51b304b1f79d92eada8c58c513e969458dcd27ce4f5bc47823ffa".to_string(),
"".to_string(),
"".to_string(),
"".to_string()
)
);
Expand All @@ -64,8 +67,21 @@ mod address_tests {
== SerializedAddress::new(
"36314aebecfbc929ee447dcb50fd690604eceae9403a298d9b1f9a54".to_string(),
"".to_string(),
"75531fbe1e68b11e9a10dbbc5df889edea92325a85b758bbbf8735d9".to_string()
"75531fbe1e68b11e9a10dbbc5df889edea92325a85b758bbbf8735d9".to_string(),
"".to_string()
)
);

let addr5 = "addr_test1xrqjazgu36v4e7jaz4r6eccyz09d9xyz0gvlhw82fx6xg6vx0j94wtj6ercvzj48g97tnjhvn50l2r5efamja2edd86ql04h5v";
let addr5_result = serialize_bech32_address(addr5.to_string());
assert!(
addr5_result
== SerializedAddress::new(
"".to_string(),
"c12e891c8e995cfa5d1547ace30413cad298827a19fbb8ea49b46469".to_string(),
"".to_string(),
"867c8b572e5ac8f0c14aa7417cb9caec9d1ff50e994f772eab2d69f4".to_string()
)
)
);
}
}
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.5.2"
version = "0.5.3"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -24,7 +24,7 @@ noop_proc_macro = "0.3.0"
pallas-codec = "0.22.0"
pallas-primitives = "0.22.0"
pallas-traverse = "0.22.0"
sidan-csl-rs = { version = "=0.5.2", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.5.3", path = "../sidan-csl-rs" }

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
Loading