Skip to content

Commit

Permalink
chore: rename variable and fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Oct 17, 2024
1 parent d6c1ade commit 6680853
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 138 deletions.
52 changes: 26 additions & 26 deletions packages/sidan-csl-rs/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cardano_serialization_lib::JsError;
#[derive(Clone, Debug)]
pub struct TxBuilderCore {
pub mesh_csl: MeshCSL,
pub mesh_tx_builder_body: TxBuilderBody,
pub tx_builder_body: TxBuilderBody,
pub tx_evaluation_multiplier_percentage: u64,
}

Expand All @@ -15,49 +15,49 @@ pub struct TxBuilderCore {
///
/// ### Arguments
///
/// * `mesh_tx_builder_body` - The transaction builder body information
/// * `tx_builder_body` - The transaction builder body information
/// * `params` - Optional protocol parameters, default as Cardano mainnet configuration
///
/// ### Returns
///
/// * `String` - the built transaction hex
pub fn serialize_tx_body(
mesh_tx_builder_body: TxBuilderBody,
tx_builder_body: TxBuilderBody,
params: Option<Protocol>,
) -> Result<String, JsError> {
if mesh_tx_builder_body.change_address.is_empty() {
if tx_builder_body.change_address.is_empty() {
return Err(JsError::from_str("change address cannot be empty"));
}
let mut mesh_csl = MeshCSL::new(params);

TxBuilderCore::add_all_inputs(&mut mesh_csl, mesh_tx_builder_body.inputs.clone())?;
TxBuilderCore::add_all_outputs(&mut mesh_csl, mesh_tx_builder_body.outputs.clone())?;
TxBuilderCore::add_all_collaterals(&mut mesh_csl, mesh_tx_builder_body.collaterals.clone())?;
TxBuilderCore::add_all_inputs(&mut mesh_csl, tx_builder_body.inputs.clone())?;
TxBuilderCore::add_all_outputs(&mut mesh_csl, tx_builder_body.outputs.clone())?;
TxBuilderCore::add_all_collaterals(&mut mesh_csl, tx_builder_body.collaterals.clone())?;
TxBuilderCore::add_all_reference_inputs(
&mut mesh_csl,
mesh_tx_builder_body.reference_inputs.clone(),
tx_builder_body.reference_inputs.clone(),
)?;
TxBuilderCore::add_all_withdrawals(&mut mesh_csl, mesh_tx_builder_body.withdrawals.clone())?;
TxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone())?;
TxBuilderCore::add_all_certificates(&mut mesh_csl, mesh_tx_builder_body.certificates.clone())?;
TxBuilderCore::add_all_votes(&mut mesh_csl, mesh_tx_builder_body.votes.clone())?;
TxBuilderCore::add_validity_range(&mut mesh_csl, mesh_tx_builder_body.validity_range.clone());
TxBuilderCore::add_all_withdrawals(&mut mesh_csl, tx_builder_body.withdrawals.clone())?;
TxBuilderCore::add_all_mints(&mut mesh_csl, tx_builder_body.mints.clone())?;
TxBuilderCore::add_all_certificates(&mut mesh_csl, tx_builder_body.certificates.clone())?;
TxBuilderCore::add_all_votes(&mut mesh_csl, tx_builder_body.votes.clone())?;
TxBuilderCore::add_validity_range(&mut mesh_csl, tx_builder_body.validity_range.clone());
TxBuilderCore::add_all_required_signature(
&mut mesh_csl,
&mesh_tx_builder_body
&tx_builder_body
.required_signatures
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>(),
)?;
TxBuilderCore::add_all_metadata(&mut mesh_csl, mesh_tx_builder_body.metadata.clone())?;
TxBuilderCore::add_all_metadata(&mut mesh_csl, tx_builder_body.metadata.clone())?;

match mesh_tx_builder_body.network {
match tx_builder_body.network {
Some(current_network) => mesh_csl.add_script_hash(current_network)?,
None => mesh_csl.add_script_hash(Network::Mainnet)?,
};
// if self.mesh_tx_builder_body.change_address != "" {
// let collateral_inputs = self.mesh_tx_builder_body.collaterals.clone();
// if self.tx_builder_body.change_address != "" {
// let collateral_inputs = self.tx_builder_body.collaterals.clone();
// let collateral_vec: Vec<u64> = collateral_inputs
// .into_iter()
// .map(|pub_key_tx_in| {
Expand Down Expand Up @@ -86,7 +86,7 @@ pub fn serialize_tx_body(
// let mut collateral_return_needed = false;
// if (total_collateral - collateral_estimate) > 0 {
// let collateral_estimate_output = csl::TransactionOutput::new(
// &csl::address::Address::from_bech32(&self.mesh_tx_builder_body.change_address)
// &csl::address::Address::from_bech32(&self.tx_builder_body.change_address)
// .unwrap(),
// &csl::utils::Value::new(&to_bignum(collateral_estimate)),
// );
Expand All @@ -104,7 +104,7 @@ pub fn serialize_tx_body(
// self.tx_builder
// .set_collateral_return(&csl::TransactionOutput::new(
// &csl::address::Address::from_bech32(
// &self.mesh_tx_builder_body.change_address,
// &self.tx_builder_body.change_address,
// )
// .unwrap(),
// &csl::utils::Value::new(&to_bignum(total_collateral)),
Expand All @@ -116,14 +116,14 @@ pub fn serialize_tx_body(
// collateral_return_needed = true;
// }
// }
// self.add_change(self.mesh_tx_builder_body.change_address.clone());
// self.add_change(self.tx_builder_body.change_address.clone());
// if collateral_return_needed {
// self.add_collateral_return(self.mesh_tx_builder_body.change_address.clone());
// self.add_collateral_return(self.tx_builder_body.change_address.clone());
// }
// }
mesh_csl.add_change(
mesh_tx_builder_body.change_address.clone(),
mesh_tx_builder_body.change_datum.clone(),
tx_builder_body.change_address.clone(),
tx_builder_body.change_datum.clone(),
)?;
mesh_csl.build_tx()
}
Expand All @@ -140,7 +140,7 @@ impl TxBuilderCore {
pub fn new_core(params: Option<Protocol>) -> Self {
Self {
mesh_csl: MeshCSL::new(params),
mesh_tx_builder_body: TxBuilderBody {
tx_builder_body: TxBuilderBody {
inputs: vec![],
outputs: vec![],
collaterals: vec![],
Expand Down Expand Up @@ -172,7 +172,7 @@ impl TxBuilderCore {
///
/// * `String` - The signed transaction in hex
pub fn complete_signing(&mut self) -> Result<String, JsError> {
let signing_keys = self.mesh_tx_builder_body.signing_key.clone();
let signing_keys = self.tx_builder_body.signing_key.clone();
self.add_all_signing_keys(
&signing_keys
.iter()
Expand Down
16 changes: 11 additions & 5 deletions packages/sidan-csl-rs/src/core/utils/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,28 @@ pub fn evaluate_tx_scripts_js(
match serde_json::from_str(utxo_json.as_str()) {
Ok(utxo) => deserialized_utxos.push(utxo),
Err(e) => {
return WasmResult::new_error("failure".to_string(), format!("Error in decoding UTXO: {:?}", e));
return WasmResult::new_error(
"failure".to_string(),
format!("Error in decoding UTXO: {:?}", e),
);
}
}
}

let deserialize_network = match network.try_into() {
Ok(network) => network,
Err(e) => {
return WasmResult::new_error("failure".to_string(), format!("Error in decoding network: {:?}", e));
return WasmResult::new_error(
"failure".to_string(),
format!("Error in decoding network: {:?}", e),
);
}
};

let eval_result = evaluate_tx_scripts(
&tx_hex,
&deserialized_utxos,
&additional_txs.as_ref_vec(),
additional_txs.as_ref_vec(),
&deserialize_network,
);

Expand Down Expand Up @@ -418,7 +424,7 @@ mod test {
let utxo_5 = "{\"input\": {\"outputIndex\": 2, \"txHash\": \"1c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441\"}, \"output\": {\"address\": \"addr_test1qrsaqj54nyedfg74tye8743tkrclgnfztj6z937g50q0fwv6vwcuvc9guftgju6xav470f6da9guk8t3nn46wd34z43s99hwxv\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"5000000\"}], \"scriptHash\": null}}";
let utxo_6 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"66b7282bad1aef9ba0a99f06e618d651d232d4788f0d2ee2d22db22a62391033\"}, \"output\": {\"address\": \"addr_test1qp0q40yv0ywzyzuv2mnjnjmha9wq83aay7t339ka5zkzx6xglkktstqua3rk63z02kwz3a9hthdk7jplugzzw6p6vcdqa39gds\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"26000000\"}], \"scriptHash\": \"32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bd\", \"scriptRef\": \"8202590eca590ec701000033232323232323223223232322533300832323232323232323232323232323232323232323232323232323232323232323232323232323232325333031302d30323754002264a66606460540022a666064666018910103313333000063758601660686ea8c080c0d0dd50158a9998191998050031bac301130343754604060686ea80acdd61810181a1baa30203034375405626666444464646464a666074606c60766ea80044c8c8c8c8c8c8c94ccc10402854ccc10402454ccc10401854ccc10400c54ccc10400840045280a5014a0294052819192999821181f0008b0a999821181d000899b89375a608e60886ea8008dd6982398241824182418221baa0061630423754002605c60846ea8c114c118c108dd50059980f99baf301a30413754006605a60826ea8059240132496e74656e7420646174756d2073686f756c6420636f6e7461696e20616c6c206d61746368696e6720726566732075736564003301e3375e605860806ea8010c084c100dd50092493f496e74656e7420746f6b656e2073686f756c64206f6e6c7920657665722062652073656e7420746f20696e74656e74207370656e64696e672073637269707400533303d3039303e37540022646464646464646464646464a666098609e0042646493182280218178038b18268009826801182580098258011bad3049001304900230470013047002375a608a002608a0046086002607e6ea800458cc0640092401264f7574707574206d75737420636f6e7461696e20736f6d6520696e6c696e656420646174756d003301b3024301c323300100137566036607c6ea8008894ccc10000452f5c0264666444646600200200644a66608c0022006264660906e9ccc120dd4803198241822800998241823000a5eb80cc00c00cc128008c120004dd7181f8009bab304000133003003304400230420014901224f6e6c792061646120616c6c6f776564207769746820696e74656e7420746f6b656e00303f303c37540022ca6660780062980103d87a80001302d3303d303e0034bd701980c1818181380124812e4f6e6c7920612073696e676c65206f7574707574207769746820696e74656e7420746f6b656e20616c6c6f77656400330173375e6e98c04c00cdd31991299981c9818a4000297adef6c6013232330010014bd6f7b63011299981f80089982019bb0375200a6e9800d2f5bded8c0264646464a66608066e400240084cc110cdd81ba9009374c00e00a2a66608066e3c0240084cc110cdd81ba9009374c00e00626608866ec0dd48011ba600133006006003375660820066eb8c0fc008c10c008c104004c8cc0040052f5bded8c044a66607c00226607e66ec0dd4801a610101004bd6f7b630099191919299981f99b90007002133043337606ea401d3010101000051533303f3371e00e00426608666ec0dd4803a61010100003133043337606ea4008dd4000998030030019bad3040003375c607c004608400460800026eb8c094c0e4dd50029bae30163039375400a9212b4f6e6c7920612073696e676c6520696e74656e7420746f6b656e2073686f756c64206265206d696e74656400330280032302f3330153756602c60726ea8004dd71812981c9baa005375c602c60726ea8014c098cc0d8dd48021981b2610140004bd701bac301530343754604060686ea80acdd59806981a1baa302030343754056606e607060706070607060706070607060686ea8c080c0d0dd50158a5014a02a66606466e2000520001533303233300c488103313838000063758601660686ea8c080c0d0dd501589998050031bac301130343754604060686ea80acdd61810181a1baa302030343754056294058dd6981b18199baa00116533303030283301501500113301b0014890014c103d87a8000325333030302830313754002297adef6c6013756606a60646ea8004cc064c02cdd5980518189baa301d3031375405000264a66605e605660606ea80044dd7181a18189baa00116300d3030375404ea66605a6052605c6ea80044c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc108c1140084c8c8c8c8c8c8c926302b00b302a00c302a00d302900e302700f303b010533303f303b3040375402226464a666088608e004264931981b000919181798228011bae3043001163756608a00260826ea80445858c10c004c10c008dd698208009820801181f800981f801181e800981e801181d800981d801181c800981c801181b800981b801181a800981a801181980098179baa00116300f302e3754004a666056604e60586ea80044c8c8c8c8c8c94ccc0d0c0dc0084c8c926301a00430190051630350013035002303300130330023031001302d37540022c6600e601260586ea800524011e436f6c642072656620646174756d206d75737420626520696e6c696e6564003232533302b323300100102a22533303000114a0264a66605c64604e66601a6eacc038c0c4dd5180718189baa005375c603a60626ea8004dd7180718189baa001303300214a2266006006002606600220022ca666054604c60566ea80044c0bcc0b0dd50008b198069bac3008302b3754602e60566ea8088098888c94ccc0b14ccc0b0c090c0b4dd519808001980598171baa0041614a2200229414ccc0acc09cc0b0dd519807800980518169baa0031614a24605a605c605c605c605c605c605c605c605c00244464660020026464a6660586050605a6ea80044c0c4c0b8dd50008992999816981498171baa00113032302f37540022c6603e00491010130003301e0010053756603060586ea8c060c0b0dd5001912999815981398161baa001132323300100100522533303100114a0264a66605e66e3cdd7181a0010020a511330030030013034001375c6060605a6ea80044c8cdc49bad30313032001301b3301e375860620024660080080026eb0c0c0c0b4dd5000918159816181618161816000919198008008011129998150008a5eb7bdb1804c8c8c8c94ccc0accdc8a45000021533302b3371e9101000021003100513302f337606ea4008dd3000998030030019bab302c003375c6054004605c00460580024464a66604c601e604e6ea80044c0acc0a0dd50008b180418139baa002222325333026301e302737540022900009bad302b3028375400264a66604c603c604e6ea8004530103d87a80001330113756605660506ea8004008cc03c00c0088c09cc0a0004894ccc0880085288b18008009129998118008a40002602266004004604c002460466048604800244646600200200644a666046002298103d87a80001323253330223375e602060486ea80080144c058cc0980092f5c0266008008002604e004604a00244a66604000229000098071980100118118009299980d980b980e1baa0011323232325333022302500213232498c94ccc084c0740044c8c94ccc098c0a40084c9263019001163027001302337540062a66604260320022a66604860466ea800c526161630213754004602c0062c604600260460046042002603a6ea80045894ccc068c058c06cdd5000899191919299981098120010a4c2c6eb8c088004c088008dd71810000980e1baa00116232533301a301600113232533301f3022002149858dd71810000980e1baa0021533301a301200113232533301f3022002132498c05c00458c080004c070dd50010a99980d180180089919299980f981100109924c60240022c604000260386ea800854ccc068cdc3a400c00226464a66603e60440042649319299980e980c800899192999811181280109924c602a0022c6046002603e6ea800854ccc074c0540044c8c94ccc088c0940084c9263015001163023001301f37540042a66603a600c002264646464a666048604e00426493180b8018b1bae302500130250023023001301f37540042a66603a66e1d200600113232323253330243027002149858dd7181280098128011bae3023001301f37540042a66603a66e1d200800113232323253330243027002149858dd6981280098128011bae3023001301f37540042a66603a66e1d200a00115333020301f37540042930b0a99980e99b874803000454ccc080c07cdd50010a4c2c2c603a6ea800458c080004c070dd50010b180d1baa001370e900211191980080080191299980e8008a60103d87a8000132323232533301e3372200e0042a66603c66e3c01c0084c048cc088dd3000a5eb80530103d87a80001330060060033756603e0066eb8c074008c084008c07c00488c8cc00400400c894ccc0700045300103d87a8000132323232533301d3372200e0042a66603a66e3c01c0084c044cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c00400488c94ccc058c0480044c8c94ccc06cc07800852616375c603800260306ea800854ccc058c0380044c8c94ccc06cc0780084c926323232533301e3021002132498cc04000c8cc02402400458dd6980f800980f8011bac301d001163758603800260306ea800858c058dd50009180c000980080091299980a8008a4000260066600400460300026e01200222323300100100322533301500114bd7009919299980a180280109980c00119802002000899802002000980c801180b80091191980080080191299980a0008a6103d87a800013232323253330153372200e0042a66602a66e3c01c0084c024cc0640052f5c0298103d87a80001330060060033016003375c60280046030004602c0026e95200022323300100100322533301200114984c8cc00c00cc058008c00cc0500048c94ccc030c0200044c8c94ccc044c0500084c9263005001163012001300e37540042a66601860080022646464646464a66602a60300042930b1bad30160013016002375a602800260280046eb4c048004c038dd50010b18061baa001232533300b30070011323253330103013002149858dd7180880098069baa0021533300b30030011323253330103013002149858dd7180880098069baa00216300b37540026e1d200214984d958c00400c94ccc018c008c01cdd50008991919192999806980800109924ca666014600c60166ea800c4c8c94ccc03cc04800852616375c602000260186ea800c5858dd698070009807001180600098041baa00116370e90001bac0015734aae7555cf2ab9f5740ae855d12601259fd8799f581c55871db8a58f10fddf48b92029827d168271e785646af257de85486c40ffff0001\"}}";
let utxo_7 = "{\"input\": {\"outputIndex\": 0, \"txHash\": \"5f759f3527a47632735470586a7ab2fbee4b4aa8b6504d52d52bc62fa8ec961a\"}, \"output\": {\"address\": \"addr_test1qp0q40yv0ywzyzuv2mnjnjmha9wq83aay7t339ka5zkzx6xglkktstqua3rk63z02kwz3a9hthdk7jplugzzw6p6vcdqa39gds\", \"amount\": [{\"unit\": \"lovelace\", \"quantity\": \"4000000\"}, {\"unit\": \"55871db8a58f10fddf48b92029827d168271e785646af257de85486c\", \"quantity\": \"1\"}], \"dataHash\": \"a5a21bf7d9119e01f8cf04316dba1d9cdcacd998430728fdb938de8dad4b6c1f\", \"plutusData\": \"d8799fd8799f581c0eb1e4ef980b3c308edd7b3ab64990d5240e5230286038cae5c634cdffd8799f581c1fdf3668220c08618b4f2e5e7cc54f70ca4b11fd2b6a3fbe678235f1ffd8799fd8799fa14130d8799f581cc6aa7af71f8ba577246149edf075d2edd9daa63980b7ca176799af6cffffd8799fd8799f58201c4ef054932bafcb4a59810f31fa0ed001d6611066938d1a1aef1d1237c0a441ff00ffd8799fd87a9f581ceafce55e4f0e057b495f77d8019577c56ae1fe188dc7e6d63f4f93b8ffd87a80ffd8799f581c32b7e3d552b2b18cb9bf1a39e6e1ce75f62c084f2b917a44c071a3bd40ffd8799f581cdbde35dec305604c1c8a596437802fd5e3468c8e92ce1781203e7bb74455534441ffd8799fd87a9f581c10fcea52f80dbc6e499106b02894173a2e60d21c6b3d1fe881d9495dffd87a80ffd8799fd8799f581cc6aa7af71f8ba577246149edf075d2edd9daa63980b7ca176799af6cffd87a80ff1903e801ffff\", \"scriptHash\": null}}";
let mut resolved_utxos = JsVecString::new();
let mut resolved_utxos = JsVecString::new();
resolved_utxos.add(utxo_1.to_string());
resolved_utxos.add(utxo_2.to_string());
resolved_utxos.add(utxo_3.to_string());
Expand All @@ -433,7 +439,7 @@ mod test {
tx_hex.to_string(),
&resolved_utxos,
&additional_txs,
"preprod".to_string()
"preprod".to_string(),
);

assert_eq!(result.get_status(), "success");
Expand Down
2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/src/model/js_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl JsVecString {
self.0.push(elem.clone());
}

pub(crate) fn into_vec(self) -> Vec<String> {
pub fn into_vec(self) -> Vec<String> {
self.0
}

Expand Down
Loading

0 comments on commit 6680853

Please sign in to comment.