From 1c8025c21d75d77501cbdf97466379f364eaa3a9 Mon Sep 17 00:00:00 2001 From: SIDANWhatever Date: Wed, 19 Jun 2024 01:18:12 +0800 Subject: [PATCH] feat: adding error catching for most methods --- packages/Cargo.lock | 1073 +---------------- packages/sidan-csl-rs/Cargo.toml | 2 +- packages/sidan-csl-rs/src/builder/core.rs | 120 +- .../sidan-csl-rs/src/builder/interface.rs | 36 +- packages/sidan-csl-rs/src/core/builder.rs | 460 ++++--- packages/whisky/Cargo.toml | 6 +- packages/whisky/src/builder/core.rs | 24 +- packages/whisky/src/builder/interface.rs | 16 +- packages/whisky/src/builder/tx_eval.rs | 4 +- packages/whisky/tests/integration_tests.rs | 6 +- 10 files changed, 384 insertions(+), 1363 deletions(-) diff --git a/packages/Cargo.lock b/packages/Cargo.lock index 5c00af2..331d7d4 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" version = "0.8.11" @@ -29,15 +14,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - [[package]] name = "anyhow" version = "1.0.86" @@ -67,66 +43,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core", - "bitflags 1.3.2", - "bytes", - "futures-util", - "http", - "http-body", - "hyper", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper", - "tower", - "tower-layer", - "tower-service", -] - -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http", - "http-body", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "base16ct" version = "0.2.0" @@ -139,18 +55,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64ct" version = "1.6.0" @@ -175,12 +79,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" - [[package]] name = "block-buffer" version = "0.9.0" @@ -217,18 +115,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cardano-serialization-lib" version = "12.0.0-alpha.30" @@ -281,15 +167,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "num-traits", -] - [[package]] name = "clear_on_drop" version = "0.2.5" @@ -305,7 +182,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -457,28 +334,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "equivalent" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "fastrand" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" - [[package]] name = "ff" version = "0.13.0" @@ -489,12 +344,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "fixedbitset" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" - [[package]] name = "flat-rs" version = "0.0.27" @@ -505,57 +354,12 @@ dependencies = [ "thiserror", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-core", - "futures-task", - "pin-project-lite", - "pin-utils", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -580,12 +384,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - [[package]] name = "glob" version = "0.3.1" @@ -603,25 +401,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "h2" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap 2.2.6", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "half" version = "1.8.3" @@ -679,85 +458,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" - -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-timeout" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" -dependencies = [ - "hyper", - "pin-project-lite", - "tokio", - "tokio-io-timeout", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -768,16 +468,6 @@ dependencies = [ "hashbrown 0.12.3", ] -[[package]] -name = "indexmap" -version = "2.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" -dependencies = [ - "equivalent", - "hashbrown 0.14.5", -] - [[package]] name = "itertools" version = "0.10.5" @@ -825,42 +515,18 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - [[package]] name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" -[[package]] -name = "matchit" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" - -[[package]] -name = "memchr" -version = "2.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" - [[package]] name = "miette" version = "5.10.0" @@ -884,12 +550,6 @@ dependencies = [ "syn 2.0.65", ] -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - [[package]] name = "minicbor" version = "0.18.0" @@ -932,32 +592,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "miniz_oxide" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" -dependencies = [ - "adler", -] - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "multimap" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" - [[package]] name = "noop_proc_macro" version = "0.3.0" @@ -1058,15 +692,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -1079,23 +704,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pallas" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d414da3cb1cdddd5a11ae11ddbdbd0be42917619e18ea8ddfc942ce564177207" -dependencies = [ - "pallas-addresses 0.22.0", - "pallas-applying", - "pallas-codec 0.22.0", - "pallas-configs", - "pallas-crypto 0.22.0", - "pallas-network", - "pallas-primitives 0.22.0", - "pallas-traverse 0.22.0", - "pallas-utxorpc", -] - [[package]] name = "pallas-addresses" version = "0.16.0" @@ -1126,21 +734,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "pallas-applying" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0bda8d2f978d1482470484d3efcd1a029d9a1f560bb75e32a7a67539e68c58" -dependencies = [ - "hex", - "pallas-addresses 0.22.0", - "pallas-codec 0.22.0", - "pallas-crypto 0.22.0", - "pallas-primitives 0.22.0", - "pallas-traverse 0.22.0", - "rand", -] - [[package]] name = "pallas-codec" version = "0.16.0" @@ -1165,21 +758,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "pallas-configs" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6aa7902aefb3fd30f04a345be664df3a36af8a5be38efc55027ef8e2536e69" -dependencies = [ - "base64 0.21.7", - "hex", - "pallas-addresses 0.22.0", - "pallas-codec 0.22.0", - "pallas-crypto 0.22.0", - "serde", - "serde_json", -] - [[package]] name = "pallas-crypto" version = "0.16.0" @@ -1208,24 +786,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "pallas-network" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc07ddecbb424ebf1e23ad5202442a7ae7c3cb909eb375c65a57f9acc521665a" -dependencies = [ - "byteorder", - "hex", - "itertools", - "pallas-codec 0.22.0", - "pallas-crypto 0.22.0", - "rand", - "socket2", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "pallas-primitives" version = "0.16.0" @@ -1288,18 +848,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "pallas-utxorpc" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9547f8ada5e3d89894e89a1a372e75b61c526b7081ca1962f39ea264180d2778" -dependencies = [ - "pallas-codec 0.22.0", - "pallas-primitives 0.22.0", - "pallas-traverse 0.22.0", - "utxorpc", -] - [[package]] name = "paste" version = "1.0.15" @@ -1307,50 +855,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] -name = "pbjson" -version = "0.5.1" +name = "peg" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "048f9ac93c1eab514f9470c4bc8d97ca2a0a236b84f45cc19d69a59fc11467f6" +checksum = "8a625d12ad770914cbf7eff6f9314c3ef803bfe364a1b20bc36ddf56673e71e5" dependencies = [ - "base64 0.13.1", - "serde", -] - -[[package]] -name = "pbjson-build" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdbb7b706f2afc610f3853550cdbbf6372fd324824a087806bd4480ea4996e24" -dependencies = [ - "heck", - "itertools", - "prost", - "prost-types", -] - -[[package]] -name = "pbjson-types" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a88c8d87f99a4ac14325e7a4c24af190fca261956e3b82dd7ed67e77e6c7043" -dependencies = [ - "bytes", - "chrono", - "pbjson", - "pbjson-build", - "prost", - "prost-build", - "serde", -] - -[[package]] -name = "peg" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a625d12ad770914cbf7eff6f9314c3ef803bfe364a1b20bc36ddf56673e71e5" -dependencies = [ - "peg-macros", - "peg-runtime", + "peg-macros", + "peg-runtime", ] [[package]] @@ -1370,54 +881,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3aeb8f54c078314c2065ee649a7241f46b9d8e418e1a9581ba0546657d7aa3a" -[[package]] -name = "percent-encoding" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" - -[[package]] -name = "petgraph" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" -dependencies = [ - "fixedbitset", - "indexmap 2.2.6", -] - -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.65", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "pkcs8" version = "0.10.2" @@ -1456,16 +919,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "prettyplease" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" -dependencies = [ - "proc-macro2", - "syn 1.0.109", -] - [[package]] name = "proc-macro2" version = "1.0.83" @@ -1475,60 +928,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prost" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-build" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" -dependencies = [ - "bytes", - "heck", - "itertools", - "lazy_static", - "log", - "multimap", - "petgraph", - "prettyplease", - "prost", - "prost-types", - "regex", - "syn 1.0.109", - "tempfile", - "which", -] - -[[package]] -name = "prost-derive" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" -dependencies = [ - "anyhow", - "itertools", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "prost-types" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" -dependencies = [ - "prost", -] - [[package]] name = "quote" version = "1.0.36" @@ -1607,35 +1006,6 @@ dependencies = [ "rand_core 0.3.1", ] -[[package]] -name = "regex" -version = "1.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" - [[package]] name = "rfc6979" version = "0.4.0" @@ -1646,25 +1016,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - -[[package]] -name = "rustix" -version = "0.38.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "rustversion" version = "1.0.17" @@ -1833,7 +1184,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.5.4" +version = "0.5.5" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -1865,25 +1216,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "spki" version = "0.7.3" @@ -1941,24 +1273,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - [[package]] name = "thiserror" version = "1.0.61" @@ -1988,164 +1302,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "pin-project-lite", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.65", -] - -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tokio-util" -version = "0.7.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tonic" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" -dependencies = [ - "async-trait", - "axum", - "base64 0.21.7", - "bytes", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", - "percent-encoding", - "pin-project", - "prost", - "tokio", - "tokio-stream", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "indexmap 1.9.3", - "pin-project", - "pin-project-lite", - "rand", - "slab", - "tokio", - "tokio-util", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-layer" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" - -[[package]] -name = "tower-service" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.65", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "typed-arena" version = "2.0.2" @@ -2186,7 +1342,7 @@ dependencies = [ "cryptoxide", "flat-rs", "hex", - "indexmap 1.9.3", + "indexmap", "itertools", "num-bigint", "num-integer", @@ -2209,14 +1365,14 @@ dependencies = [ [[package]] name = "uplc" -version = "1.0.26-alpha" +version = "1.0.29-alpha" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c318172974a4c190197ffdb7070fe8d59a0637becc7d6347513a02375178e821" +checksum = "def463ac61b58bc4d91b2b45ada0bb283111dd7b134d89d191429e7062199b94" dependencies = [ "blst", "cryptoxide", "hex", - "indexmap 1.9.3", + "indexmap", "itertools", "k256", "miette", @@ -2224,8 +1380,11 @@ dependencies = [ "num-integer", "num-traits", "once_cell", - "pallas", + "pallas-addresses 0.22.0", "pallas-codec 0.22.0", + "pallas-crypto 0.22.0", + "pallas-primitives 0.22.0", + "pallas-traverse 0.22.0", "peg", "pretty", "secp256k1", @@ -2236,59 +1395,12 @@ dependencies = [ "thiserror", ] -[[package]] -name = "utxorpc" -version = "1.0.0-alpha.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1841467f5ca405d4e878be56e1a8c8ae1f6f62b50984988027f6b4859d36c0" -dependencies = [ - "utxorpc-spec-cardano", - "utxorpc-spec-sync", -] - -[[package]] -name = "utxorpc-spec-cardano" -version = "1.0.0-alpha.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb1a8c03aef60aa154ae04fe871c9a6fab18c99f468f0ddc096e45c21c5b6814" -dependencies = [ - "bytes", - "pbjson", - "pbjson-types", - "prost", - "serde", -] - -[[package]] -name = "utxorpc-spec-sync" -version = "1.0.0-alpha.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f7ab73d37f96892e16a5c89f9aa430b9efdcaa5f2a0259a87f99a2eb732ea0" -dependencies = [ - "bytes", - "pbjson", - "pbjson-types", - "prost", - "serde", - "tonic", - "utxorpc-spec-cardano", -] - [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2373,21 +1485,9 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - [[package]] name = "whisky" -version = "0.5.4" +version = "0.5.5" dependencies = [ "async-trait", "cardano-serialization-lib", @@ -2403,7 +1503,7 @@ dependencies = [ "serde-wasm-bindgen 0.6.5", "serde_json", "sidan-csl-rs", - "uplc 1.0.26-alpha", + "uplc 1.0.29-alpha", "wasm-bindgen", ] @@ -2429,145 +1529,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - [[package]] name = "yansi" version = "0.5.1" diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index 6d29c89..1403e3b 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.4" +version = "0.5.5" 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 132662d..8d4fa6f 100644 --- a/packages/sidan-csl-rs/src/builder/core.rs +++ b/packages/sidan-csl-rs/src/builder/core.rs @@ -1,3 +1,5 @@ +use cardano_serialization_lib::JsError; + use crate::{ core::builder::{IMeshCSL, MeshCSL}, csl, @@ -17,7 +19,7 @@ pub fn js_serialize_tx_body(mesh_tx_builder_body_json: &str, params_json: &str) Err(_) => None, }; - serialize_tx_body(mesh_tx_builder_body, params) + serialize_tx_body(mesh_tx_builder_body, params).unwrap() } /// ## Transaction building method @@ -34,22 +36,28 @@ pub fn js_serialize_tx_body(mesh_tx_builder_body_json: &str, params_json: &str) pub fn serialize_tx_body( mesh_tx_builder_body: MeshTxBuilderBody, params: Option, -) -> String { +) -> Result { let mut mesh_csl = MeshCSL::new(params); - 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()); + 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(), + )?; MeshTxBuilderCore::add_all_reference_inputs( &mut mesh_csl, mesh_tx_builder_body.reference_inputs.clone(), - ); - MeshTxBuilderCore::add_all_withdrawals(&mut mesh_csl, mesh_tx_builder_body.withdrawals.clone()); - MeshTxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone()); + )?; + MeshTxBuilderCore::add_all_withdrawals( + &mut mesh_csl, + mesh_tx_builder_body.withdrawals.clone(), + )?; + MeshTxBuilderCore::add_all_mints(&mut mesh_csl, mesh_tx_builder_body.mints.clone())?; MeshTxBuilderCore::add_all_certificates( &mut mesh_csl, mesh_tx_builder_body.certificates.clone(), - ); + )?; MeshTxBuilderCore::add_validity_range( &mut mesh_csl, mesh_tx_builder_body.validity_range.clone(), @@ -57,10 +65,10 @@ pub fn serialize_tx_body( MeshTxBuilderCore::add_all_required_signature( &mut mesh_csl, mesh_tx_builder_body.required_signatures.clone(), - ); - MeshTxBuilderCore::add_all_metadata(&mut mesh_csl, mesh_tx_builder_body.metadata.clone()); + )?; + MeshTxBuilderCore::add_all_metadata(&mut mesh_csl, mesh_tx_builder_body.metadata.clone())?; - mesh_csl.add_script_hash(); + mesh_csl.add_script_hash()?; // if self.mesh_tx_builder_body.change_address != "" { // let collateral_inputs = self.mesh_tx_builder_body.collaterals.clone(); // let collateral_vec: Vec = collateral_inputs @@ -129,7 +137,7 @@ pub fn serialize_tx_body( mesh_csl.add_change( mesh_tx_builder_body.change_address.clone(), mesh_tx_builder_body.change_datum.clone(), - ); + )?; mesh_csl.build_tx() } @@ -171,86 +179,104 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { } } - fn add_all_inputs(mesh_csl: &mut MeshCSL, inputs: Vec) { + fn add_all_inputs(mesh_csl: &mut MeshCSL, inputs: Vec) -> Result<(), JsError> { for input in inputs { match input { - TxIn::PubKeyTxIn(pub_key_tx_in) => mesh_csl.add_tx_in(pub_key_tx_in), - TxIn::ScriptTxIn(script_tx_in) => mesh_csl.add_script_tx_in(script_tx_in), + TxIn::PubKeyTxIn(pub_key_tx_in) => mesh_csl.add_tx_in(pub_key_tx_in)?, + TxIn::ScriptTxIn(script_tx_in) => mesh_csl.add_script_tx_in(script_tx_in)?, }; } mesh_csl.tx_builder.set_inputs(&mesh_csl.tx_inputs_builder); + Ok(()) } - fn add_all_outputs(mesh_csl: &mut MeshCSL, outputs: Vec) { + fn add_all_outputs(mesh_csl: &mut MeshCSL, outputs: Vec) -> Result<(), JsError> { for output in outputs { - mesh_csl.add_output(output); + mesh_csl.add_output(output)?; } + Ok(()) } - fn add_all_collaterals(mesh_csl: &mut MeshCSL, collaterals: Vec) { + fn add_all_collaterals( + mesh_csl: &mut MeshCSL, + collaterals: Vec, + ) -> Result<(), JsError> { let mut collateral_builder = csl::TxInputsBuilder::new(); for collateral in collaterals { - mesh_csl.add_collateral(&mut collateral_builder, collateral) + mesh_csl.add_collateral(&mut collateral_builder, collateral)? } - mesh_csl.tx_builder.set_collateral(&collateral_builder) + mesh_csl.tx_builder.set_collateral(&collateral_builder); + Ok(()) } - fn add_all_reference_inputs(mesh_csl: &mut MeshCSL, ref_inputs: Vec) { + fn add_all_reference_inputs( + mesh_csl: &mut MeshCSL, + ref_inputs: Vec, + ) -> Result<(), JsError> { for ref_input in ref_inputs { - mesh_csl.add_reference_input(ref_input); + mesh_csl.add_reference_input(ref_input)?; } + Ok(()) } - fn add_all_withdrawals(mesh_csl: &mut MeshCSL, withdrawals: Vec) { + fn add_all_withdrawals( + mesh_csl: &mut MeshCSL, + withdrawals: Vec, + ) -> Result<(), JsError> { for withdrawal in withdrawals { match withdrawal { Withdrawal::PubKeyWithdrawal(pub_key_withdrawal) => { - mesh_csl.add_pub_key_withdrawal(pub_key_withdrawal) + mesh_csl.add_pub_key_withdrawal(pub_key_withdrawal)? } Withdrawal::PlutusScriptWithdrawal(plutus_script_withdrawal) => { - mesh_csl.add_plutus_withdrawal(plutus_script_withdrawal) + mesh_csl.add_plutus_withdrawal(plutus_script_withdrawal)? } } } mesh_csl .tx_builder .set_withdrawals_builder(&mesh_csl.tx_withdrawals_builder); + Ok(()) } - fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec) { + fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec) -> Result<(), JsError> { let mut mint_builder = csl::MintBuilder::new(); for (index, mint) in mints.into_iter().enumerate() { match mint.type_.as_str() { - "Plutus" => mesh_csl.add_plutus_mint(&mut mint_builder, mint, index as u64), - "Native" => mesh_csl.add_native_mint(&mut mint_builder, mint), + "Plutus" => mesh_csl.add_plutus_mint(&mut mint_builder, mint, index as u64)?, + "Native" => mesh_csl.add_native_mint(&mut mint_builder, mint)?, _ => {} }; } - mesh_csl.tx_builder.set_mint_builder(&mint_builder) + mesh_csl.tx_builder.set_mint_builder(&mint_builder); + Ok(()) } - fn add_all_certificates(mesh_csl: &mut MeshCSL, certificates: Vec) { + fn add_all_certificates( + mesh_csl: &mut MeshCSL, + certificates: Vec, + ) -> Result<(), JsError> { let mut certificates_builder = csl::CertificatesBuilder::new(); for cert in certificates { match cert { Certificate::RegisterPool(register_pool) => { - mesh_csl.add_register_pool_cert(&mut certificates_builder, register_pool) + mesh_csl.add_register_pool_cert(&mut certificates_builder, register_pool)? } Certificate::RegisterStake(register_stake) => { - mesh_csl.add_register_stake_cert(&mut certificates_builder, register_stake) + mesh_csl.add_register_stake_cert(&mut certificates_builder, register_stake)? } Certificate::DelegateStake(delegate_stake) => { - mesh_csl.add_delegate_stake_cert(&mut certificates_builder, delegate_stake) - } - Certificate::DeregisterStake(deregister_stake) => { - mesh_csl.add_deregister_stake_cert(&mut certificates_builder, deregister_stake) + mesh_csl.add_delegate_stake_cert(&mut certificates_builder, delegate_stake)? } + Certificate::DeregisterStake(deregister_stake) => mesh_csl + .add_deregister_stake_cert(&mut certificates_builder, deregister_stake)?, Certificate::RetirePool(retire_pool) => { - mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool) + mesh_csl.add_retire_pool_cert(&mut certificates_builder, retire_pool)? } } } - mesh_csl.tx_builder.set_certs_builder(&certificates_builder) + mesh_csl.tx_builder.set_certs_builder(&certificates_builder); + Ok(()) } fn add_validity_range(mesh_csl: &mut MeshCSL, validity_range: ValidityRange) { @@ -262,16 +288,24 @@ impl IMeshTxBuilderCore for MeshTxBuilderCore { } } - fn add_all_required_signature(mesh_csl: &mut MeshCSL, required_signatures: JsVecString) { + fn add_all_required_signature( + mesh_csl: &mut MeshCSL, + required_signatures: JsVecString, + ) -> Result<(), JsError> { for pub_key_hash in required_signatures { - mesh_csl.add_required_signature(pub_key_hash); + mesh_csl.add_required_signature(pub_key_hash)?; } + Ok(()) } - fn add_all_metadata(mesh_csl: &mut MeshCSL, all_metadata: Vec) { + fn add_all_metadata( + mesh_csl: &mut MeshCSL, + all_metadata: Vec, + ) -> Result<(), JsError> { for metadata in all_metadata { - mesh_csl.add_metadata(metadata); + mesh_csl.add_metadata(metadata)?; } + Ok(()) } // fn add_collateral_return(&mut self, change_address: String) { diff --git a/packages/sidan-csl-rs/src/builder/interface.rs b/packages/sidan-csl-rs/src/builder/interface.rs index 578b1a0..fe752cd 100644 --- a/packages/sidan-csl-rs/src/builder/interface.rs +++ b/packages/sidan-csl-rs/src/builder/interface.rs @@ -1,3 +1,5 @@ +use cardano_serialization_lib::JsError; + use crate::{core::builder::MeshCSL, model::*}; pub struct MeshTxBuilderCore { @@ -44,7 +46,7 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `inputs` - A vector of inputs - fn add_all_inputs(mesh_csl: &mut MeshCSL, inputs: Vec); + fn add_all_inputs(mesh_csl: &mut MeshCSL, inputs: Vec) -> Result<(), JsError>; /// ## Internal method /// @@ -54,7 +56,7 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `outputs` - A vector of outputs - fn add_all_outputs(mesh_csl: &mut MeshCSL, outputs: Vec); + fn add_all_outputs(mesh_csl: &mut MeshCSL, outputs: Vec) -> Result<(), JsError>; /// ## Internal method /// @@ -64,7 +66,10 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `collaterals` - A vector of collaterals - fn add_all_collaterals(mesh_csl: &mut MeshCSL, collaterals: Vec); + fn add_all_collaterals( + mesh_csl: &mut MeshCSL, + collaterals: Vec, + ) -> Result<(), JsError>; /// ## Internal method /// @@ -74,7 +79,10 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `ref_inputs` - A vector of reference inputs - fn add_all_reference_inputs(mesh_csl: &mut MeshCSL, ref_inputs: Vec); + fn add_all_reference_inputs( + mesh_csl: &mut MeshCSL, + ref_inputs: Vec, + ) -> Result<(), JsError>; /// ## Internal method /// @@ -84,7 +92,10 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `withdrawals` - A vector of withdrawals - fn add_all_withdrawals(mesh_csl: &mut MeshCSL, withdrawals: Vec); + fn add_all_withdrawals( + mesh_csl: &mut MeshCSL, + withdrawals: Vec, + ) -> Result<(), JsError>; /// ## Internal method /// @@ -94,7 +105,7 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `mints` - A vector of mints - fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec); + fn add_all_mints(mesh_csl: &mut MeshCSL, mints: Vec) -> Result<(), JsError>; /// ## Internal method /// @@ -104,7 +115,10 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `certificates` - A vector of certificates - fn add_all_certificates(mesh_csl: &mut MeshCSL, certificates: Vec); + fn add_all_certificates( + mesh_csl: &mut MeshCSL, + certificates: Vec, + ) -> Result<(), JsError>; /// ## Internal method /// @@ -124,7 +138,10 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `required_signatures` - A vector of required signatures - fn add_all_required_signature(mesh_csl: &mut MeshCSL, required_signatures: JsVecString); + fn add_all_required_signature( + mesh_csl: &mut MeshCSL, + required_signatures: JsVecString, + ) -> Result<(), JsError>; /// ## Internal method /// @@ -134,5 +151,6 @@ pub trait IMeshTxBuilderCore { /// /// * `mesh_csl` - The MeshCSL instance /// * `all_metadata` - A vector of metadata - fn add_all_metadata(mesh_csl: &mut MeshCSL, all_metadata: Vec); + fn add_all_metadata(mesh_csl: &mut MeshCSL, all_metadata: Vec) + -> Result<(), JsError>; } diff --git a/packages/sidan-csl-rs/src/core/builder.rs b/packages/sidan-csl-rs/src/core/builder.rs index 0ac0efc..eebcf9f 100644 --- a/packages/sidan-csl-rs/src/core/builder.rs +++ b/packages/sidan-csl-rs/src/core/builder.rs @@ -1,57 +1,72 @@ use std::net::{Ipv4Addr, Ipv6Addr}; +use cardano_serialization_lib::JsError; + use crate::{csl, model::*}; use super::{utils::build_tx_builder, utils::sign_transaction, utils::to_bignum, utils::to_value}; pub trait IMeshCSL { fn new(params: Option) -> Self; - fn add_tx_in(&mut self, input: PubKeyTxIn); - fn add_script_tx_in(&mut self, input: ScriptTxIn); - fn add_output(&mut self, output: Output); + fn add_tx_in(&mut self, input: PubKeyTxIn) -> Result<(), JsError>; + fn add_script_tx_in(&mut self, input: ScriptTxIn) -> Result<(), JsError>; + fn add_output(&mut self, output: Output) -> Result<(), JsError>; fn add_collateral( &mut self, collateral_builder: &mut csl::TxInputsBuilder, collateral: PubKeyTxIn, - ); - fn add_reference_input(&mut self, ref_input: RefTxIn); - fn add_pub_key_withdrawal(&mut self, withdrawal: PubKeyWithdrawal); - fn add_plutus_withdrawal(&mut self, withdrawal: PlutusScriptWithdrawal); - fn add_plutus_mint(&mut self, mint_builder: &mut csl::MintBuilder, mint: MintItem, index: u64); - fn add_native_mint(&mut self, mint_builder: &mut csl::MintBuilder, mint: MintItem); + ) -> Result<(), JsError>; + fn add_reference_input(&mut self, ref_input: RefTxIn) -> Result<(), JsError>; + fn add_pub_key_withdrawal(&mut self, withdrawal: PubKeyWithdrawal) -> Result<(), JsError>; + fn add_plutus_withdrawal(&mut self, withdrawal: PlutusScriptWithdrawal) -> Result<(), JsError>; + fn add_plutus_mint( + &mut self, + mint_builder: &mut csl::MintBuilder, + mint: MintItem, + index: u64, + ) -> Result<(), JsError>; + fn add_native_mint( + &mut self, + mint_builder: &mut csl::MintBuilder, + mint: MintItem, + ) -> Result<(), JsError>; fn add_register_pool_cert( &mut self, certificate_builder: &mut csl::CertificatesBuilder, register_pool: RegisterPool, - ); + ) -> Result<(), JsError>; fn add_register_stake_cert( &mut self, certificate_builder: &mut csl::CertificatesBuilder, register_stake: RegisterStake, - ); + ) -> Result<(), JsError>; fn add_delegate_stake_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, delegate_stake: DelegateStake, - ); + ) -> Result<(), JsError>; fn add_deregister_stake_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, deregister_stake: DeregisterStake, - ); + ) -> Result<(), JsError>; fn add_retire_pool_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, retire_pool: RetirePool, - ); + ) -> Result<(), JsError>; fn add_invalid_before(&mut self, invalid_before: u64); fn add_invalid_hereafter(&mut self, invalid_hereafter: u64); - fn add_change(&mut self, change_address: String, change_datum: Option); + fn add_change( + &mut self, + change_address: String, + change_datum: Option, + ) -> Result<(), JsError>; fn add_signing_keys(&mut self, signing_keys: JsVecString); - fn add_required_signature(&mut self, pub_key_hash: String); - fn add_metadata(&mut self, metadata: Metadata); - fn add_script_hash(&mut self); - fn build_tx(&mut self) -> String; + fn add_required_signature(&mut self, pub_key_hash: String) -> Result<(), JsError>; + fn add_metadata(&mut self, metadata: Metadata) -> Result<(), JsError>; + fn add_script_hash(&mut self) -> Result<(), JsError>; + fn build_tx(&mut self) -> Result; } pub struct MeshCSL { @@ -71,31 +86,29 @@ impl IMeshCSL for MeshCSL { } } - fn add_tx_in(&mut self, input: PubKeyTxIn) { - self.tx_inputs_builder - .add_regular_input( - &csl::Address::from_bech32(&input.tx_in.address.unwrap()).unwrap(), - &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&input.tx_in.tx_hash).unwrap(), - input.tx_in.tx_index, - ), - &to_value(&input.tx_in.amount.unwrap()), - ) - .unwrap(); + fn add_tx_in(&mut self, input: PubKeyTxIn) -> Result<(), JsError> { + self.tx_inputs_builder.add_regular_input( + &csl::Address::from_bech32(&input.tx_in.address.unwrap())?, + &csl::TransactionInput::new( + &csl::TransactionHash::from_hex(&input.tx_in.tx_hash)?, + input.tx_in.tx_index, + ), + &to_value(&input.tx_in.amount.unwrap()), + )?; + Ok(()) } - fn add_script_tx_in(&mut self, input: ScriptTxIn) { + fn add_script_tx_in(&mut self, input: ScriptTxIn) -> Result<(), JsError> { let datum_source = input.script_tx_in.datum_source.unwrap(); let script_source = input.script_tx_in.script_source.unwrap(); let redeemer = input.script_tx_in.redeemer.unwrap(); let csl_datum: csl::DatumSource = match datum_source { DatumSource::ProvidedDatumSource(datum) => csl::DatumSource::new( - &csl::PlutusData::from_json(&datum.data, csl::PlutusDatumSchema::DetailedSchema) - .unwrap(), + &csl::PlutusData::from_json(&datum.data, csl::PlutusDatumSchema::DetailedSchema)?, ), DatumSource::InlineDatumSource(datum) => { let ref_input = csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&datum.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&datum.tx_hash)?, datum.tx_index, ); csl::DatumSource::new_ref_input(&ref_input) @@ -109,13 +122,10 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V2 => csl::Language::new_plutus_v2(), LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; - csl::PlutusScriptSource::new( - &csl::PlutusScript::from_hex_with_version( - &script.script_cbor, - &language_version, - ) - .unwrap(), - ) + csl::PlutusScriptSource::new(&csl::PlutusScript::from_hex_with_version( + &script.script_cbor, + &language_version, + )?) } ScriptSource::InlineScriptSource(script) => { let language_version: csl::Language = match script.language_version { @@ -124,9 +134,9 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; csl::PlutusScriptSource::new_ref_input( - &csl::ScriptHash::from_hex(&script.spending_script_hash).unwrap(), + &csl::ScriptHash::from_hex(&script.spending_script_hash)?, &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&script.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&script.tx_hash)?, script.tx_index, ), &language_version, @@ -138,8 +148,7 @@ impl IMeshCSL for MeshCSL { let csl_redeemer: csl::Redeemer = csl::Redeemer::new( &csl::RedeemerTag::new_spend(), &to_bignum(0), - &csl::PlutusData::from_json(&redeemer.data, csl::PlutusDatumSchema::DetailedSchema) - .unwrap(), + &csl::PlutusData::from_json(&redeemer.data, csl::PlutusDatumSchema::DetailedSchema)?, &csl::ExUnits::new( &to_bignum(redeemer.ex_units.mem), &to_bignum(redeemer.ex_units.steps), @@ -148,16 +157,17 @@ impl IMeshCSL for MeshCSL { self.tx_inputs_builder.add_plutus_script_input( &csl::PlutusWitness::new_with_ref(&csl_script, &csl_datum, &csl_redeemer), &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&input.tx_in.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&input.tx_in.tx_hash)?, input.tx_in.tx_index, ), &to_value(&input.tx_in.amount.unwrap()), - ) + ); + Ok(()) } - fn add_output(&mut self, output: Output) { + fn add_output(&mut self, output: Output) -> Result<(), JsError> { let mut output_builder = csl::TransactionOutputBuilder::new() - .with_address(&csl::Address::from_bech32(&output.address).unwrap()); + .with_address(&csl::Address::from_bech32(&output.address)?); if output.datum.is_some() { let datum = output.datum.unwrap(); @@ -167,18 +177,14 @@ impl IMeshCSL for MeshCSL { &csl::PlutusData::from_json( &datum.data, csl::PlutusDatumSchema::DetailedSchema, - ) - .unwrap(), + )?, )); } "Inline" => { - output_builder = output_builder.with_plutus_data( - &csl::PlutusData::from_json( - &datum.data, - csl::PlutusDatumSchema::DetailedSchema, - ) - .unwrap(), - ); + output_builder = output_builder.with_plutus_data(&csl::PlutusData::from_json( + &datum.data, + csl::PlutusDatumSchema::DetailedSchema, + )?); } _ => {} }; @@ -195,73 +201,67 @@ impl IMeshCSL for MeshCSL { &csl::PlutusScript::from_hex_with_version( &output_script.script_cbor, &language_version, - ) - .unwrap(), + )?, )) } let tx_value = to_value(&output.amount); - let amount_builder = output_builder.next().unwrap(); + let amount_builder = output_builder.next()?; let built_output: csl::TransactionOutput = if tx_value.multiasset().is_some() { if tx_value.coin().is_zero() { amount_builder .with_asset_and_min_required_coin_by_utxo_cost( &tx_value.multiasset().unwrap(), &csl::DataCost::new_coins_per_byte(&to_bignum(4310)), - ) - .unwrap() - .build() - .unwrap() + )? + .build()? } else { amount_builder .with_coin_and_asset(&tx_value.coin(), &tx_value.multiasset().unwrap()) - .build() - .unwrap() + .build()? } } else { - amount_builder.with_coin(&tx_value.coin()).build().unwrap() + amount_builder.with_coin(&tx_value.coin()).build()? }; - self.tx_builder.add_output(&built_output).unwrap(); + self.tx_builder.add_output(&built_output)?; + Ok(()) } fn add_collateral( &mut self, collateral_builder: &mut csl::TxInputsBuilder, collateral: PubKeyTxIn, - ) { - collateral_builder - .add_regular_input( - &csl::Address::from_bech32(&collateral.tx_in.address.unwrap()).unwrap(), - &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&collateral.tx_in.tx_hash).unwrap(), - collateral.tx_in.tx_index, - ), - &to_value(&collateral.tx_in.amount.unwrap()), - ) - .unwrap(); + ) -> Result<(), JsError> { + collateral_builder.add_regular_input( + &csl::Address::from_bech32(&collateral.tx_in.address.unwrap())?, + &csl::TransactionInput::new( + &csl::TransactionHash::from_hex(&collateral.tx_in.tx_hash)?, + collateral.tx_in.tx_index, + ), + &to_value(&collateral.tx_in.amount.unwrap()), + )?; + Ok(()) } - fn add_reference_input(&mut self, ref_input: RefTxIn) { + fn add_reference_input(&mut self, ref_input: RefTxIn) -> Result<(), JsError> { let csl_ref_input = csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&ref_input.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&ref_input.tx_hash)?, ref_input.tx_index, ); self.tx_builder.add_reference_input(&csl_ref_input); + Ok(()) } - fn add_pub_key_withdrawal(&mut self, withdrawal: PubKeyWithdrawal) { - self.tx_withdrawals_builder - .add( - &csl::RewardAddress::from_address( - &csl::Address::from_bech32(&withdrawal.address).unwrap(), - ) + fn add_pub_key_withdrawal(&mut self, withdrawal: PubKeyWithdrawal) -> Result<(), JsError> { + self.tx_withdrawals_builder.add( + &csl::RewardAddress::from_address(&csl::Address::from_bech32(&withdrawal.address)?) .unwrap(), - &csl::BigNum::from_str(&withdrawal.coin.to_string()).unwrap(), - ) - .unwrap(); + &csl::BigNum::from_str(&withdrawal.coin.to_string())?, + )?; + Ok(()) } - fn add_plutus_withdrawal(&mut self, withdrawal: PlutusScriptWithdrawal) { + fn add_plutus_withdrawal(&mut self, withdrawal: PlutusScriptWithdrawal) -> Result<(), JsError> { let script_source = withdrawal.script_source.unwrap(); let redeemer = withdrawal.redeemer.unwrap(); @@ -272,13 +272,10 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V2 => csl::Language::new_plutus_v2(), LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; - csl::PlutusScriptSource::new( - &csl::PlutusScript::from_hex_with_version( - &script.script_cbor, - &language_version, - ) - .unwrap(), - ) + csl::PlutusScriptSource::new(&csl::PlutusScript::from_hex_with_version( + &script.script_cbor, + &language_version, + )?) } ScriptSource::InlineScriptSource(script) => { let language_version: csl::Language = match script.language_version { @@ -287,9 +284,9 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; csl::PlutusScriptSource::new_ref_input( - &csl::ScriptHash::from_hex(&script.spending_script_hash).unwrap(), + &csl::ScriptHash::from_hex(&script.spending_script_hash)?, &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&script.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&script.tx_hash)?, script.tx_index, ), &language_version, @@ -301,27 +298,28 @@ impl IMeshCSL for MeshCSL { let csl_redeemer: csl::Redeemer = csl::Redeemer::new( &csl::RedeemerTag::new_spend(), &to_bignum(0), - &csl::PlutusData::from_json(&redeemer.data, csl::PlutusDatumSchema::DetailedSchema) - .unwrap(), + &csl::PlutusData::from_json(&redeemer.data, csl::PlutusDatumSchema::DetailedSchema)?, &csl::ExUnits::new( &to_bignum(redeemer.ex_units.mem), &to_bignum(redeemer.ex_units.steps), ), ); - self.tx_withdrawals_builder - .add_with_plutus_witness( - &csl::RewardAddress::from_address( - &csl::Address::from_bech32(&withdrawal.address).unwrap(), - ) + self.tx_withdrawals_builder.add_with_plutus_witness( + &csl::RewardAddress::from_address(&csl::Address::from_bech32(&withdrawal.address)?) .unwrap(), - &csl::BigNum::from_str(&withdrawal.coin.to_string()).unwrap(), - &csl::PlutusWitness::new_with_ref_without_datum(&csl_script, &csl_redeemer), - ) - .unwrap(); + &csl::BigNum::from_str(&withdrawal.coin.to_string())?, + &csl::PlutusWitness::new_with_ref_without_datum(&csl_script, &csl_redeemer), + )?; + Ok(()) } - fn add_plutus_mint(&mut self, mint_builder: &mut csl::MintBuilder, mint: MintItem, index: u64) { + fn add_plutus_mint( + &mut self, + mint_builder: &mut csl::MintBuilder, + mint: MintItem, + index: u64, + ) -> Result<(), JsError> { let redeemer_info = mint.redeemer.unwrap(); let mint_redeemer = csl::Redeemer::new( &csl::RedeemerTag::new_mint(), @@ -329,8 +327,7 @@ impl IMeshCSL for MeshCSL { &csl::PlutusData::from_json( &redeemer_info.data, csl::PlutusDatumSchema::DetailedSchema, - ) - .unwrap(), + )?, &csl::ExUnits::new( &to_bignum(redeemer_info.ex_units.mem), &to_bignum(redeemer_info.ex_units.steps), @@ -345,9 +342,9 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; csl::PlutusScriptSource::new_ref_input( - &csl::ScriptHash::from_hex(mint.policy_id.as_str()).unwrap(), + &csl::ScriptHash::from_hex(mint.policy_id.as_str())?, &csl::TransactionInput::new( - &csl::TransactionHash::from_hex(&script.tx_hash).unwrap(), + &csl::TransactionHash::from_hex(&script.tx_hash)?, script.tx_index, ), &language_version, @@ -360,48 +357,47 @@ impl IMeshCSL for MeshCSL { LanguageVersion::V2 => csl::Language::new_plutus_v2(), LanguageVersion::V3 => csl::Language::new_plutus_v3(), }; - csl::PlutusScriptSource::new( - &csl::PlutusScript::from_hex_with_version( - script.script_cbor.as_str(), - &language_version, - ) - .unwrap(), - ) + csl::PlutusScriptSource::new(&csl::PlutusScript::from_hex_with_version( + script.script_cbor.as_str(), + &language_version, + )?) } }; - mint_builder - .add_asset( - &csl::MintWitness::new_plutus_script(&mint_script, &mint_redeemer), - &csl::AssetName::new(hex::decode(mint.asset_name).unwrap()).unwrap(), - &csl::Int::new_i32(mint.amount.try_into().unwrap()), - ) - .unwrap(); + mint_builder.add_asset( + &csl::MintWitness::new_plutus_script(&mint_script, &mint_redeemer), + &csl::AssetName::new(hex::decode(mint.asset_name).unwrap())?, + &csl::Int::new_i32(mint.amount.try_into().unwrap()), + )?; + Ok(()) } - fn add_native_mint(&mut self, mint_builder: &mut csl::MintBuilder, mint: MintItem) { + fn add_native_mint( + &mut self, + mint_builder: &mut csl::MintBuilder, + mint: MintItem, + ) -> Result<(), JsError> { let script_info = mint.script_source.unwrap(); match script_info { - ScriptSource::ProvidedScriptSource(script) => mint_builder - .add_asset( - &csl::MintWitness::new_native_script(&csl::NativeScriptSource::new( - &csl::NativeScript::from_hex(&script.script_cbor).unwrap(), - )), - &csl::AssetName::new(hex::decode(mint.asset_name).unwrap()).unwrap(), - &csl::Int::new_i32(mint.amount.try_into().unwrap()), - ) - .unwrap(), + ScriptSource::ProvidedScriptSource(script) => mint_builder.add_asset( + &csl::MintWitness::new_native_script(&csl::NativeScriptSource::new( + &csl::NativeScript::from_hex(&script.script_cbor)?, + )), + &csl::AssetName::new(hex::decode(mint.asset_name).unwrap())?, + &csl::Int::new_i32(mint.amount.try_into().unwrap()), + )?, ScriptSource::InlineScriptSource(_) => {} // Err(csl::JsError::from_str( // "Native scripts cannot be referenced", // )), }; + Ok(()) } fn add_register_pool_cert( &mut self, certificate_builder: &mut csl::CertificatesBuilder, register_pool: RegisterPool, - ) { + ) -> Result<(), JsError> { let mut relays = csl::Relays::new(); for relay in register_pool.pool_params.relays { match relay { @@ -430,12 +426,12 @@ impl IMeshCSL for MeshCSL { Relay::SingleHostName(single_host_name_relay) => relays.add( &csl::Relay::new_single_host_name(&csl::SingleHostName::new( single_host_name_relay.port, - &csl::DNSRecordAorAAAA::new(single_host_name_relay.domain_name).unwrap(), + &csl::DNSRecordAorAAAA::new(single_host_name_relay.domain_name)?, )), ), Relay::MultiHostName(multi_host_name_relay) => { relays.add(&csl::Relay::new_multi_host_name(&csl::MultiHostName::new( - &csl::DNSRecordSRV::new(multi_host_name_relay.domain_name).unwrap(), + &csl::DNSRecordSRV::new(multi_host_name_relay.domain_name)?, ))) } } @@ -443,98 +439,90 @@ impl IMeshCSL for MeshCSL { let mut pool_owners = csl::Ed25519KeyHashes::new(); for owner in register_pool.pool_params.owners { - pool_owners.add(&csl::Ed25519KeyHash::from_hex(&owner).unwrap()); + pool_owners.add(&csl::Ed25519KeyHash::from_hex(&owner)?); } - certificate_builder - .add(&csl::Certificate::new_pool_registration( - &csl::PoolRegistration::new(&csl::PoolParams::new( - &csl::Ed25519KeyHash::from_hex(®ister_pool.pool_params.operator).unwrap(), - &csl::VRFKeyHash::from_hex(®ister_pool.pool_params.vrf_key_hash).unwrap(), - &csl::BigNum::from_str(®ister_pool.pool_params.pledge).unwrap(), - &csl::BigNum::from_str(®ister_pool.pool_params.cost).unwrap(), - &csl::UnitInterval::new( - &csl::BigNum::from_str(®ister_pool.pool_params.margin.0.to_string()) - .unwrap(), - &csl::BigNum::from_str(®ister_pool.pool_params.margin.1.to_string()) - .unwrap(), - ), - &csl::RewardAddress::from_address( - &csl::Address::from_bech32(®ister_pool.pool_params.reward_address) - .unwrap(), + certificate_builder.add(&csl::Certificate::new_pool_registration( + &csl::PoolRegistration::new(&csl::PoolParams::new( + &csl::Ed25519KeyHash::from_hex(®ister_pool.pool_params.operator)?, + &csl::VRFKeyHash::from_hex(®ister_pool.pool_params.vrf_key_hash)?, + &csl::BigNum::from_str(®ister_pool.pool_params.pledge)?, + &csl::BigNum::from_str(®ister_pool.pool_params.cost)?, + &csl::UnitInterval::new( + &csl::BigNum::from_str(®ister_pool.pool_params.margin.0.to_string())?, + &csl::BigNum::from_str(®ister_pool.pool_params.margin.1.to_string())?, + ), + &csl::RewardAddress::from_address(&csl::Address::from_bech32( + ®ister_pool.pool_params.reward_address, + )?) + .unwrap(), + &pool_owners, + &relays, + register_pool.pool_params.metadata.map(|data| { + csl::PoolMetadata::new( + &csl::URL::new(data.url).unwrap(), + &csl::PoolMetadataHash::from_hex(&data.hash).unwrap(), ) - .unwrap(), - &pool_owners, - &relays, - register_pool.pool_params.metadata.map(|data| { - csl::PoolMetadata::new( - &csl::URL::new(data.url).unwrap(), - &csl::PoolMetadataHash::from_hex(&data.hash).unwrap(), - ) - }), - )), - )) - .unwrap(); + }), + )), + ))?; + Ok(()) } fn add_register_stake_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, register_stake: RegisterStake, - ) { - certificates_builder - .add(&csl::Certificate::new_stake_registration( - &csl::StakeRegistration::new(&csl::Credential::from_keyhash( - &csl::Ed25519KeyHash::from_hex(®ister_stake.stake_key_hash).unwrap(), - )), - )) - .unwrap(); + ) -> Result<(), JsError> { + certificates_builder.add(&csl::Certificate::new_stake_registration( + &csl::StakeRegistration::new(&csl::Credential::from_keyhash( + &csl::Ed25519KeyHash::from_hex(®ister_stake.stake_key_hash)?, + )), + ))?; + Ok(()) } fn add_delegate_stake_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, delegate_stake: DelegateStake, - ) { - certificates_builder - .add(&csl::Certificate::new_stake_delegation( - &csl::StakeDelegation::new( - &csl::Credential::from_keyhash( - &csl::Ed25519KeyHash::from_hex(&delegate_stake.stake_key_hash).unwrap(), - ), - &csl::Ed25519KeyHash::from_hex(&delegate_stake.pool_id).unwrap(), - ), - )) - .unwrap(); + ) -> Result<(), JsError> { + certificates_builder.add(&csl::Certificate::new_stake_delegation( + &csl::StakeDelegation::new( + &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex( + &delegate_stake.stake_key_hash, + )?), + &csl::Ed25519KeyHash::from_hex(&delegate_stake.pool_id)?, + ), + ))?; + Ok(()) } fn add_deregister_stake_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, deregister_stake: DeregisterStake, - ) { - certificates_builder - .add(&csl::Certificate::new_stake_deregistration( - &csl::StakeDeregistration::new(&csl::Credential::from_keyhash( - &csl::Ed25519KeyHash::from_hex(&deregister_stake.stake_key_hash).unwrap(), - )), - )) - .unwrap(); + ) -> Result<(), JsError> { + certificates_builder.add(&csl::Certificate::new_stake_deregistration( + &csl::StakeDeregistration::new(&csl::Credential::from_keyhash( + &csl::Ed25519KeyHash::from_hex(&deregister_stake.stake_key_hash)?, + )), + ))?; + Ok(()) } fn add_retire_pool_cert( &mut self, certificates_builder: &mut csl::CertificatesBuilder, retire_pool: RetirePool, - ) { - certificates_builder - .add(&csl::Certificate::new_pool_retirement( - &csl::PoolRetirement::new( - &csl::Ed25519KeyHash::from_hex(&retire_pool.pool_id).unwrap(), - retire_pool.epoch, - ), - )) - .unwrap(); + ) -> Result<(), JsError> { + certificates_builder.add(&csl::Certificate::new_pool_retirement( + &csl::PoolRetirement::new( + &csl::Ed25519KeyHash::from_hex(&retire_pool.pool_id)?, + retire_pool.epoch, + ), + ))?; + Ok(()) } fn add_invalid_before(&mut self, invalid_before: u64) { @@ -546,55 +534,53 @@ impl IMeshCSL for MeshCSL { self.tx_builder .set_ttl_bignum(&to_bignum(invalid_hereafter)); } - fn add_change(&mut self, change_address: String, change_datum: Option) { + + fn add_change( + &mut self, + change_address: String, + change_datum: Option, + ) -> Result<(), JsError> { if let Some(change_datum) = change_datum { - self.tx_builder - .add_change_if_needed_with_datum( - &csl::Address::from_bech32(&change_address).unwrap(), - &csl::OutputDatum::new_data( - &csl::PlutusData::from_json( - &change_datum.data, - csl::PlutusDatumSchema::DetailedSchema, - ) - .unwrap(), - ), - ) - .unwrap(); + self.tx_builder.add_change_if_needed_with_datum( + &csl::Address::from_bech32(&change_address)?, + &csl::OutputDatum::new_data(&csl::PlutusData::from_json( + &change_datum.data, + csl::PlutusDatumSchema::DetailedSchema, + )?), + )?; } else { self.tx_builder - .add_change_if_needed(&csl::Address::from_bech32(&change_address).unwrap()) - .unwrap(); + .add_change_if_needed(&csl::Address::from_bech32(&change_address)?)?; } + Ok(()) } fn add_signing_keys(&mut self, signing_keys: JsVecString) { self.tx_hex = sign_transaction(self.tx_hex.to_string(), signing_keys); } - fn add_required_signature(&mut self, pub_key_hash: String) { + fn add_required_signature(&mut self, pub_key_hash: String) -> Result<(), JsError> { self.tx_builder - .add_required_signer(&csl::Ed25519KeyHash::from_hex(&pub_key_hash).unwrap()) + .add_required_signer(&csl::Ed25519KeyHash::from_hex(&pub_key_hash)?); + Ok(()) } - fn add_metadata(&mut self, metadata: Metadata) { + fn add_metadata(&mut self, metadata: Metadata) -> Result<(), JsError> { self.tx_builder - .add_json_metadatum( - &csl::BigNum::from_str(&metadata.tag).unwrap(), - metadata.metadata, - ) - .unwrap() + .add_json_metadatum(&csl::BigNum::from_str(&metadata.tag)?, metadata.metadata)?; + Ok(()) } - fn add_script_hash(&mut self) { + fn add_script_hash(&mut self) -> Result<(), JsError> { self.tx_builder - .calc_script_data_hash(&csl::TxBuilderConstants::plutus_vasil_cost_models()) - .unwrap(); + .calc_script_data_hash(&csl::TxBuilderConstants::plutus_vasil_cost_models())?; + Ok(()) } - fn build_tx(&mut self) -> String { + fn build_tx(&mut self) -> Result { let tx = self.tx_builder.build_tx().unwrap(); self.tx_hex = tx.to_hex(); - self.tx_hex.to_string() + Ok(self.tx_hex.to_string()) } } diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index 372e22b..317e4b5 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky" -version = "0.5.4" +version = "0.5.5" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -17,14 +17,14 @@ serde_json = "1.0" cryptoxide = "0.4.4" serde-wasm-bindgen = "0.6.5" async-trait = "0.1.79" -uplc = "=1.0.26-alpha" +uplc = "=1.0.29-alpha" wasm-bindgen = { version = "=0.2.90", features = ["serde-serialize"] } rand_os = "0.1" 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.4", path = "../sidan-csl-rs" } +sidan-csl-rs = { version = "=0.5.5", 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 769d74c..91fb7e7 100644 --- a/packages/whisky/src/builder/core.rs +++ b/packages/whisky/src/builder/core.rs @@ -1,4 +1,5 @@ use async_trait::async_trait; +use cardano_serialization_lib::JsError; use sidan_csl_rs::{ builder::{serialize_tx_body, IMeshTxBuilderCore, MeshTxBuilderCore}, core::{algo::select_utxos, builder::IMeshCSL, utils::build_tx_builder}, @@ -51,8 +52,11 @@ impl IMeshTxBuilder for MeshTxBuilder { }) } - async fn complete(&mut self, customized_tx: Option) -> &mut Self { - self.complete_sync(customized_tx); + async fn complete( + &mut self, + customized_tx: Option, + ) -> Result<&mut Self, JsError> { + self.complete_sync(customized_tx)?; match &self.evaluator { Some(evaluator) => { let tx_evaluation_result = evaluator @@ -72,13 +76,16 @@ impl IMeshTxBuilder for MeshTxBuilder { self.complete_sync(None) } - fn complete_sync(&mut self, customized_tx: Option) -> &mut Self { + fn complete_sync( + &mut self, + customized_tx: Option, + ) -> Result<&mut Self, JsError> { if customized_tx.is_some() { 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); + self.add_utxos_from(self.extra_inputs.clone(), self.selection_threshold)?; } } @@ -107,11 +114,11 @@ impl IMeshTxBuilder for MeshTxBuilder { let tx_hex = serialize_tx_body( self.core.mesh_tx_builder_body.clone(), self.protocol_params.clone(), - ); + )?; self.core.mesh_csl.tx_hex = tx_hex; self.core.mesh_csl.tx_builder = build_tx_builder(None); self.core.mesh_csl.tx_inputs_builder = csl::TxInputsBuilder::new(); - self + Ok(self) } fn complete_signing(&mut self) -> String { @@ -761,7 +768,7 @@ impl IMeshTxBuilder for MeshTxBuilder { } } - fn add_utxos_from(&mut self, extra_inputs: Vec, threshold: u64) { + fn add_utxos_from(&mut self, extra_inputs: Vec, threshold: u64) -> Result<(), JsError> { let mut required_assets = Value::new(); for output in &self.core.mesh_tx_builder_body.outputs { @@ -804,7 +811,7 @@ impl IMeshTxBuilder for MeshTxBuilder { amount: Some(input.output.amount.clone()), address: Some(input.output.address.clone()), }, - }); + })?; self.core .mesh_tx_builder_body .inputs @@ -818,5 +825,6 @@ impl IMeshTxBuilder for MeshTxBuilder { }, })); } + Ok(()) } } diff --git a/packages/whisky/src/builder/interface.rs b/packages/whisky/src/builder/interface.rs index 643e90e..0a5d515 100644 --- a/packages/whisky/src/builder/interface.rs +++ b/packages/whisky/src/builder/interface.rs @@ -1,8 +1,10 @@ use async_trait::async_trait; +use cardano_serialization_lib::JsError; use sidan_csl_rs::{ builder::MeshTxBuilderCore, model::{ - Asset, LanguageVersion, MeshTxBuilderBody, MintItem, Output, PoolParams, Protocol, PubKeyTxIn, Redeemer, TxIn, UTxO, Withdrawal + Asset, LanguageVersion, MeshTxBuilderBody, MintItem, Output, PoolParams, Protocol, + PubKeyTxIn, Redeemer, TxIn, UTxO, Withdrawal, }, }; @@ -70,7 +72,10 @@ pub trait IMeshTxBuilder { /// ### Returns /// /// * `Self` - The MeshTxBuilder instance - async fn complete(&mut self, customized_tx: Option) -> &mut Self; + async fn complete( + &mut self, + customized_tx: Option, + ) -> Result<&mut Self, JsError>; /// ## Transaction building method /// @@ -83,7 +88,10 @@ pub trait IMeshTxBuilder { /// ### Returns /// /// * `Self` - The MeshTxBuilder instance - fn complete_sync(&mut self, customized_tx: Option) -> &mut Self; + fn complete_sync( + &mut self, + customized_tx: Option, + ) -> Result<&mut Self, JsError>; /// ## Transaction building method /// @@ -722,5 +730,5 @@ pub trait IMeshTxBuilder { /// /// * `extra_inputs` - A vector of extra inputs provided /// * `threshold` - The threshold as configured - fn add_utxos_from(&mut self, extra_inputs: Vec, threshold: u64); + fn add_utxos_from(&mut self, extra_inputs: Vec, threshold: u64) -> Result<(), JsError>; } diff --git a/packages/whisky/src/builder/tx_eval.rs b/packages/whisky/src/builder/tx_eval.rs index 499a2ab..e487c2e 100644 --- a/packages/whisky/src/builder/tx_eval.rs +++ b/packages/whisky/src/builder/tx_eval.rs @@ -99,7 +99,9 @@ impl IEvaluator for MeshTxEvaluator { inputs: &[UTxO], additional_txs: &[String], ) -> Result, JsError> { - self.evaluate_tx_sync(tx_hex, inputs, additional_txs) + let res = self.evaluate_tx_sync(tx_hex, inputs, additional_txs); + println!("res: {:?}", res); + res } } diff --git a/packages/whisky/tests/integration_tests.rs b/packages/whisky/tests/integration_tests.rs index 526e7cf..89512e8 100644 --- a/packages/whisky/tests/integration_tests.rs +++ b/packages/whisky/tests/integration_tests.rs @@ -156,7 +156,8 @@ mod int_tests { ) .change_address(wallet_address) .change_output_datum(&con_str0(json!([])).to_string()) - .complete_sync(None); + .complete_sync(None) + .unwrap(); println!("{}", mesh.core.mesh_csl.tx_hex); assert!(mesh.core.mesh_csl.tx_hex != *""); } @@ -179,6 +180,7 @@ mod int_tests { .change_address("addr_test1vru4e2un2tq50q4rv6qzk7t8w34gjdtw3y2uzuqxzj0ldrqqactxh") .signing_key("51022b7e38be01d1cc581230e18030e6e1a3e949a1fdd2aeae5f5412154fe82b") .complete_sync(None) + .unwrap() .complete_signing(); println!("{}", signed_tx); @@ -208,6 +210,7 @@ mod int_tests { .signing_key("58208d4cfa90e8bd0c48c52d2fb62c77ba3f6f5eb46f640d5f997390012928d670f7") .signing_key("5820ba73019f1239fa47f8d9c0c42c5d05bf34f2b2f6ebd1c556f8f86e5bee1aac66") .complete_sync(None) + .unwrap() .complete_signing(); println!("{}", signed_tx); @@ -254,6 +257,7 @@ mod int_tests { .required_signer_hash("4f91183f5fc7c81cbc11d1ecbfde2d1cfc1a71ef9de999bdc1e15ecb") .signing_key("5820c835cd2413c6330537c85e3d510b313dfdeee5708206e76ce8bd387cdd4b6bb2") .complete_sync(None) + .unwrap() .complete_signing(); println!("{}", signed_tx);