diff --git a/Cargo.lock b/Cargo.lock index ae47bf6..1f4099d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,21 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.86" @@ -349,6 +364,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + [[package]] name = "cipher" version = "0.4.4" @@ -376,6 +404,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.12" @@ -453,6 +487,41 @@ dependencies = [ "petgraph", ] +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "delegate-display" version = "2.1.1" @@ -472,6 +541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", + "serde", ] [[package]] @@ -503,7 +573,7 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "equihash" version = "0.2.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "blake2b_simd", "byteorder", @@ -528,7 +598,7 @@ dependencies = [ [[package]] name = "f4jumble" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "blake2b_simd", ] @@ -931,11 +1001,39 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "incrementalmerkletree" version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75346da3bd8e3d8891d02508245ed2df34447ca6637e343829f8d08986e9cde2" +source = "git+https://github.com/ec2/incrementalmerkletree.git?rev=16eff253ad2575d48feec04f7387e6507a7dd698#16eff253ad2575d48feec04f7387e6507a7dd698" dependencies = [ "either", ] @@ -965,6 +1063,7 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", + "serde", ] [[package]] @@ -975,6 +1074,7 @@ checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown 0.14.5", + "serde", ] [[package]] @@ -1068,6 +1168,16 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.22" @@ -1334,6 +1444,29 @@ dependencies = [ "group", ] +[[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" @@ -1627,6 +1760,15 @@ 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" @@ -1771,6 +1913,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "sapling-crypto" version = "0.2.0" @@ -1832,6 +1980,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "secp256k1" version = "0.27.0" @@ -1879,6 +2033,48 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.3.0", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha2" version = "0.10.8" @@ -1902,8 +2098,7 @@ dependencies = [ [[package]] name = "shardtree" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78222845cd8bbe5eb95687407648ff17693a35de5e8abaa39a4681fb21e033f9" +source = "git+https://github.com/ec2/incrementalmerkletree.git?rev=16eff253ad2575d48feec04f7387e6507a7dd698#16eff253ad2575d48feec04f7387e6507a7dd698" dependencies = [ "bitflags", "either", @@ -1948,6 +2143,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.6.1" @@ -2651,6 +2852,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2745,7 +2955,7 @@ dependencies = [ [[package]] name = "zcash_address" version = "0.5.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "bech32", "bs58", @@ -2757,8 +2967,9 @@ dependencies = [ [[package]] name = "zcash_client_backend" version = "0.13.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ + "async-trait", "base64 0.21.7", "bech32", "bls12_381", @@ -2766,6 +2977,7 @@ dependencies = [ "byteorder", "crossbeam-channel", "document-features", + "futures-util", "group", "hex", "hyper-util", @@ -2801,23 +3013,27 @@ dependencies = [ [[package]] name = "zcash_client_memory" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "bs58", "byteorder", "group", "incrementalmerkletree", "jubjub", - "maybe-rayon", "nonempty", "orchard", + "parking_lot", "prost 0.13.2", + "rayon", "sapling-crypto", "secrecy", + "serde", + "serde_with", "shardtree", "static_assertions", "subtle", "thiserror", + "tokio", "tracing", "zcash_address", "zcash_client_backend", @@ -2831,7 +3047,7 @@ dependencies = [ [[package]] name = "zcash_client_sqlite" version = "0.11.2" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "bs58", "byteorder", @@ -2867,7 +3083,7 @@ dependencies = [ [[package]] name = "zcash_encoding" version = "0.2.1" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "byteorder", "nonempty", @@ -2876,7 +3092,7 @@ dependencies = [ [[package]] name = "zcash_keys" version = "0.3.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "bech32", "bip32", @@ -2917,7 +3133,7 @@ dependencies = [ [[package]] name = "zcash_primitives" version = "0.17.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "aes", "bip32", @@ -2955,7 +3171,7 @@ dependencies = [ [[package]] name = "zcash_proofs" version = "0.17.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "bellman", "blake2b_simd", @@ -2975,7 +3191,7 @@ dependencies = [ [[package]] name = "zcash_protocol" version = "0.3.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "document-features", "memuse", @@ -3044,7 +3260,7 @@ dependencies = [ [[package]] name = "zip321" version = "0.1.0" -source = "git+https://github.com/ChainSafe/librustzcash?rev=c97a3f6e60446523fafa63cdf77b6c2584ac9f3b#c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" +source = "git+https://github.com/ChainSafe/librustzcash?rev=0fdd2fbb992a6f84eba45f488ee74a75d08d449b#0fdd2fbb992a6f84eba45f488ee74a75d08d449b" dependencies = [ "base64 0.21.7", "nom", diff --git a/Cargo.toml b/Cargo.toml index f031c5e..1ba3a2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ path = "examples/simple-sync.rs" name = "message-board-sync" path = "examples/message-board-sync.rs" + [profile.release] # Tell `rustc` to optimize for small code size. opt-level = 3 @@ -35,6 +36,8 @@ native = ["dep:tokio", "tonic/channel", "tonic/gzip", "tonic/tls-webpki-roots"] sqlite-db = ["dep:zcash_client_sqlite"] console_error_panic_hook = ["dep:console_error_panic_hook"] +sync2 = [] + [dependencies] ## Web dependencies wasm-bindgen = "0.2.84" @@ -48,12 +51,12 @@ console_error_panic_hook = { version = "0.1.7", optional = true } tonic-web-wasm-client = "0.6.0" ## Zcash dependencies -zcash_keys = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b", features = ["transparent-inputs", "orchard", "sapling", "unstable"] } -zcash_client_backend = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b", default-features = false, features = ["lightwalletd-tonic", "wasm-bindgen"] } -zcash_client_memory = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b", features = ["orchard"] } -zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" } -zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b" } -zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b", default-features = false, features = ["bundled-prover"] } +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"] } +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"] } ## gRPC Web dependencies prost = { version = "0.12", default-features = false } @@ -63,7 +66,7 @@ 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 = "c97a3f6e60446523fafa63cdf77b6c2584ac9f3b", default-features = false, features = ["unstable", "orchard"], optional = true } +zcash_client_sqlite = { git = "https://github.com/ChainSafe/librustzcash", rev = "0fdd2fbb992a6f84eba45f488ee74a75d08d449b", default-features = false, features = ["unstable", "orchard"], optional = true } getrandom = { version = "0.2", features = ["js"] } thiserror = "1.0.63" @@ -85,3 +88,16 @@ tempfile = "3.12" [patch.crates-io] zip32 = { git = "https://github.com/zcash/zip32.git", branch = "diversifier_index_ord" } +# TODO: Remove these once the PRs are merged +shardtree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" } +incrementalmerkletree = { git = "https://github.com/ec2/incrementalmerkletree.git", rev = "16eff253ad2575d48feec04f7387e6507a7dd698" } + +#[patch.'https://github.com/chainsafe/librustzcash'] +#zcash_address = { path = "../librustzcash/components/zcash_address" } +#zcash_client_backend = { path = "../librustzcash/zcash_client_backend" } +##zcash_client_sqlite = { path = "../librustzcash/zcash_client_sqlite" } +#zcash_client_memory = { path = "../librustzcash/zcash_client_memory" } +#zcash_keys = { path = "../librustzcash/zcash_keys" } +#zcash_primitives = { path = "../librustzcash/zcash_primitives" } +#zcash_proofs = { path = "../librustzcash/zcash_proofs" } +#zcash_protocol = { path = "../librustzcash/components/zcash_protocol" } \ No newline at end of file diff --git a/examples/message-board-sync.rs b/examples/message-board-sync.rs index dcb4496..70d8318 100644 --- a/examples/message-board-sync.rs +++ b/examples/message-board-sync.rs @@ -63,12 +63,20 @@ async fn main() { let id = w.import_ufvk(&ufvk, Some(2477329)).await.unwrap(); tracing::info!("Created account with id: {}", id); - tracing::info!("Syncing wallet"); - w.sync(|scanned_to, tip| { - println!("Scanned: {}/{}", scanned_to, tip); - }) - .await - .unwrap(); + #[cfg(not(feature = "sync2"))] + { + tracing::info!("Syncing wallet with our sync impl"); + w.sync(|scanned_to, tip| { + println!("Scanned: {}/{}", scanned_to, tip); + }) + .await + .unwrap(); + } + #[cfg(feature = "sync2")] + { + tracing::info!("Syncing wallet with sync2"); + w.sync2().await.unwrap(); + } tracing::info!("Syncing complete :)"); diff --git a/examples/simple-sync.rs b/examples/simple-sync.rs index fb7dcf1..fd2bc16 100644 --- a/examples/simple-sync.rs +++ b/examples/simple-sync.rs @@ -59,12 +59,20 @@ async fn main() { let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap(); tracing::info!("Created account with id: {}", id); - tracing::info!("Syncing wallet"); - w.sync(|scanned_to, tip| { - println!("Scanned: {}/{}", scanned_to, tip); - }) - .await - .unwrap(); + #[cfg(not(feature = "sync2"))] + { + tracing::info!("Syncing wallet with our sync impl"); + w.sync(|scanned_to, tip| { + println!("Scanned: {}/{}", scanned_to, tip); + }) + .await + .unwrap(); + } + #[cfg(feature = "sync2")] + { + tracing::info!("Syncing wallet with sync2"); + w.sync2().await.unwrap(); + } tracing::info!("Syncing complete :)"); diff --git a/justfile b/justfile index d97a854..c835ac8 100644 --- a/justfile +++ b/justfile @@ -4,29 +4,26 @@ default: build: wasm-pack build -t web --release --out-dir ./packages/webz-core -Z --no-default-features --features="wasm" build-std="panic_abort,std" -## Wasm Tests -test-web: - WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features="wasm" -Z build-std="panic_abort,std" - -test-message-board-web: - WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features="wasm" -Z build-std="panic_abort,std" --test message-board-sync - -test-simple-web: - WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features="wasm" -Z build-std="panic_abort,std" --test simple-sync-and-send +# All Wasm Tests +test-web *features: + WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features "wasm {{features}}" -Z build-std="panic_abort,std" +# sync message board in the web: addigional args: sync2 +test-message-board-web *features: + WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features "wasm {{features}}" -Z build-std="panic_abort,std" --test message-board-sync -## Native Examples -example-simple: - cargo run -r --example simple-sync +# simple example in the web: additional args: sync2 +test-simple-web *features: + WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --firefox --no-default-features --features "wasm {{features}}" -Z build-std="panic_abort,std" --test simple-sync-and-send -example-simple-sqlite: - cargo run -r --example simple-sync --features="sqlite-db" -example-message-board: - cargo run -r --example message-board-sync +# simple example: additional args: sync2, sqlite-db +example-simple *features: + RUST_LOG="info,zcash_client_backend::sync=debug" cargo run -r --example simple-sync --features "native {{features}}" -example-message-board-sqlite: - cargo run -r --example message-board-sync --features="sqlite-db" +# sync the message board: additional args: sync2, sqlite-db +example-message-board *features: + RUST_LOG=info,zcash_client_backend::sync=debug cargo run -r --example message-board-sync --features "native {{features}}" check: cargo check diff --git a/src/bindgen/wallet.rs b/src/bindgen/wallet.rs index 542f48c..1291c0b 100644 --- a/src/bindgen/wallet.rs +++ b/src/bindgen/wallet.rs @@ -6,6 +6,7 @@ use wasm_bindgen::prelude::*; use tonic_web_wasm_client::Client; use zcash_address::ZcashAddress; +use zcash_client_backend::proto::service::compact_tx_streamer_client::CompactTxStreamerClient; use zcash_client_memory::MemoryWalletDb; use zcash_keys::keys::UnifiedFullViewingKey; use zcash_primitives::consensus::{self, BlockHeight}; @@ -45,6 +46,14 @@ impl WebWallet { _ => Err(Error::InvalidNetwork(network.to_string())), } } + + pub fn client(&mut self) -> &mut CompactTxStreamerClient { + self.inner.client() + } + + pub fn inner_mut(&mut self) -> &mut MemoryWallet { + &mut self.inner + } } #[wasm_bindgen] @@ -121,6 +130,11 @@ impl WebWallet { Ok(()) } + /// Synchronize the wallet with the blockchain up to the tip using zcash_client_backend's algo + pub async fn sync2(&mut self) -> Result<(), Error> { + self.inner.sync2().await + } + pub fn get_wallet_summary(&self) -> Result, Error> { Ok(self.inner.get_wallet_summary()?.map(Into::into)) } diff --git a/src/error.rs b/src/error.rs index 0987210..27977ca 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ // Copyright 2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use std::fmt::Display; use wasm_bindgen::JsValue; #[derive(thiserror::Error, Debug)] @@ -47,6 +48,12 @@ pub enum Error { #[error("Failed to parse key: {0}")] KeyParseError(String), + // TODO: The error type from librustzcash backend is generic. Handle that later. + // Perhaps we make our error struct generic as well + // See: zcash_client_backend::sync::Error + #[error("Syncing Error: {0}")] + SyncError(String), + #[cfg(feature = "sqlite-db")] #[error("Sqlite error: {0}")] SqliteError(#[from] zcash_client_sqlite::error::SqliteClientError), @@ -79,3 +86,14 @@ impl From for Error { Self::ScanError(e) } } + +impl From> for Error +where + A: Display, + B: Display, + C: Display, +{ + fn from(e: zcash_client_backend::sync::Error) -> Self { + Self::SyncError(e.to_string()) + } +} diff --git a/src/wallet.rs b/src/wallet.rs index 3cac98f..60bbac8 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -31,7 +31,7 @@ use zcash_client_backend::scanning::{scan_block, Nullifiers, ScanningKeys}; use zcash_client_backend::wallet::OvkPolicy; use zcash_client_backend::zip321::{Payment, TransactionRequest}; use zcash_client_backend::ShieldedProtocol; -use zcash_client_memory::MemoryWalletDb; +use zcash_client_memory::{MemBlockCache, MemoryWalletDb}; use zcash_keys::keys::{UnifiedFullViewingKey, UnifiedSpendingKey}; use zcash_primitives::consensus::{self, BlockHeight, Network}; use zcash_primitives::transaction::components::amount::NonNegativeAmount; @@ -40,6 +40,7 @@ use zcash_primitives::transaction::TxId; use zcash_proofs::prover::LocalTxProver; use zcash_client_backend::proposal::Proposal; +use zcash_client_backend::sync::run; const BATCH_SIZE: u32 = 10000; @@ -85,8 +86,11 @@ where NoteRef: Copy + Eq + Ord + Debug, Error: From<::Error>, + ::Error: std::error::Error + Send + Sync + 'static, + ::Error: std::error::Error + Send + Sync + 'static, + // GRPC connection Trait Bounds - T: GrpcService, + T: GrpcService + Clone, T::Error: Into, T::ResponseBody: Body + std::marker::Send + 'static, ::Error: Into + std::marker::Send, @@ -106,6 +110,14 @@ where }) } + pub fn db_mut(&mut self) -> &mut W { + &mut self.db + } + + pub fn client(&mut self) -> &mut CompactTxStreamerClient { + &mut self.client + } + /// Add a new account to the wallet /// /// # Arguments @@ -188,6 +200,22 @@ where })?) } + pub async fn sync2(&mut 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(); + + run( + &mut client, + &self.network.clone(), + &db_cache, + self.db_mut(), + BATCH_SIZE, + ) + .await + .map_err(Into::into) + } + /// 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> { diff --git a/tests/message-board-sync.rs b/tests/message-board-sync.rs index 41ffac2..bb81f21 100644 --- a/tests/message-board-sync.rs +++ b/tests/message-board-sync.rs @@ -33,13 +33,21 @@ async fn test_message_board() { let id = w.import_ufvk(&ufvk_str, Some(2477329)).await.unwrap(); tracing::info!("Created account with id: {}", id); - tracing::info!("Syncing wallet"); - w.sync(&js_sys::Function::new_with_args( - "scanned_to, tip", - "console.log('Scanned: ', scanned_to, '/', tip)", - )) - .await - .unwrap(); + #[cfg(not(feature = "sync2"))] + { + tracing::info!("Syncing wallet with our sync impl"); + w.sync(&js_sys::Function::new_with_args( + "scanned_to, tip", + "console.log('Scanned: ', scanned_to, '/', tip)", + )) + .await + .unwrap(); + } + #[cfg(feature = "sync2")] + { + tracing::info!("Syncing wallet with sync2"); + w.sync2().await.unwrap(); + } tracing::info!("Syncing complete :)"); let summary = w.get_wallet_summary().unwrap(); diff --git a/tests/simple-sync-and-send.rs b/tests/simple-sync-and-send.rs index 610cd67..099eb18 100644 --- a/tests/simple-sync-and-send.rs +++ b/tests/simple-sync-and-send.rs @@ -25,13 +25,20 @@ async fn test_get_and_scan_range() { let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap(); tracing::info!("Created account with id: {}", id); - tracing::info!("Syncing wallet"); - w.sync(&js_sys::Function::new_with_args( - "scanned_to, tip", - "console.log('Scanned: ', scanned_to, '/', tip)", - )) - .await - .unwrap(); + #[cfg(not(feature = "sync2"))] + { + w.sync(&js_sys::Function::new_with_args( + "scanned_to, tip", + "console.log('Scanned: ', scanned_to, '/', tip)", + )) + .await + .unwrap(); + } + #[cfg(feature = "sync2")] + { + tracing::info!("Syncing wallet with sync2"); + w.sync2().await.unwrap(); + } tracing::info!("Syncing complete :)"); let summary = w.get_wallet_summary().unwrap();