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

V0.7.6 #77

Merged
merged 2 commits into from
Aug 30, 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
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/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.7.5"
version = "0.7.6"
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
5 changes: 5 additions & 0 deletions packages/sidan-csl-rs/src/core/core_csl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ impl MeshCSL {
output_builder =
output_builder.with_plutus_data(&csl::PlutusData::from_hex(&data)?);
}
Datum::Embedded(data) => {
let datum = &csl::PlutusData::from_hex(&data)?;
output_builder = output_builder.with_data_hash(&csl::hash_plutus_data(datum));
self.tx_builder.add_extra_witness_datum(datum);
}
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/sidan-csl-rs/src/core/tx_parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl MeshTxParser {
let plutus_data = Some(data);
(None, plutus_data)
}
Some(Datum::Embedded(data)) => {
let data_hash = Some(data);
(data_hash, None)
}
None => (None, None),
};
let tx_out_utxo: UTxO = UTxO {
Expand Down
12 changes: 9 additions & 3 deletions packages/sidan-csl-rs/src/core/utils/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ pub fn get_min_utxo_value(output: &Output, coins_per_utxo_size: &u64) -> Result<
tx_output_builder =
tx_output_builder.with_plutus_data(&csl::PlutusData::from_hex(str_data)?);
}
Datum::Hash(str_data_hash) => {
tx_output_builder =
tx_output_builder.with_data_hash(&csl::DataHash::from_hex(str_data_hash)?);
Datum::Hash(str_data) => {
tx_output_builder = tx_output_builder.with_data_hash(&csl::hash_plutus_data(
&csl::PlutusData::from_hex(&str_data)?,
));
}
Datum::Embedded(str_data) => {
tx_output_builder = tx_output_builder.with_data_hash(&csl::hash_plutus_data(
&csl::PlutusData::from_hex(&str_data)?,
));
}
},
None => {}
Expand Down
4 changes: 3 additions & 1 deletion packages/sidan-csl-rs/src/model/tx_builder_types/datum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use serde::{Deserialize, Serialize};
pub enum Datum {
Inline(String),
Hash(String),
Embedded(String),
}

impl Datum {
pub fn get_inner(&self) -> &str {
match self {
Datum::Inline(s) => s,
Datum::Hash(s) => s,
Datum::Embedded(s) => s,
}
}
}
}
4 changes: 2 additions & 2 deletions packages/whisky-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "whisky-examples"
version = "0.7.5"
version = "0.7.6"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"

[dependencies]
whisky = { version = "=0.7.5", path = "../whisky" }
whisky = { version = "=0.7.6", 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.7.5"
version = "0.7.6"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -24,7 +24,7 @@ pallas-codec = "0.22.0"
pallas-primitives = "0.22.0"
pallas-traverse = "0.22.0"
maestro-rust-sdk = "1.1.3"
sidan-csl-rs = { version = "=0.7.5", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.7.6", path = "../sidan-csl-rs" }
reqwest = "0.12.5"
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }

Expand Down
29 changes: 29 additions & 0 deletions packages/whisky/src/builder/tx_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ impl MeshTxBuilder {
self
}

/// ## Transaction building method
///
/// Set the transaction output embedded datum value in the MeshTxBuilder instance
///
/// ### Arguments
///
/// * `data` - The embedded datum value
///
/// ### Returns
///
/// * `Self` - The MeshTxBuilder instance
pub fn tx_out_datum_embed_value(&mut self, data: &WData) -> &mut Self {
let tx_output = self.tx_output.take();
if tx_output.is_none() {
panic!("Undefined output")
}
let mut tx_output = tx_output.unwrap();
match data.to_cbor() {
Ok(raw_data) => {
tx_output.datum = Some(Datum::Embedded(raw_data));
self.tx_output = Some(tx_output);
}
Err(_) => {
panic!("Error converting datum to CBOR");
}
}
self
}

/// ## Transaction building method
///
/// Set the transaction output inline datum value in the MeshTxBuilder instance
Expand Down
35 changes: 33 additions & 2 deletions packages/whisky/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod int_tests {
model::{Asset, Budget, LanguageVersion},
};
use whisky::{
builder::{ MeshTxBuilder, MeshTxBuilderParam, WData::JSON, WRedeemer},
builder::{ MeshTxBuilder, MeshTxBuilderParam, WData::{self, JSON}, WRedeemer},
core::utils::merge_vkey_witnesses_to_transaction,
};

Expand Down Expand Up @@ -462,6 +462,37 @@ mod int_tests {
.complete_signing()
.unwrap();

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

#[test]
fn test_embedded_datum_output() {
let mut mesh = MeshTxBuilder::new(MeshTxBuilderParam {
evaluator: None,
fetcher: None,
submitter: None,
params: None,
});
let signed_tx = mesh
.tx_in(
"2cb57168ee66b68bd04a0d595060b546edf30c04ae1031b883c9ac797967dd85",
3,
&[Asset::new_from_str("lovelace", "9891607895")],
"addr_test1vru4e2un2tq50q4rv6qzk7t8w34gjdtw3y2uzuqxzj0ldrqqactxh",
)
.tx_out("addr_test1vru4e2un2tq50q4rv6qzk7t8w34gjdtw3y2uzuqxzj0ldrqqactxh", &[Asset::new_from_str("lovelace", "2000000")])
.tx_out_datum_embed_value(&WData::JSON(json!({
"constructor": 0,
"fields": []
}).to_string()))
.change_address("addr_test1vru4e2un2tq50q4rv6qzk7t8w34gjdtw3y2uzuqxzj0ldrqqactxh")
.signing_key("51022b7e38be01d1cc581230e18030e6e1a3e949a1fdd2aeae5f5412154fe82b")
.complete_sync(None)
.unwrap()
.complete_signing().unwrap();

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