From 7b0db1e0325a23895b2d070b90ffaab52fbade98 Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Thu, 27 Jun 2024 15:31:15 +0800 Subject: [PATCH] feat: restructure tx body --- packages/Cargo.lock | 4 ++-- packages/sidan-csl-rs/Cargo.toml | 2 +- packages/sidan-csl-rs/src/builder/core.rs | 2 ++ packages/sidan-csl-rs/src/core/tx_parser/mod.rs | 2 ++ packages/sidan-csl-rs/src/model/mod.rs | 4 +++- packages/whisky/Cargo.toml | 4 ++-- packages/whisky/src/builder/core.rs | 13 +++++++------ packages/whisky/src/builder/interface.rs | 2 -- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/Cargo.lock b/packages/Cargo.lock index 068dbec..a4072f7 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -1184,7 +1184,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.5.6" +version = "0.5.7" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -1487,7 +1487,7 @@ dependencies = [ [[package]] name = "whisky" -version = "0.5.6" +version = "0.5.7" dependencies = [ "async-trait", "cardano-serialization-lib", diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index f82f6ca..0f26286 100644 --- a/packages/sidan-csl-rs/Cargo.toml +++ b/packages/sidan-csl-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.5.6" +version = "0.5.7" edition = "2021" license = "Apache-2.0" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs" diff --git a/packages/sidan-csl-rs/src/builder/core.rs b/packages/sidan-csl-rs/src/builder/core.rs index 87cf361..35400e5 100644 --- a/packages/sidan-csl-rs/src/builder/core.rs +++ b/packages/sidan-csl-rs/src/builder/core.rs @@ -148,6 +148,7 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { mesh_tx_builder_body: MeshTxBuilderBody { inputs: vec![], outputs: vec![], + extra_inputs: vec![], collaterals: vec![], required_signatures: JsVecString::new(), reference_inputs: vec![], @@ -162,6 +163,7 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { invalid_hereafter: None, }, signing_key: JsVecString::new(), + selection_threshold: 5_000_000, }, tx_evaluation_multiplier_percentage: 110, } diff --git a/packages/sidan-csl-rs/src/core/tx_parser/mod.rs b/packages/sidan-csl-rs/src/core/tx_parser/mod.rs index 5808c93..69c2659 100644 --- a/packages/sidan-csl-rs/src/core/tx_parser/mod.rs +++ b/packages/sidan-csl-rs/src/core/tx_parser/mod.rs @@ -34,6 +34,7 @@ impl IMeshTxParser for MeshTxParser { let mut tx_body = MeshTxBuilderBody { inputs: vec![], outputs: vec![], + extra_inputs: vec![], collaterals: vec![], required_signatures: JsVecString::new(), reference_inputs: vec![], @@ -48,6 +49,7 @@ impl IMeshTxParser for MeshTxParser { invalid_hereafter: None, }, signing_key: JsVecString::new(), + selection_threshold: 5_000_000, }; let csl_tx = csl::Transaction::from_hex(s).expect("Invalid transaction"); let csl_tx_body = csl_tx.body(); diff --git a/packages/sidan-csl-rs/src/model/mod.rs b/packages/sidan-csl-rs/src/model/mod.rs index e07c8e0..3494aeb 100644 --- a/packages/sidan-csl-rs/src/model/mod.rs +++ b/packages/sidan-csl-rs/src/model/mod.rs @@ -19,6 +19,7 @@ pub use value::*; pub struct MeshTxBuilderBody { pub inputs: Vec, pub outputs: Vec, + pub extra_inputs: Vec, pub collaterals: Vec, pub required_signatures: JsVecString, pub reference_inputs: Vec, @@ -30,6 +31,7 @@ pub struct MeshTxBuilderBody { pub validity_range: ValidityRange, pub certificates: Vec, pub signing_key: JsVecString, + pub selection_threshold: u64, } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -118,7 +120,7 @@ pub struct InlineScriptSource { } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] +// #[serde(rename_all = "camelCase")] pub enum LanguageVersion { V1, V2, diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index d0dedf5..e215cb3 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky" -version = "0.5.6" +version = "0.5.7" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -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.6", path = "../sidan-csl-rs" } +sidan-csl-rs = { version = "=0.5.7", path = "../sidan-csl-rs" } [profile.release] # Tell `rustc` to optimize for small code size. diff --git a/packages/whisky/src/builder/core.rs b/packages/whisky/src/builder/core.rs index 89fde2a..6407c3f 100644 --- a/packages/whisky/src/builder/core.rs +++ b/packages/whisky/src/builder/core.rs @@ -27,8 +27,6 @@ impl IMeshTxBuilder for MeshTxBuilder { core: MeshTxBuilderCore::new_core(None), protocol_params: param.params, tx_in_item: None, - extra_inputs: vec![], - selection_threshold: 5_000_000, withdrawal_item: None, mint_item: None, collateral_item: None, @@ -88,8 +86,11 @@ impl IMeshTxBuilder for MeshTxBuilder { self.core.mesh_tx_builder_body = customized_tx.unwrap(); } else { self.queue_all_last_item(); - if !self.extra_inputs.is_empty() { - self.add_utxos_from(self.extra_inputs.clone(), self.selection_threshold)?; + if !self.core.mesh_tx_builder_body.extra_inputs.is_empty() { + self.add_utxos_from( + self.core.mesh_tx_builder_body.extra_inputs.clone(), + self.core.mesh_tx_builder_body.selection_threshold, + )?; } } @@ -838,8 +839,8 @@ impl IMeshTxBuilder for MeshTxBuilder { } fn select_utxos_from(&mut self, extra_inputs: Vec, threshold: u64) -> &mut Self { - self.selection_threshold = threshold; - self.extra_inputs = extra_inputs; + self.core.mesh_tx_builder_body.selection_threshold = threshold; + self.core.mesh_tx_builder_body.extra_inputs = extra_inputs; self } diff --git a/packages/whisky/src/builder/interface.rs b/packages/whisky/src/builder/interface.rs index c0de628..be4c4a8 100644 --- a/packages/whisky/src/builder/interface.rs +++ b/packages/whisky/src/builder/interface.rs @@ -14,8 +14,6 @@ pub struct MeshTxBuilder { pub core: MeshTxBuilderCore, pub protocol_params: Option, pub tx_in_item: Option, - pub extra_inputs: Vec, - pub selection_threshold: u64, pub withdrawal_item: Option, pub mint_item: Option, pub collateral_item: Option,