From 2c7f6a0742cd1d594d6a4ff828d4afb75b3eb074 Mon Sep 17 00:00:00 2001 From: TW Date: Sat, 10 Feb 2024 21:30:29 +0000 Subject: [PATCH 1/5] feat: bug fix on tx output datums --- src/builder/core.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/builder/core.rs b/src/builder/core.rs index e1ca8b3..2a77c1f 100644 --- a/src/builder/core.rs +++ b/src/builder/core.rs @@ -344,6 +344,7 @@ impl MeshTxBuilderCore { type_: "Hash".to_string(), data, }); + self.tx_output = Some(tx_output); self } @@ -357,6 +358,7 @@ impl MeshTxBuilderCore { type_: "Inline".to_string(), data, }); + self.tx_output = Some(tx_output); self } @@ -733,7 +735,7 @@ impl MeshTxBuilderCore { csl::plutus::PlutusDatumSchema::DetailedSchema, ) .unwrap(), - )) + )); } "Inline" => { output_builder = output_builder.with_plutus_data( @@ -742,7 +744,7 @@ impl MeshTxBuilderCore { csl::plutus::PlutusDatumSchema::DetailedSchema, ) .unwrap(), - ) + ); } _ => {} }; From 8bad8bb270c673fe719fe8e5a7541e98e6a038a3 Mon Sep 17 00:00:00 2001 From: TW Date: Sat, 10 Feb 2024 21:30:56 +0000 Subject: [PATCH 2/5] feat: bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69e5a84..8de4de5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.1.9" +version = "0.1.10" dependencies = [ "cardano-serialization-lib", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index 8ade876..54985c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.1.9" +version = "0.1.10" edition = "2021" license = "MIT" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs" From cc6a10d3ac0466cbf1a84c8fdfb1dfc2c58c5693 Mon Sep 17 00:00:00 2001 From: TW Date: Wed, 21 Feb 2024 00:01:38 +0000 Subject: [PATCH 3/5] feat: attach inline datum to change output --- src/builder/core.rs | 31 +++++++++++++++++++++++++++---- src/model/builder.rs | 1 + 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/builder/core.rs b/src/builder/core.rs index 2a77c1f..2edb376 100644 --- a/src/builder/core.rs +++ b/src/builder/core.rs @@ -33,6 +33,7 @@ impl MeshTxBuilderCore { reference_inputs: vec![], mints: vec![], change_address: "".to_string(), + change_datum: None, metadata: vec![], validity_range: ValidityRange { invalid_before: None, @@ -559,6 +560,14 @@ impl MeshTxBuilderCore { self } + pub fn change_output_datum(&mut self, data: String) -> &mut MeshTxBuilderCore { + self.mesh_tx_builder_body.change_datum = Some(Datum { + type_: "Inline".to_string(), + data, + }); + self + } + pub fn invalid_before(&mut self, slot: u64) -> &mut MeshTxBuilderCore { self.mesh_tx_builder_body.validity_range.invalid_before = Some(slot); self @@ -962,10 +971,24 @@ impl MeshTxBuilderCore { } fn add_change(&mut self, change_address: String) { - let _ = self - .tx_builder - .add_change_if_needed(&csl::address::Address::from_bech32(&change_address).unwrap()) - .unwrap(); + if self.mesh_tx_builder_body.change_datum.clone().is_some() { + self.tx_builder + .add_change_if_needed_with_datum( + &csl::address::Address::from_bech32(&change_address).unwrap(), + &csl::OutputDatum::new_data( + &csl::plutus::PlutusData::from_json( + &self.mesh_tx_builder_body.change_datum.clone().unwrap().data, + csl::plutus::PlutusDatumSchema::DetailedSchema, + ) + .unwrap(), + ), + ) + .unwrap(); + } else { + self.tx_builder + .add_change_if_needed(&csl::address::Address::from_bech32(&change_address).unwrap()) + .unwrap(); + } } // fn add_collateral_return(&mut self, change_address: String) { diff --git a/src/model/builder.rs b/src/model/builder.rs index 82109e8..e8cfe0d 100644 --- a/src/model/builder.rs +++ b/src/model/builder.rs @@ -7,6 +7,7 @@ pub struct MeshTxBuilderBody { pub reference_inputs: Vec, pub mints: Vec, pub change_address: String, + pub change_datum: Option, pub metadata: Vec, pub validity_range: ValidityRange, pub signing_key: Vec, From 512096a8053a53ac378c9b6f3346bc18b8a4ca43 Mon Sep 17 00:00:00 2001 From: TW Date: Wed, 21 Feb 2024 00:01:51 +0000 Subject: [PATCH 4/5] feat: test attach inline datum to change output --- tests/integration_tests.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 3c236fe..8a88102 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -167,8 +167,15 @@ mod int_tests { "addr_test1vpw22xesfv0hnkfw4k5vtrz386tfgkxu6f7wfadug7prl7s6gt89x".to_string(), ) .change_address(wallet_address.to_string()) + .change_output_datum( + to_string(&json!({ + "constructor": 0, + "fields": [], + })) + .unwrap(), + ) .complete_sync(None); - + println!("{}", mesh.tx_hex); assert!(mesh.tx_hex != *""); } } From 4e978f88af03a6ad63849d43a056a0bac1ce4c2e Mon Sep 17 00:00:00 2001 From: TW Date: Wed, 21 Feb 2024 00:12:32 +0000 Subject: [PATCH 5/5] feat: bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8de4de5..875cc7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.1.10" +version = "0.1.11" dependencies = [ "cardano-serialization-lib", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index 54985c2..f4c8765 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.1.10" +version = "0.1.11" edition = "2021" license = "MIT" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs"