Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Feb 23, 2024
2 parents dda4ea5 + 4e978f8 commit 4e5d7c8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
37 changes: 31 additions & 6 deletions src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -344,6 +345,7 @@ impl MeshTxBuilderCore {
type_: "Hash".to_string(),
data,
});
self.tx_output = Some(tx_output);
self
}

Expand All @@ -357,6 +359,7 @@ impl MeshTxBuilderCore {
type_: "Inline".to_string(),
data,
});
self.tx_output = Some(tx_output);
self
}

Expand Down Expand Up @@ -557,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
Expand Down Expand Up @@ -733,7 +744,7 @@ impl MeshTxBuilderCore {
csl::plutus::PlutusDatumSchema::DetailedSchema,
)
.unwrap(),
))
));
}
"Inline" => {
output_builder = output_builder.with_plutus_data(
Expand All @@ -742,7 +753,7 @@ impl MeshTxBuilderCore {
csl::plutus::PlutusDatumSchema::DetailedSchema,
)
.unwrap(),
)
);
}
_ => {}
};
Expand Down Expand Up @@ -960,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) {
Expand Down
1 change: 1 addition & 0 deletions src/model/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct MeshTxBuilderBody {
pub reference_inputs: Vec<RefTxIn>,
pub mints: Vec<MintItem>,
pub change_address: String,
pub change_datum: Option<Datum>,
pub metadata: Vec<Metadata>,
pub validity_range: ValidityRange,
pub signing_key: Vec<String>,
Expand Down
9 changes: 8 additions & 1 deletion tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 != *"");
}
}

0 comments on commit 4e5d7c8

Please sign in to comment.