Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sidan-lab/sidan-csl-rs in…
Browse files Browse the repository at this point in the history
…to feature/staking
  • Loading branch information
HinsonSIDAN committed Jun 12, 2024
2 parents a5c75b4 + c495159 commit 12e0599
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 31 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.0-alpha.9"
version = "0.5.1"
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
25 changes: 2 additions & 23 deletions packages/sidan-csl-rs/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,11 @@ pub fn js_serialize_tx_body(mesh_tx_builder_body_json: &str, params_json: &str)
///
/// * `String` - the built transaction hex
pub fn serialize_tx_body(
mut mesh_tx_builder_body: MeshTxBuilderBody,
mesh_tx_builder_body: MeshTxBuilderBody,
params: Option<Protocol>,
) -> String {
let mut mesh_csl = MeshCSL::new(params);

mesh_tx_builder_body
.mints
.sort_by(|a, b| a.policy_id.cmp(&b.policy_id));

mesh_tx_builder_body.inputs.sort_by(|a, b| {
let tx_in_data_a: &TxInParameter = match a {
TxIn::PubKeyTxIn(pub_key_tx_in) => &pub_key_tx_in.tx_in,
TxIn::ScriptTxIn(script_tx_in) => &script_tx_in.tx_in,
};

let tx_in_data_b: &TxInParameter = match b {
TxIn::PubKeyTxIn(pub_key_tx_in) => &pub_key_tx_in.tx_in,
TxIn::ScriptTxIn(script_tx_in) => &script_tx_in.tx_in,
};

tx_in_data_a
.tx_hash
.cmp(&tx_in_data_b.tx_hash)
.then_with(|| tx_in_data_a.tx_index.cmp(&tx_in_data_b.tx_index))
});

MeshTxBuilderCore::add_all_inputs(&mut mesh_csl, mesh_tx_builder_body.inputs.clone());
MeshTxBuilderCore::add_all_outputs(&mut mesh_csl, mesh_tx_builder_body.outputs.clone());
MeshTxBuilderCore::add_all_collaterals(&mut mesh_csl, mesh_tx_builder_body.collaterals.clone());
Expand Down Expand Up @@ -178,7 +157,7 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore {
},
signing_key: JsVecString::new(),
},
tx_evaluation_multiplier_percentage: 10,
tx_evaluation_multiplier_percentage: 110,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/tests/aiken_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod aiken_tests {
use serde_json::{json, to_string};
let script =
"584501000032323232323222533300432323253330073370e900018041baa0011324a2600c0022c60120026012002600600229309b2b118021baa0015734aae7555cf2ba157441";
let params = vec![to_string(&json!({ "bytes": "1234"})).unwrap()];
let params = [to_string(&json!({ "bytes": "1234"})).unwrap()];

let mut aiken_params = JsVecString::new();
aiken_params.add(params[0].clone());
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.0-alpha.9"
version = "0.5.1"
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.0-alpha.9", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.5.1", path = "../sidan-csl-rs" }

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
32 changes: 32 additions & 0 deletions packages/whisky/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl IMeshTxBuilder for MeshTxBuilder {
}
}

fn new_core() -> Self {
Self::new(super::MeshTxBuilderParam {
evaluator: None,
fetcher: None,
submitter: None,
params: None,
})
}

async fn complete(&mut self, customized_tx: Option<MeshTxBuilderBody>) -> &mut Self {
self.complete_sync(customized_tx);
match &self.evaluator {
Expand Down Expand Up @@ -72,6 +81,29 @@ impl IMeshTxBuilder for MeshTxBuilder {
self.add_utxos_from(self.extra_inputs.clone(), self.selection_threshold);
}
}

self.core
.mesh_tx_builder_body
.mints
.sort_by(|a, b| a.policy_id.cmp(&b.policy_id));

self.core.mesh_tx_builder_body.inputs.sort_by(|a, b| {
let tx_in_data_a: &TxInParameter = match a {
TxIn::PubKeyTxIn(pub_key_tx_in) => &pub_key_tx_in.tx_in,
TxIn::ScriptTxIn(script_tx_in) => &script_tx_in.tx_in,
};

let tx_in_data_b: &TxInParameter = match b {
TxIn::PubKeyTxIn(pub_key_tx_in) => &pub_key_tx_in.tx_in,
TxIn::ScriptTxIn(script_tx_in) => &script_tx_in.tx_in,
};

tx_in_data_a
.tx_hash
.cmp(&tx_in_data_b.tx_hash)
.then_with(|| tx_in_data_a.tx_index.cmp(&tx_in_data_b.tx_index))
});

let tx_hex = serialize_tx_body(
self.core.mesh_tx_builder_body.clone(),
self.protocol_params.clone(),
Expand Down
13 changes: 13 additions & 0 deletions packages/whisky/src/builder/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,24 @@ pub trait IMeshTxBuilder {
///
/// Create a new MeshTxBuilder instance
///
/// ### Arguments
///
/// * `param` - Parameters for setting up the MeshTxBuilder instance, including evaluator, fetcher, submitter, and protocol parameters
///
/// ### Returns
///
/// * `Self` - A new MeshTxBuilder instance
fn new(param: MeshTxBuilderParam) -> Self;

/// ## Transaction building method
///
/// Create a new MeshTxBuilder instance
///
/// ### Returns
///
/// * `Self` - A new MeshTxBuilder instance
fn new_core() -> Self;

/// ## Transaction building method
///
/// Complete the transaction building process with fetching missing information & tx evaluation
Expand Down
2 changes: 1 addition & 1 deletion packages/whisky/src/builder/tx_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn to_pallas_utxos(utxos: &Vec<UTxO>) -> Result<Vec<ResolvedInput>, JsError> {
let resolved_input = ResolvedInput {
input: TransactionInput {
transaction_id: Hash::from(tx_hash),
index: utxo.input.output_index.try_into().unwrap(),
index: utxo.input.output_index.into(),
},
output: TransactionOutput::PostAlonzo(PostAlonzoTransactionOutput {
address: Bytes::from(
Expand Down
5 changes: 4 additions & 1 deletion packages/whisky/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod builder;
pub mod service;
pub use sidan_csl_rs;
pub use sidan_csl_rs::builder as builder_core;
pub use sidan_csl_rs::core;
pub use sidan_csl_rs::csl;
pub use sidan_csl_rs::model;

0 comments on commit 12e0599

Please sign in to comment.