Improvements to JniConverter.scanBlocks()
- Store Sapling tree with blocks - Store witnesses with full notes - Track note spends - Track change notes - Store index within block for each transaction - This will make it easier to request entire blocks of transactions at some point, and then filter out only the transactions we care about. - Store block times while scanning blocks - Return bool with error state from JniConverter.scanBlocks() - Support cached blocks that are height-ascending but not sequential - Blocks that do not contain Sapling data may be skipped. - Return error from scan_cached_blocks() if heights are not ascending
This commit is contained in:
parent
3188cf8942
commit
ab2b5903a0
|
@ -85,15 +85,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
[[package]]
|
||||
name = "bellman"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"group 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -117,6 +119,17 @@ dependencies = [
|
|||
"constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"block-padding 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-cipher-trait"
|
||||
version = "0.5.3"
|
||||
|
@ -125,11 +138,24 @@ dependencies = [
|
|||
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-padding"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byte-tools"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.2.7"
|
||||
|
@ -188,6 +214,14 @@ dependencies = [
|
|||
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.0"
|
||||
|
@ -218,6 +252,34 @@ dependencies = [
|
|||
"synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fake-simd"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ff"
|
||||
version = "0.4.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff_derive 0.3.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ff_derive"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"num-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fpe"
|
||||
version = "0.1.0"
|
||||
|
@ -266,6 +328,23 @@ dependencies = [
|
|||
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "group"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hex"
|
||||
version = "0.3.2"
|
||||
|
@ -388,12 +467,19 @@ name = "opaque-debug"
|
|||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "opaque-debug"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "pairing"
|
||||
version = "0.14.2"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"group 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -482,16 +568,28 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "sapling-crypto"
|
||||
version = "0.0.1"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stream-cipher"
|
||||
version = "0.1.1"
|
||||
|
@ -500,6 +598,16 @@ dependencies = [
|
|||
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.14.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "0.15.21"
|
||||
|
@ -606,62 +714,88 @@ name = "zcash-wallet-sdk-poc"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"android_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"protobuf 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rusqlite 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"zcash_client_backend 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"zcash_client_backend 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zcash_client_backend"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"bech32 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chacha20-poly1305-aead 0.1.2 (git+https://github.com/gtank/chacha20-poly1305-aead?rev=aefc71f95e8bc43f2070e3c5b08130d9c86bbf4f)",
|
||||
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"protobuf 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"protobuf-codegen-pure 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zcash_proofs 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zcash_primitives"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zcash_proofs"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zip32"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a#63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
source = "git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666#89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
dependencies = [
|
||||
"aes 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)",
|
||||
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"fpe 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)",
|
||||
"pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
"zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
|
@ -675,12 +809,15 @@ dependencies = [
|
|||
"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
|
||||
"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
|
||||
"checksum bech32 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad20b907fd16610c3960c7fe9dae13dd243343409bab80299774c9a8b5d7bed8"
|
||||
"checksum bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum bellman 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum bit-vec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "02b4ff8b16e6076c3e14220b39fbc1fabb6737522281a388998046859400895f"
|
||||
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
|
||||
"checksum blake2-rfc 0.2.18 (git+https://github.com/gtank/blake2-rfc?rev=7a5b5fc99ae483a0043db7547fb79a6fa44b88a9)" = "<none>"
|
||||
"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d"
|
||||
"checksum block-cipher-trait 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "370424437b9459f3dfd68428ed9376ddfe03d8b70ede29cc533b3557df186ab4"
|
||||
"checksum block-padding 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc4358306e344bf9775d0197fd00d2603e5afb0771bb353538630f022068ea3"
|
||||
"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40"
|
||||
"checksum byte-tools 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "980479e6fde23246dfb54d47580d66b4e99202e7579c5eaa9fe10ecb5ebd2182"
|
||||
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
|
||||
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
|
||||
"checksum cesu8 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
|
||||
|
@ -690,16 +827,22 @@ dependencies = [
|
|||
"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
|
||||
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"
|
||||
"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90"
|
||||
"checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c"
|
||||
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
|
||||
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
|
||||
"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
|
||||
"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
|
||||
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
|
||||
"checksum ff 0.4.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum ff_derive 0.3.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum fpe 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce3371c82bfbd984f624cab093f55e7336f5a6e589f8518e1258f54f011b89ad"
|
||||
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
||||
"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
|
||||
"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4"
|
||||
"checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592"
|
||||
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
|
||||
"checksum group 0.1.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
|
||||
"checksum jni 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ecfa3b81afc64d9a6539c4eece96ac9a93c551c713a313800dade8e33d7b5c1"
|
||||
"checksum jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
|
||||
|
@ -717,7 +860,8 @@ dependencies = [
|
|||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
||||
"checksum opaque-debug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d620c9c26834b34f039489ac0dfdb12c7ac15ccaf818350a64c9b5334a452ad7"
|
||||
"checksum pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum opaque-debug 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51ecbcb821e1bd256d456fe858aaa7f380b63863eab2eb86eee1bd9f33dd6682"
|
||||
"checksum pairing 0.14.2 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
|
||||
"checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09"
|
||||
"checksum protobuf 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbd08d128db199b1c6bb662e343d7d1a8f6d0060b411675766d88e5146a4bb38"
|
||||
|
@ -729,8 +873,10 @@ dependencies = [
|
|||
"checksum rusqlite 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39bae767eb27866f5c0be918635ae54af705bc09db11be2c43a3c6b361cf3462"
|
||||
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
|
||||
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
|
||||
"checksum sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum sapling-crypto 0.0.1 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d"
|
||||
"checksum stream-cipher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "30dc6118470d69ce0fdcf7e6f95e95853f7f4f72f80d835d4519577c323814ab"
|
||||
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
||||
"checksum syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)" = "816b7af21405b011a23554ea2dc3f6576dc86ca557047c34098c1d741f10f823"
|
||||
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
|
||||
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
|
||||
|
@ -745,6 +891,7 @@ dependencies = [
|
|||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
"checksum winapi-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc5508759c5bf4285e61feb862b6083c8480aec864fa17a81fdec6f69b461ab"
|
||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
"checksum zcash_client_backend 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=63ec78bb857a258a97d25a5a6e747389996e566a)" = "<none>"
|
||||
"checksum zcash_client_backend 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum zcash_primitives 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum zcash_proofs 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
"checksum zip32 0.0.0 (git+https://github.com/str4d/librustzcash.git?rev=89cfef8515d5d88809c485a44fdc54572b9e5666)" = "<none>"
|
||||
|
|
18
Cargo.toml
18
Cargo.toml
|
@ -6,17 +6,31 @@ description = "Simple PoC that rust can work with protobufs over JNI"
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
failure = "0.1"
|
||||
protobuf = "2"
|
||||
rand = "0.4"
|
||||
rusqlite = { version = "0.15", features = ["bundled"] }
|
||||
log = "0.4"
|
||||
|
||||
[dependencies.ff]
|
||||
git = "https://github.com/str4d/librustzcash.git"
|
||||
rev = "89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
|
||||
[dependencies.pairing]
|
||||
git = "https://github.com/str4d/librustzcash.git"
|
||||
rev = "89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
|
||||
[dependencies.zcash_client_backend]
|
||||
git = "https://github.com/str4d/librustzcash.git"
|
||||
rev = "63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
rev = "89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
|
||||
[dependencies.zcash_primitives]
|
||||
git = "https://github.com/str4d/librustzcash.git"
|
||||
rev = "89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
|
||||
[dependencies.zip32]
|
||||
git = "https://github.com/str4d/librustzcash.git"
|
||||
rev = "63ec78bb857a258a97d25a5a6e747389996e566a"
|
||||
rev = "89cfef8515d5d88809c485a44fdc54572b9e5666"
|
||||
|
||||
[target.'cfg(target_os="android")'.dependencies]
|
||||
jni = { version = "0.10", default-features = false }
|
||||
|
|
|
@ -4,7 +4,7 @@ class JniConverter {
|
|||
|
||||
external fun getAddress(seed: ByteArray): String
|
||||
|
||||
external fun scanBlocks(db_cache: String, db_data: String, seed: ByteArray)
|
||||
external fun scanBlocks(db_cache: String, db_data: String, seed: ByteArray): Boolean
|
||||
|
||||
external fun initLogs()
|
||||
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
extern crate failure;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate ff;
|
||||
extern crate pairing;
|
||||
extern crate protobuf;
|
||||
extern crate rusqlite;
|
||||
extern crate zcash_client_backend;
|
||||
extern crate zcash_primitives;
|
||||
extern crate zip32;
|
||||
|
||||
use failure::{format_err, Error};
|
||||
use ff::{PrimeField, PrimeFieldRepr};
|
||||
use protobuf::parse_from_bytes;
|
||||
use rusqlite::{types::ToSql, Connection, NO_PARAMS};
|
||||
use zcash_client_backend::{
|
||||
address::encode_payment_address, constants::HRP_SAPLING_EXTENDED_SPENDING_KEY_TEST,
|
||||
welding_rig::scan_block_from_bytes,
|
||||
constants::HRP_SAPLING_PAYMENT_ADDRESS_TEST, encoding::encode_payment_address,
|
||||
proto::compact_formats::CompactBlock, welding_rig::scan_block,
|
||||
};
|
||||
use zcash_primitives::{
|
||||
merkle_tree::{CommitmentTree, IncrementalWitness},
|
||||
JUBJUB,
|
||||
};
|
||||
use zip32::{ChildIndex, ExtendedFullViewingKey, ExtendedSpendingKey};
|
||||
|
||||
|
@ -27,7 +40,7 @@ fn extfvk_from_seed(seed: &[u8]) -> ExtendedFullViewingKey {
|
|||
|
||||
fn address_from_extfvk(extfvk: &ExtendedFullViewingKey) -> String {
|
||||
let addr = extfvk.default_address().unwrap().1;
|
||||
encode_payment_address(HRP_SAPLING_EXTENDED_SPENDING_KEY_TEST, &addr)
|
||||
encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS_TEST, &addr)
|
||||
}
|
||||
|
||||
fn init_data_database(db_data: &str) -> rusqlite::Result<()> {
|
||||
|
@ -35,7 +48,8 @@ fn init_data_database(db_data: &str) -> rusqlite::Result<()> {
|
|||
data.execute(
|
||||
"CREATE TABLE IF NOT EXISTS blocks (
|
||||
height INTEGER PRIMARY KEY,
|
||||
time INTEGER
|
||||
time INTEGER NOT NULL,
|
||||
sapling_tree BLOB NOT NULL
|
||||
)",
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
|
@ -43,7 +57,9 @@ fn init_data_database(db_data: &str) -> rusqlite::Result<()> {
|
|||
"CREATE TABLE IF NOT EXISTS transactions (
|
||||
id_tx INTEGER PRIMARY KEY,
|
||||
txid BLOB NOT NULL UNIQUE,
|
||||
block INTEGER NOT NULL,
|
||||
block INTEGER,
|
||||
tx_index INTEGER,
|
||||
raw BLOB,
|
||||
FOREIGN KEY (block) REFERENCES blocks(height)
|
||||
)",
|
||||
NO_PARAMS,
|
||||
|
@ -53,12 +69,32 @@ fn init_data_database(db_data: &str) -> rusqlite::Result<()> {
|
|||
id_note INTEGER PRIMARY KEY,
|
||||
tx INTEGER NOT NULL,
|
||||
output_index INTEGER NOT NULL,
|
||||
account INTEGER NOT NULL,
|
||||
diversifier BLOB NOT NULL,
|
||||
value INTEGER NOT NULL,
|
||||
rcm BLOB NOT NULL,
|
||||
nf BLOB NOT NULL UNIQUE,
|
||||
is_change BOOLEAN NOT NULL,
|
||||
memo BLOB,
|
||||
spent INTEGER,
|
||||
FOREIGN KEY (tx) REFERENCES transactions(id_tx),
|
||||
FOREIGN KEY (spent) REFERENCES transactions(id_tx),
|
||||
CONSTRAINT tx_output UNIQUE (tx, output_index)
|
||||
)",
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
data.execute(
|
||||
"CREATE TABLE IF NOT EXISTS sapling_witnesses (
|
||||
id_witness INTEGER PRIMARY KEY,
|
||||
note INTEGER NOT NULL,
|
||||
block INTEGER NOT NULL,
|
||||
witness BLOB NOT NULL,
|
||||
FOREIGN KEY (note) REFERENCES received_notes(id_note),
|
||||
FOREIGN KEY (block) REFERENCES blocks(height),
|
||||
CONSTRAINT witness_height UNIQUE (note, block)
|
||||
)",
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -67,6 +103,12 @@ struct CompactBlockRow {
|
|||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct WitnessRow {
|
||||
id_note: i64,
|
||||
witness: IncrementalWitness,
|
||||
}
|
||||
|
||||
/// Scans new blocks added to the cache for any transactions received by the given
|
||||
/// ExtendedFullViewingKeys.
|
||||
///
|
||||
|
@ -75,7 +117,7 @@ fn scan_cached_blocks(
|
|||
db_cache: &str,
|
||||
db_data: &str,
|
||||
extfvks: &[ExtendedFullViewingKey],
|
||||
) -> rusqlite::Result<()> {
|
||||
) -> Result<(), Error> {
|
||||
let cache = Connection::open(db_cache)?;
|
||||
let data = Connection::open(db_data)?;
|
||||
|
||||
|
@ -94,18 +136,35 @@ fn scan_cached_blocks(
|
|||
// Prepare necessary SQL statements
|
||||
let mut stmt_blocks = cache
|
||||
.prepare("SELECT height, data FROM compactblocks WHERE height > ? ORDER BY height ASC")?;
|
||||
let mut stmt_fetch_tree = data.prepare("SELECT sapling_tree FROM blocks WHERE height = ?")?;
|
||||
let mut stmt_fetch_witnesses =
|
||||
data.prepare("SELECT note, witness FROM sapling_witnesses WHERE block = ?")?;
|
||||
let mut stmt_fetch_nullifiers =
|
||||
data.prepare("SELECT id_note, nf, account FROM received_notes WHERE spent IS NULL")?;
|
||||
let mut stmt_insert_block = data.prepare(
|
||||
"INSERT INTO blocks (height)
|
||||
VALUES (?)",
|
||||
)?;
|
||||
let mut stmt_insert_tx = data.prepare(
|
||||
"INSERT INTO transactions (txid, block)
|
||||
VALUES (?, ?)",
|
||||
)?;
|
||||
let mut stmt_insert_note = data.prepare(
|
||||
"INSERT INTO received_notes (tx, output_index, value)
|
||||
"INSERT INTO blocks (height, time, sapling_tree)
|
||||
VALUES (?, ?, ?)",
|
||||
)?;
|
||||
let mut stmt_update_tx = data.prepare(
|
||||
"UPDATE transactions
|
||||
SET block = ?, tx_index = ? WHERE txid = ?",
|
||||
)?;
|
||||
let mut stmt_insert_tx = data.prepare(
|
||||
"INSERT INTO transactions (txid, block, tx_index)
|
||||
VALUES (?, ?, ?)",
|
||||
)?;
|
||||
let mut stmt_select_tx = data.prepare("SELECT id_tx FROM transactions WHERE txid = ?")?;
|
||||
let mut stmt_mark_spent_note =
|
||||
data.prepare("UPDATE received_notes SET spent = ? WHERE nf = ?")?;
|
||||
let mut stmt_insert_note = data.prepare(
|
||||
"INSERT INTO received_notes (tx, output_index, account, diversifier, value, rcm, nf, is_change)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
)?;
|
||||
let mut stmt_insert_witness = data.prepare(
|
||||
"INSERT INTO sapling_witnesses (note, block, witness)
|
||||
VALUES (?, ?, ?)",
|
||||
)?;
|
||||
let mut stmt_prune_witnesses = data.prepare("DELETE FROM sapling_witnesses WHERE block < ?")?;
|
||||
|
||||
// Fetch the CompactBlocks we need to scan
|
||||
let rows = stmt_blocks.query_map(&[last_height], |row| CompactBlockRow {
|
||||
|
@ -113,37 +172,165 @@ fn scan_cached_blocks(
|
|||
data: row.get(1),
|
||||
})?;
|
||||
|
||||
// Get the most recent CommitmentTree
|
||||
let mut tree = match stmt_fetch_tree.query_row(&[last_height], |row| match row.get_checked(0) {
|
||||
Ok(data) => {
|
||||
let data: Vec<_> = data;
|
||||
CommitmentTree::read(&data[..]).unwrap()
|
||||
}
|
||||
Err(_) => CommitmentTree::new(),
|
||||
}) {
|
||||
Ok(tree) => tree,
|
||||
Err(_) => CommitmentTree::new(),
|
||||
};
|
||||
|
||||
// Get most recent incremental witnesses for the notes we are tracking
|
||||
let witnesses = stmt_fetch_witnesses.query_map(&[last_height], |row| {
|
||||
let data: Vec<_> = row.get(1);
|
||||
WitnessRow {
|
||||
id_note: row.get(0),
|
||||
witness: IncrementalWitness::read(&data[..]).unwrap(),
|
||||
}
|
||||
})?;
|
||||
let mut witnesses: Vec<_> = witnesses.collect::<Result<_, _>>()?;
|
||||
|
||||
// Get the nullifiers for the notes we are tracking
|
||||
let nullifiers = stmt_fetch_nullifiers.query_map(NO_PARAMS, |row| {
|
||||
let nf: Vec<_> = row.get(1);
|
||||
let account: i64 = row.get(2);
|
||||
(nf, account as usize)
|
||||
})?;
|
||||
let mut nullifiers: Vec<_> = nullifiers.collect::<Result<_, _>>()?;
|
||||
|
||||
for row in rows {
|
||||
let row = row?;
|
||||
|
||||
// Scanned blocks MUST be height-seqential.
|
||||
if row.height != (last_height + 1) {
|
||||
error!(
|
||||
"Expected height of next CompactBlock to be {}, but was {}",
|
||||
// Start an SQL transaction for this block.
|
||||
data.execute("BEGIN IMMEDIATE", NO_PARAMS)?;
|
||||
|
||||
// Scanned blocks MUST be height-ascending, but they might not be height-sequential
|
||||
// (e.g. if blocks that don't contain Sapling data are skipped). Note that this
|
||||
// introduces a risk that a block containing Sapling data is skipped; it is up to
|
||||
// the caller to ensure this does not happen.
|
||||
if row.height <= last_height {
|
||||
return Err(format_err!(
|
||||
"Expected height of next CompactBlock to be at least {}, but was {}",
|
||||
last_height + 1,
|
||||
row.height
|
||||
);
|
||||
// Nothing more we can do
|
||||
break;
|
||||
));
|
||||
}
|
||||
last_height = row.height;
|
||||
|
||||
let block: CompactBlock = parse_from_bytes(&row.data)?;
|
||||
let block_time = block.time;
|
||||
|
||||
let txs = {
|
||||
let nf_refs: Vec<_> = nullifiers.iter().map(|(nf, acc)| (&nf[..], *acc)).collect();
|
||||
let mut witness_refs: Vec<_> = witnesses.iter_mut().map(|w| &mut w.witness).collect();
|
||||
scan_block(block, &extfvks, &nf_refs, &mut tree, &mut witness_refs[..])
|
||||
};
|
||||
|
||||
// Insert the block into the database.
|
||||
stmt_insert_block.execute(&[row.height.to_sql()?])?;
|
||||
let mut encoded_tree = Vec::new();
|
||||
tree.write(&mut encoded_tree).unwrap();
|
||||
stmt_insert_block.execute(&[
|
||||
row.height.to_sql()?,
|
||||
block_time.to_sql()?,
|
||||
encoded_tree.to_sql()?,
|
||||
])?;
|
||||
|
||||
for tx in scan_block_from_bytes(&row.data, &extfvks) {
|
||||
// Insert our transaction into the database.
|
||||
stmt_insert_tx.execute(&[tx.txid.0.to_vec().to_sql()?, row.height.to_sql()?])?;
|
||||
let tx_row = data.last_insert_rowid();
|
||||
for (tx, new_witnesses) in txs {
|
||||
// First try update an existing transaction in the database.
|
||||
let txid = tx.txid.0.to_vec();
|
||||
let tx_row = if stmt_update_tx.execute(&[
|
||||
row.height.to_sql()?,
|
||||
(tx.index as i64).to_sql()?,
|
||||
txid.to_sql()?,
|
||||
])? == 0
|
||||
{
|
||||
// It isn't there, so insert our transaction into the database.
|
||||
stmt_insert_tx.execute(&[
|
||||
txid.to_sql()?,
|
||||
row.height.to_sql()?,
|
||||
(tx.index as i64).to_sql()?,
|
||||
])?;
|
||||
data.last_insert_rowid()
|
||||
} else {
|
||||
// It was there, so grab its row number.
|
||||
stmt_select_tx.query_row(&[txid], |row| row.get(0))?
|
||||
};
|
||||
|
||||
// Mark notes as spent and remove them from the scanning cache
|
||||
for spend in &tx.shielded_spends {
|
||||
stmt_mark_spent_note.execute(&[tx_row.to_sql()?, spend.nf.to_sql()?])?;
|
||||
}
|
||||
nullifiers = nullifiers
|
||||
.into_iter()
|
||||
.filter(|(nf, _acc)| {
|
||||
tx.shielded_spends
|
||||
.iter()
|
||||
.find(|spend| &spend.nf == nf)
|
||||
.is_none()
|
||||
})
|
||||
.collect();
|
||||
|
||||
for (output, witness) in tx
|
||||
.shielded_outputs
|
||||
.into_iter()
|
||||
.zip(new_witnesses.into_iter())
|
||||
{
|
||||
let mut rcm = [0; 32];
|
||||
output.note.r.into_repr().write_le(&mut rcm[..])?;
|
||||
let nf = output.note.nf(
|
||||
&extfvks[output.account].fvk.vk,
|
||||
witness.position() as u64,
|
||||
&JUBJUB,
|
||||
);
|
||||
|
||||
for output in tx.shielded_outputs {
|
||||
// Insert received note into the database.
|
||||
// Assumptions:
|
||||
// - A transaction will not contain more than 2^63 shielded outputs.
|
||||
// - A note value will never exceed 2^63 zatoshis.
|
||||
stmt_insert_note.execute(&[tx_row, output.index as i64, output.value as i64])?;
|
||||
stmt_insert_note.execute(&[
|
||||
tx_row.to_sql()?,
|
||||
(output.index as i64).to_sql()?,
|
||||
(output.account as i64).to_sql()?,
|
||||
output.to.diversifier.0.to_sql()?,
|
||||
(output.note.value as i64).to_sql()?,
|
||||
rcm.to_sql()?,
|
||||
nf.to_sql()?,
|
||||
output.is_change.to_sql()?,
|
||||
])?;
|
||||
let note_row = data.last_insert_rowid();
|
||||
|
||||
// Save witness for note.
|
||||
witnesses.push(WitnessRow {
|
||||
id_note: note_row,
|
||||
witness,
|
||||
});
|
||||
|
||||
// Cache nullifier for note (to detect subsequent spends in this scan).
|
||||
nullifiers.push((nf, output.account));
|
||||
}
|
||||
}
|
||||
|
||||
// Insert current witnesses into the database.
|
||||
let mut encoded = Vec::new();
|
||||
for witness_row in witnesses.iter() {
|
||||
encoded.clear();
|
||||
witness_row.witness.write(&mut encoded).unwrap();
|
||||
stmt_insert_witness.execute(&[
|
||||
witness_row.id_note.to_sql()?,
|
||||
last_height.to_sql()?,
|
||||
encoded.to_sql()?,
|
||||
])?;
|
||||
}
|
||||
|
||||
// Prune the stored witnesses (we only expect rollbacks of at most 100 blocks).
|
||||
stmt_prune_witnesses.execute(&[last_height - 100])?;
|
||||
|
||||
// Commit the SQL transaction, writing this block's data atomically.
|
||||
data.execute("COMMIT", NO_PARAMS)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -161,7 +348,7 @@ pub mod android {
|
|||
|
||||
use self::android_logger::Filter;
|
||||
use self::jni::objects::{JClass, JString};
|
||||
use self::jni::sys::{jbyteArray, jstring};
|
||||
use self::jni::sys::{jboolean, jbyteArray, jstring, JNI_FALSE, JNI_TRUE};
|
||||
use self::jni::JNIEnv;
|
||||
|
||||
use super::{address_from_extfvk, extfvk_from_seed, scan_cached_blocks};
|
||||
|
@ -202,7 +389,7 @@ pub mod android {
|
|||
db_cache: JString,
|
||||
db_data: JString,
|
||||
seed: jbyteArray,
|
||||
) {
|
||||
) -> jboolean {
|
||||
let db_cache: String = env
|
||||
.get_string(db_cache)
|
||||
.expect("Couldn't get Java string!")
|
||||
|
@ -213,8 +400,12 @@ pub mod android {
|
|||
.into();
|
||||
let seed = env.convert_byte_array(seed).unwrap();
|
||||
|
||||
if let Err(e) = scan_cached_blocks(&db_cache, &db_data, &[extfvk_from_seed(&seed)]) {
|
||||
error!("Error while scanning blocks: {}", e);
|
||||
match scan_cached_blocks(&db_cache, &db_data, &[extfvk_from_seed(&seed)]) {
|
||||
Ok(()) => JNI_TRUE,
|
||||
Err(e) => {
|
||||
error!("Error while scanning blocks: {}", e);
|
||||
JNI_FALSE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue