diff --git a/Cargo.lock b/Cargo.lock index f11c018..e2cccd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,16 +29,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets 0.52.6", -] - -[[package]] -name = "backtrace-ext" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537beee3be4a18fb023b570f80e3ae28003db9167a751266b259926e25539d50" -dependencies = [ - "backtrace", + "windows-targets", ] [[package]] @@ -49,29 +40,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bech32" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" - -[[package]] -name = "bincode" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" -dependencies = [ - "bincode_derive", - "serde", - "unty", -] - -[[package]] -name = "bincode_derive" -version = "2.0.1" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" -dependencies = [ - "virtue", -] +checksum = "32637268377fc7b10a8c6d51de3e7fba1ce5dd371a96e342b34e6078db558e7f" [[package]] name = "bitflags" @@ -79,15 +50,6 @@ version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - [[package]] name = "bumpalo" version = "3.19.0" @@ -122,34 +84,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] -name = "cpufeatures" -version = "0.2.17" +name = "ciborium" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ - "libc", + "ciborium-io", + "ciborium-ll", + "serde", ] [[package]] -name = "crypto-common" -version = "0.1.6" +name = "ciborium-io" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] -name = "digest" -version = "0.10.7" +name = "ciborium-ll" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ - "block-buffer", - "crypto-common", + "ciborium-io", + "half", ] +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "displaydoc" version = "0.2.5" @@ -161,16 +127,6 @@ dependencies = [ "syn", ] -[[package]] -name = "errno" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" -dependencies = [ - "libc", - "windows-sys 0.60.2", -] - [[package]] name = "fnv" version = "1.0.7" @@ -219,16 +175,6 @@ dependencies = [ "pin-utils", ] -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.16" @@ -262,6 +208,17 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + [[package]] name = "hex" version = "0.4.3" @@ -502,12 +459,6 @@ dependencies = [ "serde", ] -[[package]] -name = "is_ci" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7655c9839580ee829dfacba1d1278c2b7883e50a277ff7541299489d6bdfdc45" - [[package]] name = "itoa" version = "1.0.15" @@ -530,12 +481,6 @@ version = "0.2.174" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" -[[package]] -name = "linux-raw-sys" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" - [[package]] name = "litemap" version = "0.8.0" @@ -560,36 +505,6 @@ version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" -[[package]] -name = "miette" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f98efec8807c63c752b5bd61f862c165c115b0a35685bdcfd9238c7aeb592b7" -dependencies = [ - "backtrace", - "backtrace-ext", - "cfg-if", - "miette-derive", - "owo-colors", - "supports-color", - "supports-hyperlinks", - "supports-unicode", - "terminal_size", - "textwrap", - "unicode-width 0.1.14", -] - -[[package]] -name = "miette-derive" -version = "7.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db5b29714e950dbb20d5e6f74f9dcec4edbcc1067bb7f8ed198c097b8c1a818b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "miniz_oxide" version = "0.8.9" @@ -625,65 +540,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "owo-colors" -version = "4.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" - [[package]] name = "percent-encoding" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pest" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323" -dependencies = [ - "memchr", - "miette", - "serde", - "serde_json", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb056d9e8ea77922845ec74a1c4e8fb17e7c218cc4fc11a15c5d25e189aa40bc" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e404e638f781eb3202dc82db6760c8ae8a1eeef7fb3fa8264b2ef280504966" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd1101f170f5903fde0914f899bb503d9ff5271d7ba76bbb70bea63690cc0d5" -dependencies = [ - "pest", - "sha2", -] - [[package]] name = "pin-project-lite" version = "0.2.16" @@ -886,19 +748,6 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" -[[package]] -name = "rustix" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.59.0", -] - [[package]] name = "rustls" version = "0.23.29" @@ -990,17 +839,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "shlex" version = "1.3.0" @@ -1041,27 +879,6 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "supports-color" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fc7232dd8d2e4ac5ce4ef302b1d81e0b80d055b9d77c7c4f51f6aa4c867d6" -dependencies = [ - "is_ci", -] - -[[package]] -name = "supports-hyperlinks" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804f44ed3c63152de6a9f90acbea1a110441de43006ea51bcce8f436196a288b" - -[[package]] -name = "supports-unicode" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7401a30af6cb5818bb64852270bb722533397edcfc7344954a38f420819ece2" - [[package]] name = "syn" version = "2.0.104" @@ -1093,26 +910,6 @@ dependencies = [ "syn", ] -[[package]] -name = "terminal_size" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" -dependencies = [ - "rustix", - "windows-sys 0.59.0", -] - -[[package]] -name = "textwrap" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057" -dependencies = [ - "unicode-linebreak", - "unicode-width 0.2.1", -] - [[package]] name = "thiserror" version = "2.0.12" @@ -1249,17 +1046,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "trait-variant" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "try-lock" version = "0.2.5" @@ -1267,84 +1053,46 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] -name = "tx3-lang" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4faaad8f112e459a8e06c0ccd07756cf4b71a5d5545d1b95078c304dc74934fe" +name = "tx3-sdk" +version = "0.8.0" dependencies = [ - "bincode", + "base64", + "bech32", "hex", - "miette", - "pest", - "pest_derive", + "reqwest", "serde", + "serde_json", "thiserror", - "trait-variant", + "tx3-tir", + "uuid", ] [[package]] -name = "tx3-sdk" -version = "0.8.0" +name = "tx3-tir" +version = "0.13.0" +source = "git+https://github.com/tx3-lang/tx3.git#0df40b455af7fb90365799d33d3fff19bc237171" dependencies = [ "base64", "bech32", + "ciborium", "hex", - "reqwest", "serde", "serde_json", "thiserror", - "tx3-lang", - "uuid", ] -[[package]] -name = "typenum" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" - -[[package]] -name = "ucd-trie" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" - [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "unicode-linebreak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - -[[package]] -name = "unicode-width" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c" - [[package]] name = "untrusted" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "unty" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" - [[package]] name = "url" version = "2.5.4" @@ -1373,18 +1121,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "virtue" -version = "0.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" - [[package]] name = "want" version = "0.3.1" @@ -1515,7 +1251,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -1524,16 +1260,7 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.2", + "windows-targets", ] [[package]] @@ -1542,30 +1269,14 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" -dependencies = [ - "windows_aarch64_gnullvm 0.53.0", - "windows_aarch64_msvc 0.53.0", - "windows_i686_gnu 0.53.0", - "windows_i686_gnullvm 0.53.0", - "windows_i686_msvc 0.53.0", - "windows_x86_64_gnu 0.53.0", - "windows_x86_64_gnullvm 0.53.0", - "windows_x86_64_msvc 0.53.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -1574,96 +1285,48 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" - [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" - [[package]] name = "wit-bindgen-rt" version = "0.39.0" diff --git a/Cargo.toml b/Cargo.toml index c8ac394..98dc414 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,6 @@ homepage = "https://github.com/tx3-lang/rust-sdk" readme = "README.md" [workspace.dependencies] -tx3-lang = "^0" -# tx3-lang = { version = "*", path = "../tx3/crates/tx3-lang" } +# tx3-tir = "^0" +# tx3-tir = { version = "*", path = "../tx3/crates/tx3-tir" } +tx3-tir = { git = "https://github.com/tx3-lang/tx3.git" } diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 31c1a04..c812070 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -13,9 +13,12 @@ homepage.workspace = true readme.workspace = true [dependencies] -tx3-lang = { workspace = true } +tx3-tir = { workspace = true } -reqwest = { version = "0.12.20", features = ["json", "rustls-tls"], default-features = false } +reqwest = { version = "0.12.20", features = [ + "json", + "rustls-tls", +], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" uuid = { version = "1.16.0", features = ["v4"] } diff --git a/sdk/src/trp/args.rs b/sdk/src/trp/args.rs deleted file mode 100644 index e692f3e..0000000 --- a/sdk/src/trp/args.rs +++ /dev/null @@ -1,392 +0,0 @@ -use base64::Engine as _; -use serde::{Deserialize, Serialize}; -use serde_json::{json, Number, Value}; -use thiserror::Error; -use tx3_lang::{ir::Type, UtxoRef}; - -pub use tx3_lang::ArgValue; - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct BytesEnvelope { - pub content: String, - pub encoding: BytesEncoding, -} - -impl BytesEnvelope { - pub fn from_hex(hex: &str) -> Result { - Ok(Self { - content: hex.to_string(), - encoding: BytesEncoding::Hex, - }) - } -} - -impl From for Vec { - fn from(envelope: BytesEnvelope) -> Self { - match envelope.encoding { - BytesEncoding::Base64 => base64_to_bytes(&envelope.content).unwrap(), - BytesEncoding::Hex => hex_to_bytes(&envelope.content).unwrap(), - } - } -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -#[serde(rename_all = "lowercase")] -pub enum BytesEncoding { - Base64, - Hex, -} - -fn utxoref_to_value(x: UtxoRef) -> Value { - Value::String(format!("{}#{}", hex::encode(x.txid), x.index)) -} - -fn bigint_to_value(i: i128) -> Value { - if i >= i64::MIN as i128 && i <= i64::MAX as i128 { - Value::Number((i as i64).into()) - } else { - let ashex = hex::encode(i.to_be_bytes()); - Value::String(format!("0x{ashex}")) - } -} - -fn number_to_bigint(x: Number) -> Result { - x.as_i128().ok_or(Error::NumberCantFit(x)) -} - -fn string_to_bigint(s: String) -> Result { - let bytes = hex_to_bytes(&s)?; - let bytes = - <[u8; 16]>::try_from(bytes).map_err(|x| Error::InvalidBytesForNumber(hex::encode(x)))?; - Ok(i128::from_be_bytes(bytes)) -} - -fn value_to_bigint(value: Value) -> Result { - match value { - Value::Number(n) => number_to_bigint(n), - Value::String(s) => string_to_bigint(s), - Value::Null => Err(Error::ValueIsNull), - x => Err(Error::ValueIsNotANumber(x)), - } -} - -fn value_to_bool(value: Value) -> Result { - match value { - Value::Bool(b) => Ok(b), - Value::Number(n) if n == Number::from(0) => Ok(false), - Value::Number(n) if n == Number::from(1) => Ok(true), - Value::String(s) if s == "true" => Ok(true), - Value::String(s) if s == "false" => Ok(false), - x => Err(Error::ValueIsNotABool(x)), - } -} - -fn hex_to_bytes(s: &str) -> Result, Error> { - let s = if s.starts_with("0x") { - s.trim_start_matches("0x") - } else { - s - }; - - hex::decode(s).map_err(Error::InvalidHex) -} - -fn base64_to_bytes(s: &str) -> Result, Error> { - base64::engine::general_purpose::STANDARD - .decode(s) - .map_err(Error::InvalidBase64) -} - -fn value_to_bytes(value: Value) -> Result, Error> { - match value { - Value::String(s) => hex_to_bytes(&s), - Value::Object(_) => { - let envelope: BytesEnvelope = - serde_json::from_value(value).map_err(Error::InvalidBytesEnvelope)?; - - match envelope.encoding { - BytesEncoding::Base64 => base64_to_bytes(&envelope.content), - BytesEncoding::Hex => hex_to_bytes(&envelope.content), - } - } - x => Err(Error::ValueIsNotBytes(x)), - } -} - -fn bech32_to_bytes(s: &str) -> Result, Error> { - let (_, data) = bech32::decode(s).map_err(Error::InvalidBech32)?; - Ok(data) -} - -fn value_to_address(value: Value) -> Result, Error> { - match value { - Value::String(s) => match bech32_to_bytes(&s) { - Ok(data) => Ok(data), - Err(_) => hex_to_bytes(&s), - }, - x => Err(Error::ValueIsNotAnAddress(x)), - } -} - -fn value_to_underfined(value: Value) -> Result { - match value { - Value::Bool(b) => Ok(ArgValue::Bool(b)), - Value::Number(x) => Ok(ArgValue::Int(number_to_bigint(x)?)), - Value::String(s) => Ok(ArgValue::String(s)), - x => Err(Error::CantInferTypeForValue(x)), - } -} - -fn string_to_utxo_ref(s: &str) -> Result { - let (txid, index) = s - .split_once('#') - .ok_or(Error::InvalidUtxoRef(s.to_string()))?; - - let txid = hex::decode(txid).map_err(|_| Error::InvalidUtxoRef(s.to_string()))?; - let index = index - .parse() - .map_err(|_| Error::InvalidUtxoRef(s.to_string()))?; - - Ok(UtxoRef { txid, index }) -} - -fn value_to_utxo_ref(value: Value) -> Result { - match value { - Value::String(s) => string_to_utxo_ref(&s), - x => Err(Error::ValueIsNotUtxoRef(x)), - } -} - -#[derive(Debug, Error)] -pub enum Error { - #[error("value is null")] - ValueIsNull, - - #[error("can't infer type for value: {0}")] - CantInferTypeForValue(Value), - - #[error("value is not a number: {0}")] - ValueIsNotANumber(Value), - - #[error("value can't fit: {0}")] - NumberCantFit(Number), - - #[error("value is not a valid number: {0}")] - InvalidBytesForNumber(String), - - #[error("value is not a bool: {0}")] - ValueIsNotABool(Value), - - #[error("value is not a string")] - ValueIsNotAString, - - #[error("value is not bytes: {0}")] - ValueIsNotBytes(Value), - - #[error("value is not a utxo ref: {0}")] - ValueIsNotUtxoRef(Value), - - #[error("invalid bytes envelope: {0}")] - InvalidBytesEnvelope(serde_json::Error), - - #[error("invalid base64: {0}")] - InvalidBase64(base64::DecodeError), - - #[error("invalid hex: {0}")] - InvalidHex(hex::FromHexError), - - #[error("invalid bech32: {0}")] - InvalidBech32(bech32::DecodeError), - - #[error("value is not an address: {0}")] - ValueIsNotAnAddress(Value), - - #[error("invalid utxo ref: {0}")] - InvalidUtxoRef(String), - - #[error("target type not supported: {0:?}")] - TargetTypeNotSupported(Type), -} - -pub fn to_json(value: ArgValue) -> Value { - match value { - ArgValue::Int(i) => bigint_to_value(i), - ArgValue::Bool(b) => Value::Bool(b), - ArgValue::String(s) => Value::String(s), - ArgValue::Bytes(b) => Value::String(format!("0x{}", hex::encode(b))), - ArgValue::Address(a) => Value::String(hex::encode(a)), - ArgValue::UtxoSet(x) => { - let v = x.into_iter().map(|x| json!(x)).collect(); - Value::Array(v) - } - ArgValue::UtxoRef(x) => utxoref_to_value(x), - } -} - -pub fn from_json(value: Value, target: &Type) -> Result { - match target { - Type::Int => { - let i = value_to_bigint(value)?; - Ok(ArgValue::Int(i)) - } - Type::Bool => { - let b = value_to_bool(value)?; - Ok(ArgValue::Bool(b)) - } - Type::Bytes => { - let b = value_to_bytes(value)?; - Ok(ArgValue::Bytes(b)) - } - Type::Address => { - let a = value_to_address(value)?; - Ok(ArgValue::Address(a)) - } - Type::UtxoRef => { - let x = value_to_utxo_ref(value)?; - Ok(ArgValue::UtxoRef(x)) - } - Type::Undefined => value_to_underfined(value), - x => Err(Error::TargetTypeNotSupported(x.clone())), - } -} - -#[cfg(test)] -mod tests { - use super::*; - - // TODO: derive PartialEq in upstream tx3-lang - fn partial_eq(a: ArgValue, b: ArgValue) -> bool { - match a { - ArgValue::Int(a) => match b { - ArgValue::Int(b) => dbg!(a) == dbg!(b), - _ => false, - }, - ArgValue::Bool(a) => match b { - ArgValue::Bool(b) => a == b, - _ => false, - }, - ArgValue::String(a) => match b { - ArgValue::String(b) => a == b, - _ => false, - }, - ArgValue::Bytes(a) => match b { - ArgValue::Bytes(b) => a == b, - _ => false, - }, - ArgValue::Address(a) => match b { - ArgValue::Address(b) => a == b, - _ => false, - }, - ArgValue::UtxoSet(hash_set) => match b { - ArgValue::UtxoSet(b) => hash_set == b, - _ => false, - }, - ArgValue::UtxoRef(utxo_ref) => match b { - ArgValue::UtxoRef(b) => utxo_ref == b, - _ => false, - }, - } - } - - fn json_to_value_test(provided: Value, target: Type, expected: ArgValue) { - let value = from_json(provided, &target).unwrap(); - assert!(partial_eq(value, expected)); - } - - fn round_trip_test(value: ArgValue, target: Type) { - let json = to_json(value.clone()); - dbg!(&json); - let value2 = from_json(json, &target).unwrap(); - assert!(partial_eq(value, value2)); - } - - #[test] - fn test_round_trip_small_int() { - round_trip_test(ArgValue::Int(123456789), Type::Int); - } - - #[test] - fn test_round_trip_negative_int() { - round_trip_test(ArgValue::Int(-123456789), Type::Int); - } - - #[test] - fn test_round_trip_big_int() { - round_trip_test(ArgValue::Int(12345678901234567890), Type::Int); - } - - #[test] - fn test_round_trip_int_overflow() { - round_trip_test(ArgValue::Int(i128::MIN), Type::Int); - round_trip_test(ArgValue::Int(i128::MAX), Type::Int); - } - - #[test] - fn test_round_trip_bool() { - round_trip_test(ArgValue::Bool(true), Type::Bool); - round_trip_test(ArgValue::Bool(false), Type::Bool); - } - - #[test] - fn test_round_trip_bool_number() { - json_to_value_test(json!(1), Type::Bool, ArgValue::Bool(true)); - json_to_value_test(json!(0), Type::Bool, ArgValue::Bool(false)); - } - - #[test] - fn test_round_trip_bool_string() { - json_to_value_test(json!("true"), Type::Bool, ArgValue::Bool(true)); - json_to_value_test(json!("false"), Type::Bool, ArgValue::Bool(false)); - } - - #[test] - fn test_round_trip_bytes() { - round_trip_test(ArgValue::Bytes(b"hello".to_vec()), Type::Bytes); - } - - #[test] - fn test_round_trip_bytes_base64() { - let json = json!(BytesEnvelope { - content: "aGVsbG8=".to_string(), - encoding: BytesEncoding::Base64, - }); - - json_to_value_test(json, Type::Bytes, ArgValue::Bytes(b"hello".to_vec())); - } - - #[test] - fn test_round_trip_bytes_hex() { - let json = json!(BytesEnvelope { - content: "68656c6c6f".to_string(), - encoding: BytesEncoding::Hex, - }); - - json_to_value_test(json, Type::Bytes, ArgValue::Bytes(b"hello".to_vec())); - } - - #[test] - fn test_round_trip_address() { - round_trip_test(ArgValue::Address(b"abc123".to_vec()), Type::Address); - } - - #[test] - fn test_round_trip_address_bech32() { - let json = json!("addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8"); - let bytes = - hex::decode("619493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e").unwrap(); - json_to_value_test(json, Type::Address, ArgValue::Address(bytes)); - } - - #[test] - fn test_round_trip_utxo_ref() { - let json = json!("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef#0"); - - let utxo_ref = UtxoRef { - txid: hex::decode("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef") - .unwrap(), - index: 0, - }; - - json_to_value_test(json, Type::UtxoRef, ArgValue::UtxoRef(utxo_ref)); - } -} diff --git a/sdk/src/trp/mod.rs b/sdk/src/trp/mod.rs index a6ac788..d3e19e4 100644 --- a/sdk/src/trp/mod.rs +++ b/sdk/src/trp/mod.rs @@ -1,61 +1,23 @@ use reqwest::header; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use serde_json::{json, Value}; +use serde_json::Value; use std::collections::HashMap; use thiserror::Error; use uuid::Uuid; -pub mod args; +use tx3_tir::interop::json as interop; -pub use args::ArgValue; +pub use interop::ArgValue; -use crate::trp::args::BytesEnvelope; +use interop::BytesEnvelope; -#[derive(Debug, Serialize, Deserialize)] -pub struct SearchSpaceDiagnostic { - pub matched: Vec, - pub by_address_count: Option, - pub by_asset_class_count: Option, - pub by_ref_count: Option, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct InputQueryDiagnostic { - pub address: Option, - pub min_amount: HashMap, - pub refs: Vec, - pub support_many: bool, - pub collateral: bool, -} - -#[derive(Debug, Serialize, Deserialize, Error)] -#[error("input `{name}` not resolved")] -pub struct InputNotResolvedDiagnostic { - pub name: String, - pub query: InputQueryDiagnostic, - pub search_space: SearchSpaceDiagnostic, -} - -#[derive(Debug, Serialize, Deserialize, Error)] -#[error("TIR version {provided} is not supported, expected {expected}")] -pub struct UnsupportedTirDiagnostic { - pub provided: String, - pub expected: String, -} - -#[derive(Debug, Serialize, Deserialize, Error)] -#[error("tx script returned failure")] -pub struct TxScriptFailureDiagnostic { - pub logs: Vec, -} +use crate::trp::spec::{ + InputNotResolvedDiagnostic, MissingTxArgDiagnostic, ResolveParams, SubmitParams, + SubmitResponse, SubmitWitness, TirInfo, TxEnvelope, TxScriptFailureDiagnostic, + UnsupportedTirDiagnostic, +}; -#[derive(Debug, Serialize, Deserialize, Error)] -#[error("missing argument `{key}` of type {ty}")] -pub struct MissingTxArgDiagnostic { - pub key: String, - #[serde(rename = "type")] - pub ty: String, -} +mod spec; // Custom error type for TRP operations #[derive(Debug, Error)] @@ -75,7 +37,7 @@ pub enum Error { #[error("Unknown error: {0}")] UnknownError(String), - #[error(transparent)] + #[error("TIR version {provided} is not supported, expected {expected}", provided = .0.provided, expected = .0.expected)] UnsupportedTir(UnsupportedTirDiagnostic), #[error("invalid TIR envelope")] @@ -90,13 +52,13 @@ pub enum Error { #[error("node can't resolve txs while running at era {era}")] UnsupportedEra { era: String }, - #[error(transparent)] + #[error("missing argument `{key}` of type {ty}", key = .0.key, ty = .0.ty)] MissingTxArg(MissingTxArgDiagnostic), - #[error(transparent)] + #[error("input `{name}` not resolved", name = .0.name)] InputNotResolved(InputNotResolvedDiagnostic), - #[error(transparent)] + #[error("tx script returned failure")] TxScriptFailure(TxScriptFailureDiagnostic), } @@ -142,43 +104,6 @@ impl From for Error { } } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TirInfo { - pub version: String, - pub bytecode: String, - pub encoding: String, // "base64" | "hex" | other -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct VKeyWitness { - pub key: args::BytesEnvelope, - pub signature: args::BytesEnvelope, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -#[serde(tag = "type")] -pub enum SubmitWitness { - #[serde(rename = "vkey")] - VKey(VKeyWitness), -} - -#[derive(Deserialize, Debug, Serialize)] -pub struct SubmitParams { - pub tx: args::BytesEnvelope, - pub witnesses: Vec, -} - -#[derive(Deserialize, Debug, Serialize)] -pub struct SubmitResponse { - pub hash: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TxEnvelope { - pub tx: String, - pub hash: String, -} - #[derive(Debug, Clone)] pub struct ClientOptions { pub endpoint: String, @@ -219,6 +144,12 @@ pub struct ProtoTxRequest { pub args: HashMap, } +fn to_json_arg_map(args: HashMap) -> HashMap { + args.into_iter() + .map(|(k, v)| (k, interop::to_json(v))) + .collect() +} + impl Client { pub fn new(options: ClientOptions) -> Self { Self { @@ -292,11 +223,13 @@ impl Client { } pub async fn resolve(&self, proto_tx: ProtoTxRequest) -> Result { - let params = json!({ - "tir": proto_tx.tir, - "args": HashMap::::from_iter(proto_tx.args.into_iter().map(|(k, v)| (k, args::to_json(v)))), - "env": self.options.env_args, - }); + let params = ResolveParams { + tir: proto_tx.tir, + args: to_json_arg_map(proto_tx.args), + env: to_json_arg_map(self.options.env_args.clone().unwrap_or_default()), + }; + + let params = serde_json::to_value(params).unwrap(); let response = self.call("trp.resolve", params).await?; @@ -312,11 +245,12 @@ impl Client { tx: TxEnvelope, witnesses: Vec, ) -> Result { - let params = serde_json::to_value(SubmitParams { + let params = SubmitParams { tx: BytesEnvelope::from_hex(&tx.tx).unwrap(), witnesses, - }) - .unwrap(); + }; + + let params = serde_json::to_value(params).unwrap(); let response = self.call("trp.submit", params).await?; diff --git a/sdk/src/trp/spec.rs b/sdk/src/trp/spec.rs new file mode 100644 index 0000000..4dd3d19 --- /dev/null +++ b/sdk/src/trp/spec.rs @@ -0,0 +1,114 @@ +// Generated by cargo xtask gen --lang rust +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SubmitParams { + #[serde(rename = "tx")] + pub tx: BytesEnvelope, + #[serde(rename = "witnesses")] + pub witnesses: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TxEnvelope { + #[serde(rename = "hash")] + pub hash: String, + #[serde(rename = "tx")] + pub tx: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TirInfo { + #[serde(rename = "bytecode")] + pub bytecode: String, + #[serde(rename = "encoding")] + pub encoding: String, + #[serde(rename = "version")] + pub version: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SubmitResponse { + #[serde(rename = "hash")] + pub hash: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SearchSpaceDiagnostic { + #[serde(rename = "by_address_count")] + pub by_address_count: Option, + #[serde(rename = "by_asset_class_count")] + pub by_asset_class_count: Option, + #[serde(rename = "by_ref_count")] + pub by_ref_count: Option, + #[serde(rename = "matched")] + pub matched: Vec, +} + +pub type BytesEnvelope = tx3_tir::interop::json::BytesEnvelope; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InputQueryDiagnostic { + #[serde(rename = "address")] + pub address: Option, + #[serde(rename = "collateral")] + pub collateral: bool, + #[serde(rename = "min_amount")] + pub min_amount: std::collections::HashMap, + #[serde(rename = "refs")] + pub refs: Vec, + #[serde(rename = "support_many")] + pub support_many: bool, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResolveParams { + #[serde(rename = "args")] + pub args: std::collections::HashMap, + #[serde(rename = "env")] + pub env: std::collections::HashMap, + #[serde(rename = "tir")] + pub tir: TirInfo, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SubmitWitness { + #[serde(rename = "key")] + pub key: BytesEnvelope, + #[serde(rename = "signature")] + pub signature: BytesEnvelope, + #[serde(rename = "type")] + pub ty: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UnsupportedTirDiagnostic { + #[serde(rename = "expected")] + pub expected: String, + #[serde(rename = "provided")] + pub provided: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InputNotResolvedDiagnostic { + #[serde(rename = "name")] + pub name: String, + #[serde(rename = "query")] + pub query: InputQueryDiagnostic, + #[serde(rename = "search_space")] + pub search_space: SearchSpaceDiagnostic, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MissingTxArgDiagnostic { + #[serde(rename = "key")] + pub key: String, + #[serde(rename = "type")] + pub ty: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TxScriptFailureDiagnostic { + #[serde(rename = "logs")] + pub logs: Vec, +}