diff --git a/Cargo.lock b/Cargo.lock index cd868d0..5eca874 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -50,6 +50,17 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.11" @@ -231,7 +242,16 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", +] + +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", ] [[package]] @@ -261,12 +281,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "base64" -version = "0.21.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - [[package]] name = "base64" version = "0.22.1" @@ -411,6 +425,30 @@ dependencies = [ "subtle", ] +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "borsh-derive", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.77", + "syn_derive", +] + [[package]] name = "bs58" version = "0.5.1" @@ -427,6 +465,39 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byte-unit" +version = "5.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ac19bdf0b2665407c39d82dbc937e951e7e2001609f0fb32edd0af45a2d63e" +dependencies = [ + "rust_decimal", + "serde", + "utf8-width", +] + +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -463,6 +534,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chacha20" version = "0.9.1" @@ -511,6 +588,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cobs" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -560,6 +643,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "critical-section" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242" + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -640,7 +729,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.77", ] [[package]] @@ -651,7 +740,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -663,7 +752,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -702,10 +791,22 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "equihash" version = "0.2.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "blake2b_simd", "byteorder", @@ -757,7 +858,7 @@ dependencies = [ [[package]] name = "f4jumble" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "blake2b_simd", ] @@ -783,7 +884,7 @@ dependencies = [ "macroific", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -914,7 +1015,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1059,11 +1160,23 @@ dependencies = [ "tracing", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] [[package]] name = "hashbrown" @@ -1071,7 +1184,7 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash", + "ahash 0.8.11", "allocator-api2", ] @@ -1084,6 +1197,20 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "serde", + "spin", + "stable_deref_trait", +] + [[package]] name = "heck" version = "0.5.0" @@ -1434,7 +1561,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1445,7 +1572,7 @@ checksum = "13198c120864097a565ccb3ff947672d969932b7975ebd4085732c9f09435e55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1458,7 +1585,7 @@ dependencies = [ "macroific_core", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1681,29 +1808,6 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "password-hash" version = "0.5.0" @@ -1773,7 +1877,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1831,6 +1935,19 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "postcard" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "heapless", + "serde", +] + [[package]] name = "powerfmt" version = "0.2.0" @@ -1853,7 +1970,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.77", +] + +[[package]] +name = "proc-macro-crate" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", ] [[package]] @@ -1901,7 +2050,7 @@ dependencies = [ "prost 0.13.2", "prost-types", "regex", - "syn", + "syn 2.0.77", "tempfile", ] @@ -1915,7 +2064,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -1927,6 +2076,26 @@ dependencies = [ "prost 0.13.2", ] +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quote" version = "1.0.37" @@ -2025,15 +2194,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "redox_syscall" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" -dependencies = [ - "bitflags", -] - [[package]] name = "regex" version = "1.10.6" @@ -2078,6 +2238,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + [[package]] name = "ring" version = "0.17.8" @@ -2102,6 +2271,35 @@ dependencies = [ "digest", ] +[[package]] +name = "rkyv" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "rusqlite" version = "0.29.0" @@ -2117,12 +2315,37 @@ dependencies = [ "time", ] +[[package]] +name = "rust_decimal" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "rand", + "rkyv", + "serde", + "serde_json", +] + [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.37" @@ -2157,7 +2380,7 @@ version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ - "base64 0.22.1", + "base64", "rustls-pki-types", ] @@ -2260,6 +2483,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + [[package]] name = "secp256k1" version = "0.27.0" @@ -2287,6 +2516,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" version = "1.0.210" @@ -2304,7 +2539,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2325,7 +2560,7 @@ version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" dependencies = [ - "base64 0.22.1", + "base64", "chrono", "hex", "indexmap 1.9.3", @@ -2346,7 +2581,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2386,6 +2621,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "simdutf8" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" + [[package]] name = "slab" version = "0.4.9" @@ -2416,6 +2657,15 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "static_assertions" @@ -2435,6 +2685,17 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.77" @@ -2446,6 +2707,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.77", +] + [[package]] name = "tap" version = "1.0.1" @@ -2482,7 +2755,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2566,7 +2839,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2625,7 +2898,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fef2e92c3cba6bbf5b7ee3528302c01e21bd7378795bf7cc7eff17da9ecd70" dependencies = [ "quote", - "syn", + "syn 2.0.77", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.22.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +dependencies = [ + "indexmap 2.5.0", + "toml_datetime", + "winnow", ] [[package]] @@ -2635,7 +2925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6f6ba989e4b2c58ae83d862d3a3e27690b6e3ae630d0deb59f3697f32aa88ad" dependencies = [ "async-trait", - "base64 0.22.1", + "base64", "bytes", "flate2", "http", @@ -2668,7 +2958,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2677,7 +2967,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef5ca6e7bdd0042c440d36b6df97c1436f1d45871ce18298091f114004b1beb4" dependencies = [ - "base64 0.22.1", + "base64", "byteorder", "bytes", "futures-util", @@ -2747,7 +3037,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2857,6 +3147,12 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "uuid" version = "1.10.0" @@ -2899,7 +3195,7 @@ checksum = "d674d135b4a8c1d7e813e2f8d1c9a58308aee4a680323066025e53132218bd91" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -2999,7 +3295,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -3033,7 +3329,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3078,7 +3374,7 @@ checksum = "4b8220be1fa9e4c889b30fd207d4906657e7e90b12e0e6b0c8b8d8709f5de021" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -3143,6 +3439,7 @@ name = "webz-core" version = "0.1.0" dependencies = [ "bip0039", + "byte-unit", "console_error_panic_hook", "futures-util", "getrandom", @@ -3151,10 +3448,12 @@ dependencies = [ "indexed_db_futures", "js-sys", "nonempty", + "postcard", "prost 0.12.6", "rayon", "ripemd", "secrecy", + "serde", "sha2", "subtle", "tempfile", @@ -3316,6 +3615,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + [[package]] name = "wyz" version = "0.5.1" @@ -3328,7 +3636,7 @@ dependencies = [ [[package]] name = "zcash_address" version = "0.5.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "bech32", "bs58", @@ -3340,10 +3648,10 @@ dependencies = [ [[package]] name = "zcash_client_backend" version = "0.13.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "async-trait", - "base64 0.21.7", + "base64", "bech32", "bls12_381", "bs58", @@ -3386,8 +3694,9 @@ dependencies = [ [[package]] name = "zcash_client_memory" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ + "async-trait", "bs58", "byteorder", "group", @@ -3395,7 +3704,6 @@ dependencies = [ "jubjub", "nonempty", "orchard", - "parking_lot", "prost 0.13.2", "rayon", "sapling-crypto", @@ -3408,6 +3716,7 @@ dependencies = [ "thiserror", "tokio", "tracing", + "wasm_sync", "zcash_address", "zcash_client_backend", "zcash_encoding", @@ -3420,7 +3729,7 @@ dependencies = [ [[package]] name = "zcash_client_sqlite" version = "0.11.2" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "bs58", "byteorder", @@ -3456,7 +3765,7 @@ dependencies = [ [[package]] name = "zcash_encoding" version = "0.2.1" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "byteorder", "nonempty", @@ -3465,7 +3774,7 @@ dependencies = [ [[package]] name = "zcash_keys" version = "0.3.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "bech32", "bip32", @@ -3506,7 +3815,7 @@ dependencies = [ [[package]] name = "zcash_primitives" version = "0.17.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "aes", "bip32", @@ -3544,7 +3853,7 @@ dependencies = [ [[package]] name = "zcash_proofs" version = "0.17.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "bellman", "blake2b_simd", @@ -3564,7 +3873,7 @@ dependencies = [ [[package]] name = "zcash_protocol" version = "0.3.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ "document-features", "memuse", @@ -3597,7 +3906,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -3617,7 +3926,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.77", ] [[package]] @@ -3633,9 +3942,9 @@ dependencies = [ [[package]] name = "zip321" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4#b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" dependencies = [ - "base64 0.21.7", + "base64", "nom", "percent-encoding", "zcash_address", diff --git a/Cargo.toml b/Cargo.toml index 7dd43e5..c59fa13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ multicore = ["zcash_proofs/multicore", "zcash_primitives/multicore", "zcash_clie # WASM specific features wasm = ["console_error_panic_hook", "dep:tracing-web", "zcash_client_backend/wasm-bindgen"] wasm-parallel = ["wasm", "wasm-bindgen-rayon", "multicore"] -native = ["dep:tokio", "tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots"] +native = ["tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"] sqlite-db = ["dep:zcash_client_sqlite"] console_error_panic_hook = ["dep:console_error_panic_hook"] no-bundler = ["wasm-bindgen-rayon?/no-bundler"] @@ -63,12 +63,12 @@ tokio_with_wasm = { version = "0.7.1", features = ["rt", "rt-multi-thread", "syn ## Zcash dependencies -zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", features = ["transparent-inputs", "orchard", "sapling", "unstable"] } -zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] } -zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", features = ["orchard"] } -zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b" } -zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b" } -zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", default-features = false, features = ["bundled-prover"] } +zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", features = ["transparent-inputs", "orchard", "sapling", "unstable"] } +zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["sync", "lightwalletd-tonic", "wasm-bindgen", "orchard"] } +zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", features = ["orchard"] } +zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" } +zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4" } +zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["bundled-prover"] } ## gRPC Web dependencies prost = { version = "0.12", default-features = false } @@ -78,8 +78,8 @@ tonic = { version = "0.12", default-features = false, features = [ # Used in Native tests -tokio = { version = "1.0", features = ["rt", "macros", "rt-multi-thread"], optional = true } -zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", default-features = false, features = ["unstable", "orchard"], optional = true } +tokio = { version = "1.0" } +zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "b6d32dd9a57165fb1508e9c1c8ab1a3aba09c7f4", default-features = false, features = ["unstable", "orchard"], optional = true } getrandom = { version = "0.2", features = ["js"] } thiserror = "1.0.63" @@ -99,12 +99,15 @@ wasm_thread = { git = "https://github.com/WilsonGramer/wasm_thread.git", rev = " wasm_sync = "0.1.2" http = { version = "1.1.0", default-features = false } +serde = { version = "1", features = ["derive"], default-features = false } +postcard = { version = "1.0.10", features = ["alloc"] } [dev-dependencies] wasm-bindgen-test = "0.3.43" tempfile = "3.12" # Used in Native tests tokio = { version = "1.0", features = ["rt", "macros"] } +byte-unit = { version = "5.1.4", features = ["byte"] } [patch.crates-io] diff --git a/examples/message-board-sync.rs b/examples/message-board-sync.rs index 70d8318..2c6daeb 100644 --- a/examples/message-board-sync.rs +++ b/examples/message-board-sync.rs @@ -60,7 +60,7 @@ async fn main() { .unwrap(); let ufvk = UnifiedFullViewingKey::from_sapling_extended_full_viewing_key(s).unwrap(); - let id = w.import_ufvk(&ufvk, Some(2477329)).await.unwrap(); + let id = w.import_ufvk(&ufvk, Some(2277329)).await.unwrap(); tracing::info!("Created account with id: {}", id); #[cfg(not(feature = "sync2"))] @@ -80,6 +80,20 @@ async fn main() { tracing::info!("Syncing complete :)"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); + + #[cfg(not(feature = "sqlite-db"))] + { + tracing::info!("Serializing wallet"); + let serialized_wallet = w.to_vec_postcard().await; + let byte_count = byte_unit::Byte::from_u64(serialized_wallet.len() as u64); + + tracing::info!( + "Wallet serialized: {}", + byte_count + .get_adjusted_unit(byte_unit::Unit::MB) + .to_string() + ) + } } diff --git a/examples/simple-sync.rs b/examples/simple-sync.rs index deb6a3a..85973ec 100644 --- a/examples/simple-sync.rs +++ b/examples/simple-sync.rs @@ -84,7 +84,7 @@ async fn main() { tracing::info!("Syncing complete :)"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); tracing::info!("Proposing a transaction"); @@ -93,6 +93,20 @@ async fn main() { w.transfer(SEED, 0, addr.unwrap(), 1000).await.unwrap(); tracing::info!("Transaction proposed"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); + + #[cfg(not(feature = "sqlite-db"))] + { + tracing::info!("Serializing wallet"); + let serialized_wallet = w.to_vec_postcard().await; + let byte_count = byte_unit::Byte::from_u64(serialized_wallet.len() as u64); + + tracing::info!( + "Wallet serialized: {}", + byte_count + .get_adjusted_unit(byte_unit::Unit::MB) + .to_string() + ) + } } diff --git a/src/bindgen/wallet.rs b/src/bindgen/wallet.rs index 1291c0b..e8593e6 100644 --- a/src/bindgen/wallet.rs +++ b/src/bindgen/wallet.rs @@ -47,8 +47,8 @@ impl WebWallet { } } - pub fn client(&mut self) -> &mut CompactTxStreamerClient { - self.inner.client() + pub fn client(&self) -> CompactTxStreamerClient { + self.inner.client.clone() } pub fn inner_mut(&mut self) -> &mut MemoryWallet { @@ -109,8 +109,8 @@ impl WebWallet { self.inner.import_ufvk(&ufvk, birthday_height).await } - pub fn suggest_scan_ranges(&self) -> Result, Error> { - self.inner.suggest_scan_ranges() + pub async fn suggest_scan_ranges(&self) -> Result, Error> { + self.inner.suggest_scan_ranges().await } /// Synchronize the wallet with the blockchain up to the tip @@ -135,8 +135,8 @@ impl WebWallet { self.inner.sync2().await } - pub fn get_wallet_summary(&self) -> Result, Error> { - Ok(self.inner.get_wallet_summary()?.map(Into::into)) + pub async fn get_wallet_summary(&self) -> Result, Error> { + Ok(self.inner.get_wallet_summary().await?.map(Into::into)) } /// diff --git a/src/wallet.rs b/src/wallet.rs index bc85a09..6145b7d 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -11,9 +11,13 @@ use tonic::{ use crate::error::Error; use crate::BlockRange; + +use serde::{Serialize, Serializer}; use std::fmt::Debug; use std::hash::Hash; +use std::sync::Arc; use subtle::ConditionallySelectable; +use tokio::sync::RwLock; use zcash_address::ZcashAddress; use zcash_client_backend::data_api::wallet::{ create_proposed_transactions, input_selection::GreedyInputSelector, propose_transfer, @@ -64,7 +68,7 @@ const BATCH_SIZE: u32 = 10000; /// pub struct Wallet { /// Internal database used to maintain wallet data (e.g. accounts, transactions, cached blocks) - pub(crate) db: W, + pub(crate) db: Arc>, // gRPC client used to connect to a lightwalletd instance for network data pub(crate) client: CompactTxStreamerClient, pub(crate) network: consensus::Network, @@ -102,19 +106,26 @@ where min_confirmations: NonZeroU32, ) -> Result { Ok(Wallet { - db, + db: Arc::new(RwLock::new(db)), client: CompactTxStreamerClient::new(client), network, min_confirmations, }) } - pub fn db_mut(&mut self) -> &mut W { - &mut self.db + pub async fn serialize_wallet(&self, serializer: S) -> Result + where + W: Serialize, + S: Serializer, + { + self.db.read().await.serialize(serializer) } - pub fn client(&mut self) -> &mut CompactTxStreamerClient { - &mut self.client + pub async fn to_vec_postcard(&self) -> Vec + where + W: Serialize, + { + postcard::to_allocvec(&*self.db.read().await).unwrap() } /// Add a new account to the wallet @@ -125,7 +136,7 @@ where /// birthday_height - The block height at which the account was created, optionally None and the current height is used /// pub async fn create_account( - &mut self, + &self, seed_phrase: &str, account_index: u32, birthday_height: Option, @@ -139,7 +150,7 @@ where } pub async fn import_ufvk( - &mut self, + &self, ufvk: &UnifiedFullViewingKey, birthday_height: Option, ) -> Result { @@ -149,16 +160,16 @@ where /// Helper method for importing an account directly from a Ufvk or from seed. async fn import_account_ufvk( - &mut self, + &self, ufvk: &UnifiedFullViewingKey, birthday_height: Option, purpose: AccountPurpose, ) -> Result { + let mut client = self.client.clone(); let birthday = match birthday_height { Some(height) => height, None => { - let chain_tip: u32 = self - .client + let chain_tip: u32 = client .get_latest_block(service::ChainSpec::default()) .await? .into_inner() @@ -176,17 +187,21 @@ where height: (birthday - 1).into(), ..Default::default() }; - let treestate = self.client.get_tree_state(request).await?.into_inner(); + let treestate = client.get_tree_state(request).await?.into_inner(); AccountBirthday::from_treestate(treestate, None).map_err(|_| Error::BirthdayError)? }; - let _account = self.db.import_account_ufvk(ufvk, &birthday, purpose)?; + let _account = self + .db + .write() + .await + .import_account_ufvk(ufvk, &birthday, purpose)?; Ok("0".to_string()) } - pub fn suggest_scan_ranges(&self) -> Result, Error> { - Ok(self.db.suggest_scan_ranges().map(|ranges| { + pub async fn suggest_scan_ranges(&self) -> Result, Error> { + Ok(self.db.read().await.suggest_scan_ranges().map(|ranges| { ranges .iter() .map(|scan_range| { @@ -199,16 +214,17 @@ where })?) } - pub async fn sync2(&mut self) -> Result<(), Error> { - let mut client = self.client().clone(); + pub async fn sync2(&self) -> Result<(), Error> { + let mut client = self.client.clone(); // TODO: This should be held in the Wallet struct so we can download in parallel let db_cache = MemBlockCache::new(); + let mut db = self.db.write().await; run( &mut client, &self.network.clone(), &db_cache, - self.db_mut(), + &mut *db, BATCH_SIZE, ) .await @@ -217,11 +233,11 @@ where /// Synchronize the wallet with the blockchain up to the tip /// The passed callback will be called for every batch of blocks processed with the current progress - pub async fn sync(&mut self, callback: impl Fn(BlockHeight, BlockHeight)) -> Result<(), Error> { + pub async fn sync(&self, callback: impl Fn(BlockHeight, BlockHeight)) -> Result<(), Error> { let tip = self.update_chain_tip().await?; tracing::info!("Retrieving suggested scan ranges from wallet"); - let scan_ranges = self.db.suggest_scan_ranges()?; + let scan_ranges = self.db.read().await.suggest_scan_ranges()?; tracing::info!("Suggested scan ranges: {:?}", scan_ranges); // TODO: Ensure wallet's view of the chain tip as of the previous wallet session is valid. @@ -258,10 +274,10 @@ where } /// Download and process all blocks in the given range - async fn fetch_and_scan_range(&mut self, start: u32, end: u32) -> Result<(), Error> { + async fn fetch_and_scan_range(&self, start: u32, end: u32) -> Result<(), Error> { + let mut client = self.client.clone(); // get the chainstate prior to the range - let tree_state = self - .client + let tree_state = client .get_tree_state(service::BlockId { height: (start - 1).into(), ..Default::default() @@ -270,13 +286,19 @@ where let chainstate = tree_state.into_inner().to_chain_state()?; // Get the scanning keys from the DB - let account_ufvks = self.db.get_unified_full_viewing_keys()?; + let account_ufvks = self.db.read().await.get_unified_full_viewing_keys()?; let scanning_keys = ScanningKeys::from_account_ufvks(account_ufvks); // Get the nullifiers for the unspent notes we are tracking let nullifiers = Nullifiers::new( - self.db.get_sapling_nullifiers(NullifierQuery::Unspent)?, - self.db.get_orchard_nullifiers(NullifierQuery::Unspent)?, + self.db + .read() + .await + .get_sapling_nullifiers(NullifierQuery::Unspent)?, + self.db + .read() + .await + .get_orchard_nullifiers(NullifierQuery::Unspent)?, ); let range = service::BlockRange { @@ -292,8 +314,7 @@ where tracing::info!("Scanning block range: {:?} to {:?}", start, end); - let scanned_blocks = self - .client + let scanned_blocks = client .get_block_range(range) .await? .into_inner() @@ -309,20 +330,28 @@ where .try_collect() .await?; - self.db.put_blocks(&chainstate, scanned_blocks)?; + self.db + .write() + .await + .put_blocks(&chainstate, scanned_blocks)?; Ok(()) } - pub fn get_wallet_summary(&self) -> Result>, Error> { - Ok(self.db.get_wallet_summary(self.min_confirmations.into())?) + pub async fn get_wallet_summary(&self) -> Result>, Error> { + Ok(self + .db + .read() + .await + .get_wallet_summary(self.min_confirmations.into())?) } - pub(crate) async fn update_chain_tip(&mut self) -> Result { + pub(crate) async fn update_chain_tip(&self) -> Result { tracing::info!("Retrieving chain tip from lightwalletd"); let tip_height = self .client + .clone() .get_latest_block(service::ChainSpec::default()) .await? .get_ref() @@ -331,7 +360,7 @@ where .unwrap(); tracing::info!("Latest block height is {}", tip_height); - self.db.update_chain_tip(tip_height)?; + self.db.write().await.update_chain_tip(tip_height)?; Ok(tip_height) } @@ -339,13 +368,13 @@ where /// /// Create a transaction proposal to send funds from the wallet to a given address /// - fn propose_transfer( - &mut self, + async fn propose_transfer( + &self, account_index: usize, to_address: ZcashAddress, value: u64, ) -> Result, Error> { - let account_id = self.db.get_account_ids()?[account_index]; + let account_id = self.db.read().await.get_account_ids()?[account_index]; let input_selector = GreedyInputSelector::new( SingleOutputChangeStrategy::new(FeeRule::standard(), None, ShieldedProtocol::Orchard), @@ -358,15 +387,17 @@ where )]) .unwrap(); - tracing::info!("Chain height: {:?}", self.db.chain_height()?); + tracing::info!("Chain height: {:?}", self.db.read().await.chain_height()?); tracing::info!( "target and anchor heights: {:?}", self.db + .read() + .await .get_target_and_anchor_heights(self.min_confirmations)? ); - + let mut db = self.db.write().await; let proposal = propose_transfer::<_, _, _, ::Error>( - &mut self.db, + &mut *db, &self.network, account_id, &input_selector, @@ -384,13 +415,13 @@ where /// Note: At the moment this requires a USK but ideally we want to be able to hand the signing off to a separate service /// e.g. browser plugin, hardware wallet, etc. Will need to look into refactoring librustzcash create_proposed_transactions to allow for this /// - pub(crate) fn create_proposed_transactions( - &mut self, + pub(crate) async fn create_proposed_transactions( + &self, proposal: Proposal, usk: &UnifiedSpendingKey, ) -> Result, Error> { let prover = LocalTxProver::bundled(); - + let mut db = self.db.write().await; let transactions = create_proposed_transactions::< _, _, @@ -398,7 +429,7 @@ where _, _, >( - &mut self.db, + &mut *db, &self.network, &prover, &prover, @@ -420,22 +451,27 @@ where /// # Arguments /// pub async fn transfer( - &mut self, + &self, seed_phrase: &str, from_account_index: usize, to_address: ZcashAddress, value: u64, ) -> Result<(), Error> { + let mut client = self.client.clone(); let usk = usk_from_seed_str(seed_phrase, 0, &self.network)?; - let proposal = self.propose_transfer(from_account_index, to_address, value)?; + let proposal = self + .propose_transfer(from_account_index, to_address, value) + .await?; // TODO: Add callback for approving the transaction here - let txids = self.create_proposed_transactions(proposal, &usk)?; + let txids = self.create_proposed_transactions(proposal, &usk).await?; // send the transactions to the network!! tracing::info!("Sending transaction..."); let txid = *txids.first(); let (txid, raw_tx) = self .db + .read() + .await .get_transaction(txid)? .map(|tx| { let mut raw_tx = service::RawTransaction::default(); @@ -446,7 +482,7 @@ where // tracing::info!("Transaction hex: 0x{}", hex::encode(&raw_tx.data)); - let response = self.client.send_transaction(raw_tx).await?.into_inner(); + let response = client.send_transaction(raw_tx).await?.into_inner(); if response.error_code != 0 { Err(Error::SendFailed { diff --git a/tests/message-board-sync.rs b/tests/message-board-sync.rs index a1ec7eb..4b779b2 100644 --- a/tests/message-board-sync.rs +++ b/tests/message-board-sync.rs @@ -55,7 +55,7 @@ async fn test_message_board() { } tracing::info!("Syncing complete :)"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); }) .unwrap() diff --git a/tests/simple-sync-and-send.rs b/tests/simple-sync-and-send.rs index 9b493fa..aef7aaa 100644 --- a/tests/simple-sync-and-send.rs +++ b/tests/simple-sync-and-send.rs @@ -49,14 +49,14 @@ async fn test_get_and_scan_range() { } tracing::info!("Syncing complete :)"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); tracing::info!("Proposing a transaction"); w.transfer(SEED, 0, "utest1z00xn09t4eyeqw9zmjss75sf460423dymgyfjn8rtlj26cffy0yad3eea82xekk24s00wnm38cvyrm2c6x7fxlc0ns4a5j7utgl6lchvglfvl9g9p56fqwzvzvj9d3z6r6ft88j654d7dj0ep6myq5duz9s8x78fdzmtx04d2qn8ydkxr4lfdhlkx9ktrw98gd97dateegrr68vl8xu".to_string(), 1000).await.unwrap(); tracing::info!("Transaction proposed"); - let summary = w.get_wallet_summary().unwrap(); + let summary = w.get_wallet_summary().await.unwrap(); tracing::info!("Wallet summary: {:?}", summary); }).unwrap().join_async();