Skip to content

Commit

Permalink
feat: restructure tx body
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Jun 27, 2024
1 parent 2170bd1 commit 7b0db1e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
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.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"
Expand Down
2 changes: 2 additions & 0 deletions packages/sidan-csl-rs/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![],
Expand All @@ -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,
}
Expand Down
2 changes: 2 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 @@ -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![],
Expand All @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion packages/sidan-csl-rs/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use value::*;
pub struct MeshTxBuilderBody {
pub inputs: Vec<TxIn>,
pub outputs: Vec<Output>,
pub extra_inputs: Vec<UTxO>,
pub collaterals: Vec<PubKeyTxIn>,
pub required_signatures: JsVecString,
pub reference_inputs: Vec<RefTxIn>,
Expand All @@ -30,6 +31,7 @@ pub struct MeshTxBuilderBody {
pub validity_range: ValidityRange,
pub certificates: Vec<Certificate>,
pub signing_key: JsVecString,
pub selection_threshold: u64,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -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,
Expand Down
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.6"
version = "0.5.7"
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.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.
Expand Down
13 changes: 7 additions & 6 deletions packages/whisky/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)?;
}
}

Expand Down Expand Up @@ -838,8 +839,8 @@ impl IMeshTxBuilder for MeshTxBuilder {
}

fn select_utxos_from(&mut self, extra_inputs: Vec<UTxO>, 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
}

Expand Down
2 changes: 0 additions & 2 deletions packages/whisky/src/builder/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub struct MeshTxBuilder {
pub core: MeshTxBuilderCore,
pub protocol_params: Option<Protocol>,
pub tx_in_item: Option<TxIn>,
pub extra_inputs: Vec<UTxO>,
pub selection_threshold: u64,
pub withdrawal_item: Option<Withdrawal>,
pub mint_item: Option<MintItem>,
pub collateral_item: Option<PubKeyTxIn>,
Expand Down

0 comments on commit 7b0db1e

Please sign in to comment.