Skip to content

Commit

Permalink
Feature update/ref script size (#98)
Browse files Browse the repository at this point in the history
* bump csl

* add script size for ref inputs

* update tests

* bump ver

* chore: linting

---------

Co-authored-by: SIDANWhatever <[email protected]>
  • Loading branch information
twwu123 and HinsonSIDAN authored Oct 20, 2024
1 parent 25d60fa commit 455844e
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 23 deletions.
44 changes: 39 additions & 5 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/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
version = "0.9.3"
version = "0.9.4"
resolver = "2"
members = [
"sidan-csl-rs",
Expand Down
4 changes: 2 additions & 2 deletions 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.9.3"
version = "0.9.4"
edition = "2021"
license = "Apache-2.0"
description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs"
Expand All @@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
getrandom = { version = "0.2", features = ["js"] }
cardano-serialization-lib = "=12.0.1"
cardano-serialization-lib = "=13.1.0"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
7 changes: 6 additions & 1 deletion packages/sidan-csl-rs/src/core/core_csl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ impl MeshCSL {
&csl::TransactionHash::from_hex(&ref_input.tx_hash)?,
ref_input.tx_index,
);
self.tx_builder.add_reference_input(&csl_ref_input);
if ref_input.script_size.is_some() {
self.tx_builder
.add_script_reference_input(&csl_ref_input, ref_input.script_size.unwrap());
} else {
self.tx_builder.add_reference_input(&csl_ref_input);
}
Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions packages/sidan-csl-rs/src/model/tx_builder_types/tx_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum TxIn {
pub struct RefTxIn {
pub tx_hash: String,
pub tx_index: u32,
pub script_size: Option<usize>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions packages/sidan-csl-rs/src/wasm/txbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub fn js_serialize_tx_body(tx_builder_body_json: &str, params_json: &str) -> Wa

#[test]
fn test_js_serialize_tx_body() {
// let tx_builder_body_json = r#"{"inputs":[{"scriptTxIn":{"txIn":{"txHash":"72a934097270cfdf8cdc445deba5928a004c52c78cbfe94c0024d4f043cc0e77","txIndex":0,"amount":[{"unit":"lovelace","quantity":"1017160"}],"address":"addr_test1wrw35u9mkg76cj0h3npuu4d5zjc3kyl57kyx460cu6zu93gpjj7h0"},"scriptTxIn":{"scriptSource":{"providedScriptSource":{"scriptCbor":"59032759032401010033333323232323232322322322322322322533300c323232323253323301230013013375400426464646464a66602e66e1d20000011533301a301937540102a0042c2a66602e600c0022a66603460326ea8020540085854ccc05ccdc3a40080022a66603460326ea8020540085854ccc05ccdc3a400c0022a66603460326ea8020540085858c05cdd5003899191929919980c99b87480000104cc008dd59801980d9baa00c30013301d375202a97ae01533301930080041330023756600660366ea8030c004cc074dd4809a5eb8054ccc064cdc3a40080082660046eacc00cc06cdd500618009980e9ba90114bd7009919299980d99198008009bac3021302230223022302200322533302000114a0264a66603c66e3cdd7181180100e0a511330030030013023001100114a064a66603c002294054ccc078c0840044c8c8c94ccc078cdc79bae30230030141533301e3371e002038266e1c009200114a02940dd7181118118011bad302130223022001375860400022940c8cc004004dd5981000111299980f8008a5eb804c8ccc888c8cc00400400c894ccc094004400c4c8cc09cdd3998139ba90063302730240013302730250014bd7019801801981480118138009bae301e0013756603e0026600600660460046042002603e603e603e603e60366ea8030dd2a400444646600200200644a66603c00229404c94ccc070cdd7802180e98108010a5113300300300130210012301c301d301d301d301d301d301d0013016375400c60326034004603000260286ea8008dc3a40042c602a602c004602800260280046024002601c6ea800452613656375c0026eb8004dd70009bae001375c002ae6955ceaab9e5573eae815d0aba24c011e581cd161d64eef0eeb59f9124f520f8c8f3b717ed04198d54c8b17e604ae004c011e581c3dc7e4d31bf34d68a822712c47bbf544d74c22fe2350ae7bb51a3f02004c011e581c3dc7e4d31bf34d68a822712c47bbf544d74c22fe2350ae7bb51a3f02004c011e581c18c154376a49c965027adb6afbe97ce43c96a2f9b8bf0eaf9ff15851004c011e581ccc0932775ffd17eba5738509ad28e45637b3d3d45d182d5f1fbf9fe20001","languageVersion":"v3"}},"datumSource":{"inlineDatumSource":{"txHash":"72a934097270cfdf8cdc445deba5928a004c52c78cbfe94c0024d4f043cc0e77","txIndex":0}},"redeemer":{"data":"d87980","exUnits":{"mem":7000000,"steps":3000000000}}}}},{"pubKeyTxIn":{"txIn":{"txHash":"3c05db00dfec497ce870faaa67e6176f8e08352689bee93e203c12cc800c3ebc","txIndex":4,"amount":[{"unit":"lovelace","quantity":"106756821"}],"address":"addr_test1qrgkr4jwau8wkk0ezf84yruv3uahzlksgxvd2nytzlnqft4x8s2nlvl23f82fut92a82jytnw4k7p0esygk2p626vjdqu58u9n"}}}],"outputs":[],"collaterals":[{"txIn":{"txHash":"3c05db00dfec497ce870faaa67e6176f8e08352689bee93e203c12cc800c3ebc","txIndex":0,"amount":[{"unit":"lovelace","quantity":"5000000"}],"address":"addr_test1qrgkr4jwau8wkk0ezf84yruv3uahzlksgxvd2nytzlnqft4x8s2nlvl23f82fut92a82jytnw4k7p0esygk2p626vjdqu58u9n"}}],"requiredSignatures":["d161d64eef0eeb59f9124f520f8c8f3b717ed04198d54c8b17e604ae","5ca51b304b1f79d92eada8c58c513e969458dcd27ce4f5bc47823ffa"],"referenceInputs":[{"txHash":"8d68748457cd0f1a8596f41fd2125a415315897d2da4a4b94335829cee7198ae","txIndex":0}],"mints":[],"changeAddress":"addr_test1qrgkr4jwau8wkk0ezf84yruv3uahzlksgxvd2nytzlnqft4x8s2nlvl23f82fut92a82jytnw4k7p0esygk2p626vjdqu58u9n","metadata":[],"validityRange":{"invalidBefore":null,"invalidHereafter":null},"certificates":[],"signingKey":[],"withdrawals":[{"plutusScriptWithdrawal":{"address":"stake_test17q7u0exnr0e5669gyfcjc3am74zdwnpzlc34ptnmk5dr7qszs53fr","coin":0,"scriptSource":{"inlineScriptSource":{"refTxIn":{"txHash":"f75b8c0ce490b11ba002bc7ed483119665eb8b52d9a11afb0b4a448ca2663d52","txIndex"#;
let tx_builder_body_json = r#"{"inputs":[{"pubKeyTxIn":{"txIn":{"txHash":"5b0145fe7b0212a7807e7dba24997049374d965f587300a2039b73cd30806c78","txIndex":1,"amount":[{"unit":"lovelace","quantity":"1132923230"}],"address":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn"}}}],"outputs":[{"address":"addr_test1wpnlxv2xv9a9ucvnvzqakwepzl9ltx7jzgm53av2e9ncv4sysemm8","amount":[{"unit":"lovelace","quantity":"1600000"}],"datum":{"hash":{"type":"Mesh","content":"supersecret"}},"referenceScript":null}],"collaterals":[{"txIn":{"txHash":"ec0c2e70b898cf531b03c9db937602e98c45378d9fa8e8a5b5a91ec5c1d7540d","txIndex":5,"amount":[{"unit":"lovelace","quantity":"5000000"}],"address":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn"}}],"requiredSignatures":[],"referenceInputs":[],"mints":[],"changeAddress":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn","metadata":[],"validityRange":{"invalidBefore":null,"invalidHereafter":null},"certificates":[],"signingKey":[],"withdrawals":[]}"#;
let params_json = r#"{"epoch":0,"coinsPerUtxoSize":0,"priceMem":0,"priceStep":0,"minFeeA":0,"minFeeB":0,"keyDeposit":2000000,"maxTxSize":16384,"maxValSize":5000,"poolDeposit":500000000,"maxCollateralInputs":3,"decentralisation":0,"maxBlockSize":65536,"collateralPercent":150,"maxBlockHeaderSize":1100,"minPoolCost":"340000000","maxTxExMem":"14000000","maxTxExSteps":"10000000000","maxBlockExMem":"62000000","maxBlockExSteps":"20000000000","minFeeRefScriptCostPerByte":15}"#;
let tx_build_result = js_serialize_tx_body(tx_builder_body_json, params_json);
let mesh_tx_builder_body_json = r#"{"inputs":[{"pubKeyTxIn":{"txIn":{"txHash":"e637646b721e730e7f8f1336cb46736c796d069e4af9b5ad175f3805fd4253ef","txIndex":0,"amount":[{"unit":"lovelace","quantity":"3008380"}],"address":"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr"}}},{"pubKeyTxIn":{"txIn":{"txHash":"bb5c5a24c7bbfb819e5560e73b5bfa22982cb2bced632eb25d6ee7ed5a6b6e60","txIndex":1,"amount":[{"unit":"lovelace","quantity":"47321359"}],"address":"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9"}}}],"outputs":[{"address":"addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr","amount":[],"datum":null,"referenceScript":{"providedScriptSource":{"scriptCbor":"5906d05906cd01010032323232323232253330023232323232533233008300130093754004264646464646464a66601e60060022a66602460226ea8028540085854ccc03cc02000454ccc048c044dd50050a8010b0a9998079802000899191919299980b180c8010a8030b1bae30170013017002375c602a00260226ea802854ccc03ccdc3a400c0022a66602460226ea8028540085858c03cdd5004899191919192999809180318099baa008132323232323232323232323232323232323232323232325333029301d00713333001019011300200f4800854ccc0a4c08801c4cccc004064034c00802d2002132533302a301f00813232323232325333033303600213253330313026303237540022646464a6660686050606a6ea800c4c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc12cc1380084cc0540444cc0540344cc05401c4c94ccc124c8cc004004cc138dd4815198271ba90294bd701129998270008a51132533304c3302303b375c60a20042660060060022940c144004400452819baf0173232323232323230223305330540073305330540063305330540053305330540043305330540033305330540023305330540013305330543055001330533752048660a66ea408d2f5c060a800260a600260a400260a200260a0002609e00260946ea80d858dd7182600098260011bae304a001304a002375a60900026090004608c002608c0046eb8c110004c110008dd698210009821001182000098200011bae303e001303e002303c001303c002375c6074002606c6ea800c58894ccc0d4c0a4c0d8dd5001099191919299981e181f80109980380189919299981d9817800899192999820182180109919299981f981980089919299982218238010998078008a8020b182280098209baa0031533303f303800113232323232325333048304b0021500816375a609200260920046eb4c11c004c11c008dd6982280098209baa00316303f37540042a0082c6082002607a6ea800c54ccc0ecc0d000454ccc0f8c0f4dd50018a8010b0b181d9baa0021500516303d001303d002303b001303737540042c4464a66606a605200226464a666074607a0042a0082c6eb8c0ec004c0dcdd50018a99981a981700089919299981d181e8010a8020b1bae303b001303737540062c606a6ea8008c0d8c0ccdd50008b181a981b181b18191baa001163034001323300100102122533303300114bd70099192999819299981919baf3037303437540040382605664a666066605860686ea8004520001375a6070606a6ea8004c94ccc0ccc0b0c0d0dd50008a60103d87a80001323300100137566072606c6ea8008894ccc0e0004530103d87a800013232323253330393372291100002153330393371e9101000021300c3303d375000297ae014c0103d87a8000133006006003375a60740066eb8c0e0008c0f0008c0e8004c8cc004004dd5981c181c981a9baa00322533303700114c103d87a80001323232325333038337220480042a66607066e3c0900084c02ccc0f0dd3000a5eb80530103d87a8000133006006003375660720066eb8c0dc008c0ec008c0e400452809981b00119802002000899802002000981b801181a8009ba548000dd7181898190011bae3030001302c375404a2a666054660020320122666600403402c91100480045281119198008008019129998180008a50132533302e3371e6eb8c0cc008010528899801801800981980091111929998180008a50153330303033001132323253330303371e6eb8c0d400c01c54ccc0c0cdc7800803099b8700200514a02940dd7181a181a8011bad303330343034001375860640022940c8cc004004014894ccc0c400452f5c0264666444646600200200644a66606e0022006264660726e9ccc0e4dd48031981c981b0009981c981b800a5eb80cc00c00cc0ec008c0e4004dd718180009bab30310013300300330350023033001232337140029101012900337149110a5265676973747279202800330020013300400148008c0040048894ccc0a0c0840044cdc599b80002481812210013371666e00cdc1801000a40c066600600666e18008004cdc1800a40286002002444a66604c66e2000920141001133300300333706004900a19b8200148050c08cdd500e9bae30263027002375c604a002604a0046eb4c08c004c08cc08c008dd7181080098108011bad301f001301f301f002375c603a002603a004603600260360046eb8c064004c054dd5000980b980a1baa008163758602c602e602e602e602e0046eacc054004c054c054008dd618098009809980998079baa00a370e90001b8748010c03cc040008c038004c028dd50011b874800858c02cc030008c028004c028008c020004c010dd50008a4c26cacae6955ceaab9e5573eae815d0aba201","languageVersion":"v3"}}}],"collaterals":[],"requiredSignatures":[],"referenceInputs":[],"mints":[],"changeAddress":"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9","metadata":[],"validityRange":{"invalidBefore":null,"invalidHereafter":null},"certificates":[],"signingKey":[],"withdrawals":[],"votes":[],"network":"preprod"}"#;
// let mesh_tx_builder_body_json = r#"{"inputs":[{"pubKeyTxIn":{"txIn":{"txHash":"5b0145fe7b0212a7807e7dba24997049374d965f587300a2039b73cd30806c78","txIndex":1,"amount":[{"unit":"lovelace","quantity":"1132923230"}],"address":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn"}}}],"outputs":[{"address":"addr_test1wpnlxv2xv9a9ucvnvzqakwepzl9ltx7jzgm53av2e9ncv4sysemm8","amount":[{"unit":"lovelace","quantity":"1600000"}],"datum":{"hash":{"type":"Mesh","content":"supersecret"}},"referenceScript":null}],"collaterals":[{"txIn":{"txHash":"ec0c2e70b898cf531b03c9db937602e98c45378d9fa8e8a5b5a91ec5c1d7540d","txIndex":5,"amount":[{"unit":"lovelace","quantity":"5000000"}],"address":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn"}}],"requiredSignatures":[],"referenceInputs":[],"mints":[],"changeAddress":"addr_test1qq0yavv5uve45rwvfaw96qynrqt8ckpmkwcg08vlwxxdncxk82f5wz75mzaesmqzl79xqsmedwgucwtuav5str6untqqmykcpn","metadata":[],"validityRange":{"invalidBefore":null,"invalidHereafter":null},"certificates":[],"signingKey":[],"withdrawals":[]}"#;
let params_json = r#"{"epoch":0,"coinsPerUtxoSize":4310,"priceMem":0.0577,"priceStep":0.0000721,"minFeeA":44,"minFeeB":155381,"keyDeposit":2000000,"maxTxSize":16384,"maxValSize":5000,"poolDeposit":500000000,"maxCollateralInputs":3,"decentralisation":0,"maxBlockSize":65536,"collateralPercent":150,"maxBlockHeaderSize":1100,"minPoolCost":"340000000","maxTxExMem":"14000000","maxTxExSteps":"10000000000","maxBlockExMem":"62000000","maxBlockExSteps":"20000000000","minFeeRefScriptCostPerByte":15}"#;
let tx_build_result = js_serialize_tx_body(mesh_tx_builder_body_json, params_json);
println!("{:?}", tx_build_result);
}
2 changes: 1 addition & 1 deletion packages/sidan-csl-rs/tests/transaction_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod transaction_tests {
let signing_keys = ["5820010f2ecd1312019694f7cc3bba11cdc386ed320906881cd0a3a8ca05988882ba"];
let signed_tx = sign_transaction("84a30081825820616733c08d8e5846b2669f78074c6c0d1e0e63ec8ef33acbe573aff1f622748e010182a200581d70a67529ee536a0dc1cd6d138ac6644baa11a0858bb32a46b1e9834a97011a001e8480a200581d602aa80698b309b95c849a426edc5b600b8fe6cf2598bc14a3b444bdfd011b0000000253c9cc4e021a00028759a0f5f6", &signing_keys).unwrap();
println!("{}", signed_tx);
assert!(signed_tx == "84a30081825820616733c08d8e5846b2669f78074c6c0d1e0e63ec8ef33acbe573aff1f622748e010182a200581d70a67529ee536a0dc1cd6d138ac6644baa11a0858bb32a46b1e9834a97011a001e8480a200581d602aa80698b309b95c849a426edc5b600b8fe6cf2598bc14a3b444bdfd011b0000000253c9cc4e021a00028759a10081825820f444bd136f6b12767072dc541571412479280efd367335afcf15c5ddf09a98335840ea5ac790a6f75d47da28b13d55021c234ec961f81e35d5b9c447055377c70b066fb28a7e2c01978439712cc85d42f5e00b8c07b6b2b8f36d87178de6ee6d4e02f5f6")
assert!(signed_tx == "84a30081825820616733c08d8e5846b2669f78074c6c0d1e0e63ec8ef33acbe573aff1f622748e010182a200581d70a67529ee536a0dc1cd6d138ac6644baa11a0858bb32a46b1e9834a97011a001e8480a200581d602aa80698b309b95c849a426edc5b600b8fe6cf2598bc14a3b444bdfd011b0000000253c9cc4e021a00028759a100d9010281825820f444bd136f6b12767072dc541571412479280efd367335afcf15c5ddf09a98335840ea5ac790a6f75d47da28b13d55021c234ec961f81e35d5b9c447055377c70b066fb28a7e2c01978439712cc85d42f5e00b8c07b6b2b8f36d87178de6ee6d4e02f5f6")
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions packages/whisky-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "whisky-examples"
version = "0.9.3"
version = "0.9.4"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -13,4 +13,4 @@ path = "src/server.rs"
actix-cors = "0.7.0"
actix-web = "4.9.0"
serde = "1.0.209"
whisky = { version = "=0.9.3", path = "../whisky" }
whisky = { version = "=0.9.4", path = "../whisky" }
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.9.3"
version = "0.9.4"
edition = "2021"
license = "Apache-2.0"
description = "The Cardano Rust SDK, inspired by MeshJS"
Expand All @@ -24,7 +24,7 @@ pallas-codec = { version = "0.30.2", features = ["num-bigint"] }
pallas-primitives = "0.30.2"
pallas-traverse = "0.30.2"
maestro-rust-sdk = "1.1.3"
sidan-csl-rs = { version = "=0.9.3", path = "../sidan-csl-rs" }
sidan-csl-rs = { version = "=0.9.4", path = "../sidan-csl-rs" }
reqwest = "0.12.5"
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"] }

Expand Down
6 changes: 6 additions & 0 deletions packages/whisky/src/builder/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ impl TxBuilder {
ref_tx_in: RefTxIn {
tx_hash: tx_hash.to_string(),
tx_index,
// Script size is already accounted for in script source
script_size: None,
},
script_hash: script_hash.to_string(),
language_version: lang_ver,
Expand All @@ -552,6 +554,8 @@ impl TxBuilder {
ref_tx_in: RefTxIn {
tx_hash: tx_hash.to_string(),
tx_index,
// Script size is already accounted for in script source
script_size: None,
},
simple_script_hash: script_hash.to_string(),
script_size,
Expand All @@ -569,6 +573,8 @@ impl TxBuilder {
ref_tx_in: RefTxIn {
tx_hash: tx_hash.to_string(),
tx_index,
// Script size is already accounted for in script source
script_size: None,
},
script_hash: script_hash.to_string(),
language_version: lang_ver,
Expand Down
4 changes: 4 additions & 0 deletions packages/whisky/src/builder/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ impl TxBuilder {
ref_tx_in: RefTxIn {
tx_hash: tx_hash.to_string(),
tx_index,
// Script size is already accounted for in script source
script_size: None,
},
script_hash: script_hash.to_string(),
language_version: self
Expand All @@ -194,6 +196,8 @@ impl TxBuilder {
ref_tx_in: RefTxIn {
tx_hash: tx_hash.to_string(),
tx_index,
// Script size is already accounted for in script source
script_size: None,
},
simple_script_hash: script_hash.to_string(),
script_size,
Expand Down
Loading

0 comments on commit 455844e

Please sign in to comment.