From d8075dae281b7600581eebaa521e5608264e7cac Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 12:56:29 -0700 Subject: [PATCH 01/21] Add proper error for lock --- lib/src/commands.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/commands.rs b/lib/src/commands.rs index e0e4c72..eb0f270 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -356,7 +356,11 @@ impl Command for LockCommand { fn exec(&self, args: &[&str], lightclient: &LightClient) -> String { if args.len() != 0 { - return self.help(); + let mut h = vec![]; + h.push("Extra arguments to lock. Did you mean 'encrypt'?"); + h.push(""); + + return format!("{}\n{}", h.join("\n"), self.help()); } match lightclient.wallet.write().unwrap().lock() { From 13a89f8c82f3ff45398b68f19c8d72d1e9446933 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 12:56:36 -0700 Subject: [PATCH 02/21] Github build action --- lib/.github/workflows/rust.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/.github/workflows/rust.yml diff --git a/lib/.github/workflows/rust.yml b/lib/.github/workflows/rust.yml new file mode 100644 index 0000000..06a66bb --- /dev/null +++ b/lib/.github/workflows/rust.yml @@ -0,0 +1,28 @@ +name: Rust + +on: [push, pull_request] + +jobs: + build: + name: Build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: 1.38.0 + override: true + - name: cargo fetch + uses: actions-rs/cargo@v1 + with: + command: fetch + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose --release --all + \ No newline at end of file From 4a62949bdb40ee79e4286694db0bd43ea8cede57 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 13:00:10 -0700 Subject: [PATCH 03/21] Move actions to root --- {lib/.github => .github}/workflows/rust.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {lib/.github => .github}/workflows/rust.yml (100%) diff --git a/lib/.github/workflows/rust.yml b/.github/workflows/rust.yml similarity index 100% rename from lib/.github/workflows/rust.yml rename to .github/workflows/rust.yml From be2eaad44386f69baaf2cec853b3e81b59326fbe Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 13:21:18 -0700 Subject: [PATCH 04/21] Refactor into cargo workspace --- .github/workflows/rust.yml | 7 ++++++- Cargo.toml | 23 +++++------------------ cli/Cargo.toml | 18 ++++++++++++++++++ {src => cli/src}/main.rs | 0 lib/Cargo.toml | 3 --- 5 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 cli/Cargo.toml rename {src => cli/src}/main.rs (100%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 06a66bb..a13abeb 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -24,5 +24,10 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - args: --verbose --release --all + args: --verbose --release --all --tests + - name: Run tests + uses: actions-rs/cargo@v1 + with: + command: test + args: --verbose --release --all \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 4b0a909..1e7b3f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,8 @@ -[package] -name = "zecwallet-cli" -version = "1.1.0" -edition = "2018" - -[dependencies] -rustyline = "5.0.2" -clap = "2.33" -log = "0.4" -log4rs = "0.8.3" -shellwords = "1.0.0" -json = "0.12.0" -http = "0.1" -byteorder = "1" -tiny-bip39 = "0.6.2" - -zecwalletlitelib = { path = "./lib/" } - +[workspace] +members = [ + "lib", + "cli", +] [profile.release] debug = false \ No newline at end of file diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..bb0e67c --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "zecwallet-cli" +version = "1.1.0" +edition = "2018" + +[dependencies] +rustyline = "5.0.2" +clap = "2.33" +log = "0.4" +log4rs = "0.8.3" +shellwords = "1.0.0" +json = "0.12.0" +http = "0.1" +byteorder = "1" +tiny-bip39 = "0.6.2" + +zecwalletlitelib = { path = "../lib/" } + diff --git a/src/main.rs b/cli/src/main.rs similarity index 100% rename from src/main.rs rename to cli/src/main.rs diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 459ff9e..c3c3688 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -72,6 +72,3 @@ tower-grpc-build = { git = "https://github.com/tower-rs/tower-grpc", features = [dev-dependencies] tempdir = "0.3.7" - -[profile.release] -debug = false \ No newline at end of file From 8de18436eed75db6f9510de22c0e1c3b6003e161 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 13:38:08 -0700 Subject: [PATCH 05/21] Add x-compile --- .github/workflows/rust.yml | 69 +++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a13abeb..083fa8a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -30,4 +30,71 @@ jobs: with: command: test args: --verbose --release --all - \ No newline at end of file + - name: Upload + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.os }}-zecwallet-cli + path: target/release/zecwallet-cli + + linux_arm7: + name: Linux ARMv7 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: armv7-unknown-linux-gnueabihf + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target armv7-unknown-linux-gnueabihf + - name: Upload + uses: actions/upload-artifact@v1 + with: + name: linux_armv7-zecwallet-cli + path: target/armv7-unknown-linux-gnueabihf/release/zecwallet-cli + + linux_aarch64: + name: Linux ARM64 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: aarch64-unknown-linux-gnu + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target aarch64-unknown-linux-gnu + - name: Upload + uses: actions/upload-artifact@v1 + with: + name: linux_aarch64-zecwallet-cli + path: target/aarch64-unknown-linux-gnu/release/zecwallet-cli + + linux_mingw: + name: Linux mingw + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: x86_64-pc-windows-gnu + override: true + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target x86_64-pc-windows-gnu + - name: Upload + uses: actions/upload-artifact@v1 + with: + name: linux_mingw-zecwallet-cli + path: target/x86_64-pc-windows-gnu/release/zecwallet-cli.exe From 101cdc9cfa8a41dd891e67b6f563e3768f7d35af Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 14:05:14 -0700 Subject: [PATCH 06/21] debug --- .github/workflows/rust.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 083fa8a..746fd97 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -30,6 +30,9 @@ jobs: with: command: test args: --verbose --release --all + - run: pwd + - run: ls target/ + - run: ls target/release/ - name: Upload uses: actions/upload-artifact@v1 with: @@ -51,6 +54,9 @@ jobs: use-cross: true command: build args: --target armv7-unknown-linux-gnueabihf + - run: pwd + - run: ls target/ + - run: ls target/release/ - name: Upload uses: actions/upload-artifact@v1 with: @@ -71,7 +77,10 @@ jobs: with: use-cross: true command: build - args: --target aarch64-unknown-linux-gnu + args: --target aarch64-unknown-linux-gnu + - run: pwd + - run: ls target/ + - run: ls target/release/ - name: Upload uses: actions/upload-artifact@v1 with: @@ -93,6 +102,9 @@ jobs: use-cross: true command: build args: --target x86_64-pc-windows-gnu + - run: pwd + - run: ls target/ + - run: ls target/release/ - name: Upload uses: actions/upload-artifact@v1 with: From 30f692735023526d39bb473e1fa56b7e762611e5 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 14:18:31 -0700 Subject: [PATCH 07/21] Fix upload error --- .github/workflows/rust.yml | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 746fd97..422cf60 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -24,15 +24,12 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - args: --verbose --release --all --tests + args: --verbose --release --all - name: Run tests uses: actions-rs/cargo@v1 with: command: test args: --verbose --release --all - - run: pwd - - run: ls target/ - - run: ls target/release/ - name: Upload uses: actions/upload-artifact@v1 with: @@ -53,10 +50,7 @@ jobs: with: use-cross: true command: build - args: --target armv7-unknown-linux-gnueabihf - - run: pwd - - run: ls target/ - - run: ls target/release/ + args: --release --target armv7-unknown-linux-gnueabihf - name: Upload uses: actions/upload-artifact@v1 with: @@ -77,36 +71,10 @@ jobs: with: use-cross: true command: build - args: --target aarch64-unknown-linux-gnu - - run: pwd - - run: ls target/ - - run: ls target/release/ + args: --release --target aarch64-unknown-linux-gnu - name: Upload uses: actions/upload-artifact@v1 with: name: linux_aarch64-zecwallet-cli path: target/aarch64-unknown-linux-gnu/release/zecwallet-cli - linux_mingw: - name: Linux mingw - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: x86_64-pc-windows-gnu - override: true - - uses: actions-rs/cargo@v1 - with: - use-cross: true - command: build - args: --target x86_64-pc-windows-gnu - - run: pwd - - run: ls target/ - - run: ls target/release/ - - name: Upload - uses: actions/upload-artifact@v1 - with: - name: linux_mingw-zecwallet-cli - path: target/x86_64-pc-windows-gnu/release/zecwallet-cli.exe From 959755d705b18d13a8dbdf0502c47818fe7a4e94 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 14:34:03 -0700 Subject: [PATCH 08/21] Conditional upload --- .github/workflows/rust.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 422cf60..3f634ac 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -30,11 +30,19 @@ jobs: with: command: test args: --verbose --release --all - - name: Upload + - name: Upload ubuntu/macos uses: actions/upload-artifact@v1 + if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') with: name: ${{ matrix.os }}-zecwallet-cli path: target/release/zecwallet-cli + - name: Upload windows + uses: actions/upload-artifact@v1 + if: contains(matrix.os, 'windows') + with: + name: ${{ matrix.os }}-zecwallet-cli.exe + path: target/release/zecwallet-cli.exe + linux_arm7: name: Linux ARMv7 From 59fc5a17c2e65e773afb0b79e0117b0323f9a063 Mon Sep 17 00:00:00 2001 From: DenioD Date: Tue, 22 Oct 2019 23:53:06 +0200 Subject: [PATCH 09/21] merged manually --- .github/workflows/rust.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 52af80e..f61dc33 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -30,11 +30,24 @@ jobs: with: command: test args: --verbose --release --all - - name: Upload + - name: Upload ubuntu/macos uses: actions/upload-artifact@v1 + if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') with: +<<<<<<< HEAD name: ${{ matrix.os }}-silentdragonlite-cli path: target/release/silentdragonlite-cli +======= + name: ${{ matrix.os }}-silentdragonlite-cli + path: target/release/silentdragonlite-cli + - name: Upload windows + uses: actions/upload-artifact@v1 + if: contains(matrix.os, 'windows') + with: + name: ${{ matrix.os }}-silentdragonlite-cli.exe + path: target/release/silentdragonlite-cli.exe + +>>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 linux_arm7: name: Linux ARMv7 From 66da04b40b1308c421b344e58daf6c4cf885d8e5 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 15:09:42 -0700 Subject: [PATCH 10/21] Build on ubuntu 1604 --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3f634ac..55461db 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] + os: [ubuntu-16.04, windows-latest, macOS-latest] steps: - uses: actions/checkout@v1 From cb5c55a8295a6c22d8e21cbde4476d96435b97cc Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 17:03:44 -0700 Subject: [PATCH 11/21] Add checkpoints --- lib/src/lightclient.rs | 28 ++++------ lib/src/lightclient/checkpoints.rs | 85 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 lib/src/lightclient/checkpoints.rs diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 0d17f8a..8e80cc8 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -25,6 +25,8 @@ use crate::grpcconnector::{self, *}; use crate::SaplingParams; use crate::ANCHOR_OFFSET; +mod checkpoints; + pub const DEFAULT_SERVER: &str = "https://lightd-main.zecwallet.co:443"; pub const WALLET_NAME: &str = "zecwallet-light-wallet.dat"; pub const LOGFILE_NAME: &str = "zecwallet-light-wallet.debug.log"; @@ -117,18 +119,8 @@ impl LightClientConfig { log_path.into_boxed_path() } - pub fn get_initial_state(&self) -> Option<(u64, &str, &str)> { - match &self.chain_name[..] { - "test" => Some((600000, - "0107385846c7451480912c294b6ce1ee1feba6c2619079fd9104f6e71e4d8fe7", - "01690698411e3f8badea7da885e556d7aba365a797e9b20b44ac0946dced14b23c001001ab2a18a5a86aa5d77e43b69071b21770b6fe6b3c26304dcaf7f96c0bb3fed74d000186482712fa0f2e5aa2f2700c4ed49ef360820f323d34e2b447b78df5ec4dfa0401a332e89a21afb073cb1db7d6f07396b56a95e97454b9bca5a63d0ebc575d3a33000000000001c9d3564eff54ebc328eab2e4f1150c3637f4f47516f879a0cfebdf49fe7b1d5201c104705fac60a85596010e41260d07f3a64f38f37a112eaef41cd9d736edc5270145e3d4899fcd7f0f1236ae31eafb3f4b65ad6b11a17eae1729cec09bd3afa01a000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39" - )), - "main" => Some((610000, - "000000000218882f481e3b49ca3df819734b8d74aac91f69e848d7499b34b472", - "0192943f1eca6525cea7ea8e26b37c792593ed50cfe2be7a1ff551a08dc64b812f001000000001deef7ae5162a9942b4b9aa797137c5bdf60750e9548664127df99d1981dda66901747ad24d5daf294ce2a27aba923e16e52e7348eea3048c5b5654b99ab0a371200149d8aff830305beb3887529f6deb150ab012916c3ce88a6b47b78228f8bfeb3f01ff84a89890cfae65e0852bc44d9aa82be2c5d204f5aebf681c9e966aa46f540e000001d58f1dfaa9db0996996129f8c474acb813bfed452d347fb17ebac2e775e209120000000001319312241b0031e3a255b0d708750b4cb3f3fe79e3503fe488cc8db1dd00753801754bb593ea42d231a7ddf367640f09bbf59dc00f2c1d2003cc340e0c016b5b13" - )), - _ => None - } + pub fn get_initial_state(&self, height: u64) -> Option<(u64, &str, &str)> { + checkpoints::get_closest_checkpoint(&self.chain_name, height) } pub fn get_server_or_default(server: Option) -> http::Uri { @@ -213,10 +205,10 @@ pub struct LightClient { impl LightClient { - pub fn set_wallet_initial_state(&self) { + pub fn set_wallet_initial_state(&self, height: u64) { use std::convert::TryInto; - let state = self.config.get_initial_state(); + let state = self.config.get_initial_state(height); match state { Some((height, hash, tree)) => self.wallet.read().unwrap().set_initial_block(height.try_into().unwrap(), hash, tree), @@ -242,7 +234,7 @@ impl LightClient { sapling_spend : vec![] }; - l.set_wallet_initial_state(); + l.set_wallet_initial_state(0); l.read_sapling_params(); info!("Created new wallet!"); @@ -266,7 +258,7 @@ impl LightClient { sapling_spend : vec![] }; - l.set_wallet_initial_state(); + l.set_wallet_initial_state(latest_block); l.read_sapling_params(); info!("Created new wallet with a new seed!"); @@ -288,7 +280,7 @@ impl LightClient { sapling_spend : vec![] }; - l.set_wallet_initial_state(); + l.set_wallet_initial_state(latest_block); l.read_sapling_params(); info!("Created new wallet!"); @@ -727,7 +719,7 @@ impl LightClient { self.wallet.read().unwrap().clear_blocks(); // Then set the initial block - self.set_wallet_initial_state(); + self.set_wallet_initial_state(self.wallet.read().unwrap().get_birthday()); // Then, do a sync, which will force a full rescan from the initial state let response = self.do_sync(true); diff --git a/lib/src/lightclient/checkpoints.rs b/lib/src/lightclient/checkpoints.rs new file mode 100644 index 0000000..cf140f3 --- /dev/null +++ b/lib/src/lightclient/checkpoints.rs @@ -0,0 +1,85 @@ +pub fn get_closest_checkpoint(chain_name: &str, height: u64) -> Option<(u64, &'static str, &'static str)> { + match chain_name { + "test" => get_test_checkpoint(height), + "main" => get_main_checkpoint(height), + _ => None + } +} + +fn get_test_checkpoint(height: u64) -> Option<(u64, &'static str, &'static str)> { + let checkpoints: Vec<(u64, &str, &str)> = vec![ + (600000, "0107385846c7451480912c294b6ce1ee1feba6c2619079fd9104f6e71e4d8fe7", + "01690698411e3f8badea7da885e556d7aba365a797e9b20b44ac0946dced14b23c001001ab2a18a5a86aa5d77e43b69071b21770b6fe6b3c26304dcaf7f96c0bb3fed74d000186482712fa0f2e5aa2f2700c4ed49ef360820f323d34e2b447b78df5ec4dfa0401a332e89a21afb073cb1db7d6f07396b56a95e97454b9bca5a63d0ebc575d3a33000000000001c9d3564eff54ebc328eab2e4f1150c3637f4f47516f879a0cfebdf49fe7b1d5201c104705fac60a85596010e41260d07f3a64f38f37a112eaef41cd9d736edc5270145e3d4899fcd7f0f1236ae31eafb3f4b65ad6b11a17eae1729cec09bd3afa01a000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39" + ) + ]; + + find_checkpoint(height, checkpoints) +} + + +fn get_main_checkpoint(height: u64) -> Option<(u64, &'static str, &'static str)> { + let checkpoints: Vec<(u64, &str, &str)> = vec![ + (610000, "000000000218882f481e3b49ca3df819734b8d74aac91f69e848d7499b34b472", + "0192943f1eca6525cea7ea8e26b37c792593ed50cfe2be7a1ff551a08dc64b812f001000000001deef7ae5162a9942b4b9aa797137c5bdf60750e9548664127df99d1981dda66901747ad24d5daf294ce2a27aba923e16e52e7348eea3048c5b5654b99ab0a371200149d8aff830305beb3887529f6deb150ab012916c3ce88a6b47b78228f8bfeb3f01ff84a89890cfae65e0852bc44d9aa82be2c5d204f5aebf681c9e966aa46f540e000001d58f1dfaa9db0996996129f8c474acb813bfed452d347fb17ebac2e775e209120000000001319312241b0031e3a255b0d708750b4cb3f3fe79e3503fe488cc8db1dd00753801754bb593ea42d231a7ddf367640f09bbf59dc00f2c1d2003cc340e0c016b5b13" + ) + ]; + + find_checkpoint(height, checkpoints) +} + +fn find_checkpoint(height: u64, chkpts: Vec<(u64, &'static str, &'static str)>) -> Option<(u64, &'static str, &'static str)> { + // Find the closest checkpoint + let mut heights = chkpts.iter().map(|(h, _, _)| *h as u64).collect::>(); + heights.sort(); + + match get_first_lower_than(height, heights) { + Some(closest_height) => { + chkpts.iter().find(|(h, _, _)| *h == closest_height).map(|t| *t) + }, + None => None + } +} + +fn get_first_lower_than(height: u64, heights: Vec) -> Option { + // If it's before the first checkpoint, return None. + if heights.len() == 0 || height < heights[0] { + return None; + } + + for (i, h) in heights.iter().enumerate() { + if height < *h { + return Some(heights[i-1]); + } + } + + return Some(*heights.last().unwrap()); +} + +#[cfg(test)] +pub mod tests { + use super::*; + + #[test] + fn test_lower_than() { + assert_eq!(get_first_lower_than( 9, vec![10, 30, 40]), None); + assert_eq!(get_first_lower_than(10, vec![10, 30, 40]).unwrap(), 10); + assert_eq!(get_first_lower_than(11, vec![10, 30, 40]).unwrap(), 10); + assert_eq!(get_first_lower_than(29, vec![10, 30, 40]).unwrap(), 10); + assert_eq!(get_first_lower_than(30, vec![10, 30, 40]).unwrap(), 30); + assert_eq!(get_first_lower_than(40, vec![10, 30, 40]).unwrap(), 40); + assert_eq!(get_first_lower_than(41, vec![10, 30, 40]).unwrap(), 40); + assert_eq!(get_first_lower_than(99, vec![10, 30, 40]).unwrap(), 40); + } + + #[test] + fn test_checkpoints() { + assert_eq!(get_test_checkpoint(500000), None); + assert_eq!(get_test_checkpoint(600000).unwrap().0, 600000); + assert_eq!(get_test_checkpoint(625000).unwrap().0, 600000); + + assert_eq!(get_main_checkpoint(500000), None); + assert_eq!(get_main_checkpoint(610000).unwrap().0, 610000); + assert_eq!(get_main_checkpoint(625000).unwrap().0, 610000); + } + +} \ No newline at end of file From adba18e13bd181980af0784f6c548593961f6cd9 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 21:03:11 -0700 Subject: [PATCH 12/21] Add new testnet checkpoint --- lib/src/lightclient/checkpoints.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/lightclient/checkpoints.rs b/lib/src/lightclient/checkpoints.rs index cf140f3..61e7e69 100644 --- a/lib/src/lightclient/checkpoints.rs +++ b/lib/src/lightclient/checkpoints.rs @@ -10,6 +10,9 @@ fn get_test_checkpoint(height: u64) -> Option<(u64, &'static str, &'static str) let checkpoints: Vec<(u64, &str, &str)> = vec![ (600000, "0107385846c7451480912c294b6ce1ee1feba6c2619079fd9104f6e71e4d8fe7", "01690698411e3f8badea7da885e556d7aba365a797e9b20b44ac0946dced14b23c001001ab2a18a5a86aa5d77e43b69071b21770b6fe6b3c26304dcaf7f96c0bb3fed74d000186482712fa0f2e5aa2f2700c4ed49ef360820f323d34e2b447b78df5ec4dfa0401a332e89a21afb073cb1db7d6f07396b56a95e97454b9bca5a63d0ebc575d3a33000000000001c9d3564eff54ebc328eab2e4f1150c3637f4f47516f879a0cfebdf49fe7b1d5201c104705fac60a85596010e41260d07f3a64f38f37a112eaef41cd9d736edc5270145e3d4899fcd7f0f1236ae31eafb3f4b65ad6b11a17eae1729cec09bd3afa01a000000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39" + ), + (650000, "003f7e09a357a75c3742af1b7e1189a9038a360cebb9d55e158af94a1c5aa682", + "010113f257f93a40e25cfc8161022f21c06fa2bc7fb03ee9f9399b3b30c636715301ef5b99706e40a19596d758bf7f4fd1b83c3054557bf7fab4801985642c317d41100001b2ad599fd7062af72bea99438dc5d8c3aa66ab52ed7dee3e066c4e762bd4e42b0001599dd114ec6c4c5774929a342d530bf109b131b48db2d20855afa9d37c92d6390000019159393c84b1bf439d142ed2c54ee8d5f7599a8b8f95e4035a75c30b0ec0fa4c0128e3a018bd08b2a98ed8b6995826f5857a9dc2777ce6af86db1ae68b01c3c53d0000000001e3ec5d790cc9acc2586fc6e9ce5aae5f5aba32d33e386165c248c4a03ec8ed670000011f8322ef806eb2430dc4a7a41c1b344bea5be946efc7b4349c1c9edb14ff9d39" ) ]; @@ -76,6 +79,8 @@ pub mod tests { assert_eq!(get_test_checkpoint(500000), None); assert_eq!(get_test_checkpoint(600000).unwrap().0, 600000); assert_eq!(get_test_checkpoint(625000).unwrap().0, 600000); + assert_eq!(get_test_checkpoint(650000).unwrap().0, 650000); + assert_eq!(get_test_checkpoint(655000).unwrap().0, 650000); assert_eq!(get_main_checkpoint(500000), None); assert_eq!(get_main_checkpoint(610000).unwrap().0, 610000); From 11bc928f8d130c28f17b65324dd85f2dba1911df Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 22 Oct 2019 21:03:23 -0700 Subject: [PATCH 13/21] Need birthday while restoring seed --- cli/src/main.rs | 38 ++++++++++++++++++++++++++++++-------- lib/src/lightclient.rs | 27 +++++++++++++++++++-------- lib/src/lightwallet.rs | 12 ++++++++---- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index a9f96ae..48574ef 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -61,6 +61,11 @@ pub fn main() { .value_name("seed_phrase") .help("Create a new wallet with the given 24-word seed phrase. Will fail if wallet already exists") .takes_value(true)) + .arg(Arg::with_name("birthday") + .long("birthday") + .value_name("birthday") + .help("Specify wallet birthday when restoring from seed. This is the earlist block height where the wallet has a transaction.") + .takes_value(true)) .arg(Arg::with_name("server") .long("server") .value_name("server") @@ -112,8 +117,25 @@ pub fn main() { let command = matches.value_of("COMMAND"); let params = matches.values_of("PARAMS").map(|v| v.collect()).or(Some(vec![])).unwrap(); - let maybe_server = matches.value_of("server").map(|s| s.to_string()); - let seed = matches.value_of("seed").map(|s| s.to_string()); + let maybe_server = matches.value_of("server").map(|s| s.to_string()); + + let seed = matches.value_of("seed").map(|s| s.to_string()); + let maybe_birthday = matches.value_of("birthday"); + + if seed.is_some() && maybe_birthday.is_none() { + eprintln!("ERROR!"); + eprintln!("Please specify the wallet birthday (eg. '--birthday 600000') to restore from seed."); + eprintln!("This should be the block height where the wallet was created. If you don't remember the block height, you can pass '--birthday 0' to scan from the start of the blockchain."); + return; + } + + let birthday = match maybe_birthday.unwrap_or("0").parse::() { + Ok(b) => b, + Err(e) => { + eprintln!("Couldn't parse birthday. This should be a block number. Error={}", e); + return; + } + }; let server = LightClientConfig::get_server_or_default(maybe_server); @@ -125,7 +147,7 @@ pub fn main() { let dangerous = matches.is_present("dangerous"); let nosync = matches.is_present("nosync"); - let (command_tx, resp_rx) = match startup(server, dangerous, seed, !nosync, command.is_none()) { + let (command_tx, resp_rx) = match startup(server, dangerous, seed, birthday, !nosync, command.is_none()) { Ok(c) => c, Err(e) => { eprintln!("Error during startup: {}", e); @@ -163,7 +185,7 @@ pub fn main() { } } -fn startup(server: http::Uri, dangerous: bool, seed: Option, first_sync: bool, print_updates: bool) +fn startup(server: http::Uri, dangerous: bool, seed: Option, birthday: u64, first_sync: bool, print_updates: bool) -> io::Result<(Sender<(String, Vec)>, Receiver)> { // Try to get the configuration let (config, latest_block_height) = LightClientConfig::create(server.clone(), dangerous)?; @@ -175,7 +197,7 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option, first_sync: })?; let lightclient = match seed { - Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, latest_block_height)?), + Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday)?), None => { if config.wallet_exists() { Arc::new(LightClient::read_from_disk(&config)?) @@ -195,9 +217,6 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option, first_sync: println!("Lightclient connecting to {}", config.server); } - // Start the command loop - let (command_tx, resp_rx) = command_loop(lightclient.clone()); - // At startup, run a sync. if first_sync { let update = lightclient.do_sync(true); @@ -206,6 +225,9 @@ fn startup(server: http::Uri, dangerous: bool, seed: Option, first_sync: } } + // Start the command loop + let (command_tx, resp_rx) = command_loop(lightclient.clone()); + Ok((command_tx, resp_rx)) } diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 8e80cc8..0be799d 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -3,7 +3,7 @@ use crate::lightwallet::LightWallet; use log::{info, warn, error}; use rand::{rngs::OsRng, seq::SliceRandom}; -use std::sync::{Arc, RwLock}; +use std::sync::{Arc, RwLock, Mutex}; use std::sync::atomic::{AtomicU64, AtomicI32, AtomicUsize, Ordering}; use std::path::{Path, PathBuf}; use std::fs::File; @@ -201,6 +201,8 @@ pub struct LightClient { // zcash-params pub sapling_output : Vec, pub sapling_spend : Vec, + + sync_lock : Mutex<()>, } impl LightClient { @@ -231,7 +233,8 @@ impl LightClient { wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), &config, 0)?)), config : config.clone(), sapling_output : vec![], - sapling_spend : vec![] + sapling_spend : vec![], + sync_lock : Mutex::new(()), }; l.set_wallet_initial_state(0); @@ -255,7 +258,8 @@ impl LightClient { wallet : Arc::new(RwLock::new(LightWallet::new(None, config, latest_block)?)), config : config.clone(), sapling_output : vec![], - sapling_spend : vec![] + sapling_spend : vec![], + sync_lock : Mutex::new(()), }; l.set_wallet_initial_state(latest_block); @@ -267,20 +271,22 @@ impl LightClient { Ok(l) } - pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, latest_block: u64) -> io::Result { + pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, birthday: u64) -> io::Result { if config.wallet_exists() { return Err(Error::new(ErrorKind::AlreadyExists, "Cannot create a new wallet from seed, because a wallet already exists")); } let mut l = LightClient { - wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), config, latest_block)?)), + wallet : Arc::new(RwLock::new(LightWallet::new(Some(seed_phrase), config, birthday)?)), config : config.clone(), sapling_output : vec![], - sapling_spend : vec![] + sapling_spend : vec![], + sync_lock : Mutex::new(()), }; - l.set_wallet_initial_state(latest_block); + println!("Setting birthday to {}", birthday); + l.set_wallet_initial_state(birthday); l.read_sapling_params(); info!("Created new wallet!"); @@ -302,7 +308,8 @@ impl LightClient { wallet : Arc::new(RwLock::new(wallet)), config : config.clone(), sapling_output : vec![], - sapling_spend : vec![] + sapling_spend : vec![], + sync_lock : Mutex::new(()), }; lc.read_sapling_params(); @@ -729,6 +736,10 @@ impl LightClient { } pub fn do_sync(&self, print_updates: bool) -> String { + // We can only do one sync at a time because we sync blocks in serial order + // If we allow multiple syncs, they'll all get jumbled up. + let _lock = self.sync_lock.lock().unwrap(); + // Sync is 3 parts // 1. Get the latest block // 2. Get all the blocks that we don't have diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 6cf8c2b..df1d1c1 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -358,8 +358,8 @@ impl LightWallet { })?; utils::write_string(&mut writer, &self.config.chain_name)?; - // While writing the birthday, be sure that we're right, and that we don't - // have a tx that is before the current birthday + // While writing the birthday, get it from the fn so we recalculate it properly + // in case of rescans etc... writer.write_u64::(self.get_birthday())?; Ok(()) @@ -373,7 +373,11 @@ impl LightWallet { } pub fn get_birthday(&self) -> u64 { - cmp::min(self.get_first_tx_block(), self.birthday) + if self.birthday == 0 { + self.get_first_tx_block() + } else { + cmp::min(self.get_first_tx_block(), self.birthday) + } } // Get the first block that this wallet has a tx in. This is often used as the wallet's "birthday" @@ -386,7 +390,7 @@ impl LightWallet { .collect::>(); blocks.sort(); - *blocks.first() // Returns optional + *blocks.first() // Returns optional, so if there's no txns, it'll get the activation height .unwrap_or(&cmp::max(self.birthday, self.config.sapling_activation_height)) } From f6e87caf516a7fc4e5164c51b915db01c74453f2 Mon Sep 17 00:00:00 2001 From: DenioD Date: Wed, 23 Oct 2019 15:00:38 +0200 Subject: [PATCH 14/21] merged manually --- .github/workflows/rust.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index abc5ddd..fd6c66f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,31 +34,15 @@ jobs: uses: actions/upload-artifact@v1 if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu') with: -<<<<<<< HEAD -<<<<<<< HEAD name: ${{ matrix.os }}-silentdragonlite-cli path: target/release/silentdragonlite-cli -======= - name: ${{ matrix.os }}-silentdragonlite-cli - path: target/release/silentdragonlite-cli -======= - name: ${{ matrix.os }}-zecwallet-cli - path: target/release/zecwallet-cli ->>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 - name: Upload windows uses: actions/upload-artifact@v1 if: contains(matrix.os, 'windows') with: -<<<<<<< HEAD name: ${{ matrix.os }}-silentdragonlite-cli.exe path: target/release/silentdragonlite-cli.exe ->>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 -======= - name: ${{ matrix.os }}-zecwallet-cli.exe - path: target/release/zecwallet-cli.exe - ->>>>>>> 959755d705b18d13a8dbdf0502c47818fe7a4e94 linux_arm7: name: Linux ARMv7 From da955de8b7bb35794460fa477237b53fef7739ea Mon Sep 17 00:00:00 2001 From: DenioD Date: Wed, 23 Oct 2019 20:58:26 +0200 Subject: [PATCH 15/21] change address Prefix --- lib/src/lightclient.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 640aabd..d8f8da3 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -709,7 +709,7 @@ impl LightClient { let new_address = match addr_type { "z" => wallet.add_zaddr(), - "t" => wallet.add_taddr(), + "R" => wallet.add_taddr(), _ => { let e = format!("Unrecognized address type: {}", addr_type); error!("{}", e); @@ -980,14 +980,14 @@ pub mod tests { assert!(!lc.do_export(None).is_err()); assert!(!lc.do_new_address("z").is_err()); - assert!(!lc.do_new_address("t").is_err()); + assert!(!lc.do_new_address("R").is_err()); assert_eq!(lc.do_seed_phrase().unwrap()["seed"], TEST_SEED.to_string()); // Encrypt and Lock the wallet lc.wallet.write().unwrap().encrypt("password".to_string()).unwrap(); assert!(lc.do_export(None).is_err()); assert!(lc.do_seed_phrase().is_err()); - assert!(lc.do_new_address("t").is_err()); + assert!(lc.do_new_address("R").is_err()); assert!(lc.do_new_address("z").is_err()); assert!(lc.do_send(vec![("z", 0, None)]).is_err()); @@ -995,7 +995,7 @@ pub mod tests { lc.wallet.write().unwrap().unlock("password".to_string()).unwrap(); assert!(!lc.do_export(None).is_err()); assert!(!lc.do_seed_phrase().is_err()); - assert!(!lc.do_new_address("t").is_err()); + assert!(!lc.do_new_address("R").is_err()); assert!(!lc.do_new_address("z").is_err()); } @@ -1005,8 +1005,8 @@ pub mod tests { // Add new z and t addresses - let taddr1 = lc.do_new_address("t").unwrap()[0].as_str().unwrap().to_string(); - let taddr2 = lc.do_new_address("t").unwrap()[0].as_str().unwrap().to_string(); + let taddr1 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); + let taddr2 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); let zaddr1 = lc.do_new_address("z").unwrap()[0].as_str().unwrap().to_string(); let zaddr2 = lc.do_new_address("z").unwrap()[0].as_str().unwrap().to_string(); From ac0c282753e84df74b32543c1e4f7978f3a0fc75 Mon Sep 17 00:00:00 2001 From: DenioD Date: Wed, 23 Oct 2019 23:58:12 +0200 Subject: [PATCH 16/21] fix zs address --- lib/src/lightclient.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index d8f8da3..08f2338 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -708,7 +708,7 @@ impl LightClient { let wallet = self.wallet.write().unwrap(); let new_address = match addr_type { - "z" => wallet.add_zaddr(), + "zs1" => wallet.add_zaddr(), "R" => wallet.add_taddr(), _ => { let e = format!("Unrecognized address type: {}", addr_type); @@ -979,7 +979,7 @@ pub mod tests { let lc = super::LightClient::unconnected(TEST_SEED.to_string(), None).unwrap(); assert!(!lc.do_export(None).is_err()); - assert!(!lc.do_new_address("z").is_err()); + assert!(!lc.do_new_address("zs1").is_err()); assert!(!lc.do_new_address("R").is_err()); assert_eq!(lc.do_seed_phrase().unwrap()["seed"], TEST_SEED.to_string()); @@ -988,15 +988,15 @@ pub mod tests { assert!(lc.do_export(None).is_err()); assert!(lc.do_seed_phrase().is_err()); assert!(lc.do_new_address("R").is_err()); - assert!(lc.do_new_address("z").is_err()); - assert!(lc.do_send(vec![("z", 0, None)]).is_err()); + assert!(lc.do_new_address("zs1").is_err()); + assert!(lc.do_send(vec![("zs1", 0, None)]).is_err()); // Do a unlock, and make sure it all works now lc.wallet.write().unwrap().unlock("password".to_string()).unwrap(); assert!(!lc.do_export(None).is_err()); assert!(!lc.do_seed_phrase().is_err()); assert!(!lc.do_new_address("R").is_err()); - assert!(!lc.do_new_address("z").is_err()); + assert!(!lc.do_new_address("zs1").is_err()); } #[test] @@ -1007,8 +1007,8 @@ pub mod tests { let taddr1 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); let taddr2 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); - let zaddr1 = lc.do_new_address("z").unwrap()[0].as_str().unwrap().to_string(); - let zaddr2 = lc.do_new_address("z").unwrap()[0].as_str().unwrap().to_string(); + let zaddr1 = lc.do_new_address("zs1").unwrap()[0].as_str().unwrap().to_string(); + let zaddr2 = lc.do_new_address("zs1").unwrap()[0].as_str().unwrap().to_string(); let addresses = lc.do_address(); assert_eq!(addresses["z_addresses"].len(), 3); From 8ac15162cf70c696f6bc1998fbe02a1b1f34e6d0 Mon Sep 17 00:00:00 2001 From: DenioD Date: Thu, 24 Oct 2019 00:52:27 +0200 Subject: [PATCH 17/21] update librustzcash commit height --- lib/Cargo.toml | 12 ++++++------ lib/src/lightwallet/tests.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 157bdce..3bac14e 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -38,34 +38,34 @@ sodiumoxide = "0.2.5" [dependencies.bellman] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" default-features = false features = ["groth16"] [dependencies.pairing] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" [dependencies.zcash_client_backend] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" default-features = false [dependencies.zcash_primitives] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" default-features = false features = ["transparent-inputs"] [dependencies.zcash_proofs] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" default-features = false [dependencies.ff] git = "https://github.com/DenioD/librustzcash.git" -rev= "44a1c3981df37b73d87f0e625ca3557d8534e6f3" +rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" features = ["ff_derive"] [build-dependencies] diff --git a/lib/src/lightwallet/tests.rs b/lib/src/lightwallet/tests.rs index 469d022..bf5ae88 100644 --- a/lib/src/lightwallet/tests.rs +++ b/lib/src/lightwallet/tests.rs @@ -1601,18 +1601,18 @@ fn test_t_derivation() { // Test the addresses against https://iancoleman.io/bip39/ let (taddr, pk) = &wallet.get_t_secret_keys()[0]; - assert_eq!(taddr, "t1eQ63fwkQ4n4Eo5uCrPGaAV8FWB2tmx7ui"); - assert_eq!(pk, "Kz9ybX4giKag4NtnP1pi8WQF2B2hZDkFU85S7Dciz3UUhM59AnhE"); + assert_eq!(taddr, "RXBxhYDg8vSsHVmAGadniQKh3NvzAtzjRe"); + assert_eq!(pk, "UvGDnY7bpsyz9GnRPvMRQTMKHPyCK5k6c2FBiGQcgRSe9xVNuGGs"); // Test a couple more wallet.add_taddr(); let (taddr, pk) = &wallet.get_t_secret_keys()[1]; - assert_eq!(taddr, "t1NoS6ZgaUTpmjkge2cVpXGcySasdYDrXqh"); - assert_eq!(pk, "KxdmS38pxskS6bbKX43zhTu8ppWckNmWjKsQFX1hwidvhRRgRd3c"); + assert_eq!(taddr, "RKDGjDoFHf9BfTFuL27voFdqdV7LhWw9rG"); + assert_eq!(pk, "UqGi6D8rFfdoEtbqhjz1utu1hKLmagY5TBVHWau54pput9HRfYbG"); let (zaddr, sk) = &wallet.get_z_private_keys()[0]; - assert_eq!(zaddr, "zs1q6xk3q783t5k92kjqt2rkuuww8pdw2euzy5rk6jytw97enx8fhpazdv3th4xe7vsk6e9sfpawfg"); - assert_eq!(sk, "secret-extended-key-main1qvpa0qr8qqqqpqxn4l054nzxpxzp3a8r2djc7sekdek5upce8mc2j2z0arzps4zv940qeg706hd0wq6g5snzvhp332y6vhwyukdn8dhekmmsk7fzvzkqm6ypc99uy63tpesqwxhpre78v06cx8k5xpp9mrhtgqs5dvp68cqx2yrvthflmm2ynl8c0506dekul0f6jkcdmh0292lpphrksyc5z3pxwws97zd5els3l2mjt2s7hntap27mlmt6w0drtfmz36vz8pgu7ec0twfrq"); + assert_eq!(zaddr, "zs1wp96063hjs496d28e05uz5gavg7mwshhsgglchtan57el88uwa5jfdgk4nd68kda62vgwucfe6z"); + assert_eq!(sk, "secret-extended-key-main1qvkk0dn2qqqqpqrk6fl6c6fzzrmkhlj59d2c6kkz37hmal6d4dm69ne75xf0exuvnyk6qrjgp6crvdtaehkda2edg0llv488u25vjh5jtldnp53nrphqeexel57a0dn4t2kkcr6uj6y832yg8wsx3wx6t6rk470dynzdx3cp37xdwl9mpe59vj6yqh67x09vea9khzk5wdqkt65c6x9qkuht7nxyetthu0pr7jrwpthzq2ncgm0dvczadqxuhhk5ekua5v5zzw2kydcudu965"); assert_eq!(seed_phrase, Some(wallet.get_seed_phrase())); } From 61f016c871c33b02993c75569eca38de49941308 Mon Sep 17 00:00:00 2001 From: DenioD Date: Thu, 24 Oct 2019 01:08:34 +0200 Subject: [PATCH 18/21] fix prefix --- lib/src/lightwallet.rs | 2 +- lib/src/lightwallet/data.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index 3d799a5..a1bcc3a 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -153,7 +153,7 @@ impl LightWallet { let extsk: ExtendedSpendingKey = ExtendedSpendingKey::from_path( &ExtendedSpendingKey::master(bip39_seed), &[ - ChildIndex::Hardened(32), + ChildIndex::Hardened(31), ChildIndex::Hardened(config.get_coin_type()), ChildIndex::Hardened(pos) ], diff --git a/lib/src/lightwallet/data.rs b/lib/src/lightwallet/data.rs index 38128ca..3ebc254 100644 --- a/lib/src/lightwallet/data.rs +++ b/lib/src/lightwallet/data.rs @@ -267,7 +267,7 @@ impl Utxo { let mut address_bytes = vec![0; address_len as usize]; reader.read_exact(&mut address_bytes)?; let address = String::from_utf8(address_bytes).unwrap(); - assert_eq!(address.chars().take(1).collect::>()[0], 't'); + assert_eq!(address.chars().take(1).collect::>()[0], 'R'); let mut txid_bytes = [0; 32]; reader.read_exact(&mut txid_bytes)?; From 25ed8e2a62b38595cd4c0cd68e9bee7276fcca58 Mon Sep 17 00:00:00 2001 From: DenioD Date: Thu, 24 Oct 2019 01:25:46 +0200 Subject: [PATCH 19/21] fix --- lib/Cargo.toml | 12 ++++++------ lib/src/lightclient.rs | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 3bac14e..27260db 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -38,34 +38,34 @@ sodiumoxide = "0.2.5" [dependencies.bellman] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" default-features = false features = ["groth16"] [dependencies.pairing] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" [dependencies.zcash_client_backend] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" default-features = false [dependencies.zcash_primitives] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" default-features = false features = ["transparent-inputs"] [dependencies.zcash_proofs] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" default-features = false [dependencies.ff] git = "https://github.com/DenioD/librustzcash.git" -rev= "b51e7c055b9dff6fc6e15a7b619a2d2416b0ca8e" +rev= "caaee693c47c2ee9ecd1e1546b8fe3c714f342bc" features = ["ff_derive"] [build-dependencies] diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 08f2338..9f9fb02 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -708,7 +708,7 @@ impl LightClient { let wallet = self.wallet.write().unwrap(); let new_address = match addr_type { - "zs1" => wallet.add_zaddr(), + "zs" => wallet.add_zaddr(), "R" => wallet.add_taddr(), _ => { let e = format!("Unrecognized address type: {}", addr_type); @@ -979,7 +979,7 @@ pub mod tests { let lc = super::LightClient::unconnected(TEST_SEED.to_string(), None).unwrap(); assert!(!lc.do_export(None).is_err()); - assert!(!lc.do_new_address("zs1").is_err()); + assert!(!lc.do_new_address("zs").is_err()); assert!(!lc.do_new_address("R").is_err()); assert_eq!(lc.do_seed_phrase().unwrap()["seed"], TEST_SEED.to_string()); @@ -988,15 +988,15 @@ pub mod tests { assert!(lc.do_export(None).is_err()); assert!(lc.do_seed_phrase().is_err()); assert!(lc.do_new_address("R").is_err()); - assert!(lc.do_new_address("zs1").is_err()); - assert!(lc.do_send(vec![("zs1", 0, None)]).is_err()); + assert!(lc.do_new_address("zs").is_err()); + assert!(lc.do_send(vec![("zs", 0, None)]).is_err()); // Do a unlock, and make sure it all works now lc.wallet.write().unwrap().unlock("password".to_string()).unwrap(); assert!(!lc.do_export(None).is_err()); assert!(!lc.do_seed_phrase().is_err()); assert!(!lc.do_new_address("R").is_err()); - assert!(!lc.do_new_address("zs1").is_err()); + assert!(!lc.do_new_address("zs").is_err()); } #[test] @@ -1007,8 +1007,8 @@ pub mod tests { let taddr1 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); let taddr2 = lc.do_new_address("R").unwrap()[0].as_str().unwrap().to_string(); - let zaddr1 = lc.do_new_address("zs1").unwrap()[0].as_str().unwrap().to_string(); - let zaddr2 = lc.do_new_address("zs1").unwrap()[0].as_str().unwrap().to_string(); + let zaddr1 = lc.do_new_address("zs").unwrap()[0].as_str().unwrap().to_string(); + let zaddr2 = lc.do_new_address("zs").unwrap()[0].as_str().unwrap().to_string(); let addresses = lc.do_address(); assert_eq!(addresses["z_addresses"].len(), 3); From 6dc22e4d74e9cec458d279d793477dea3bfe27e5 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 24 Oct 2019 11:50:07 -0700 Subject: [PATCH 20/21] Safely handler seed phrases --- lib/src/lightwallet.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index df1d1c1..4376ccd 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -171,8 +171,16 @@ impl LightWallet { let mut system_rng = OsRng; system_rng.fill(&mut seed_bytes); } else { - seed_bytes.copy_from_slice(&Mnemonic::from_phrase(seed_phrase.expect("should have a seed phrase"), - Language::English).unwrap().entropy()); + let phrase = match Mnemonic::from_phrase(seed_phrase.unwrap(), Language::English) { + Ok(p) => p, + Err(e) => { + let e = format!("Error parsing phrase: {}", e); + error!("{}", e); + return Err(io::Error::new(ErrorKind::InvalidData, e)); + } + }; + + seed_bytes.copy_from_slice(&phrase.entropy()); } // The seed bytes is the raw entropy. To pass it to HD wallet generation, @@ -1296,7 +1304,7 @@ impl LightWallet { // Print info about the block every 10,000 blocks if height % 10_000 == 0 { match self.get_sapling_tree() { - Ok((h, hash, stree)) => info!("Sapling tree at height {}/{} - {}", h, hash, stree), + Ok((h, hash, stree)) => info!("Sapling tree at height\n({}, \"{}\",\"{}\"),", h, hash, stree), Err(e) => error!("Couldn't determine sapling tree: {}", e) } } From 39fd884ded0d5a8419dfa1ddb6ff6d3275018215 Mon Sep 17 00:00:00 2001 From: DenioD Date: Thu, 24 Oct 2019 23:23:04 +0200 Subject: [PATCH 21/21] fix broken balance --- lib/src/commands.rs | 2 +- lib/src/lightclient.rs | 10 +++++----- lib/src/lightwallet.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/commands.rs b/lib/src/commands.rs index f25ab6c..80ba787 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -382,7 +382,7 @@ impl Command for SendCommand { h.push("Usage:"); h.push("send
\"optional_memo\""); h.push("OR"); - h.push("send '[{'address':
, 'amount': , 'memo': }, ...]'"); + h.push("send '[{'address':
, 'amount': , 'memo': }, ...]'"); h.push(""); h.push("Example:"); h.push("send ztestsapling1x65nq4dgp0qfywgxcwk9n0fvm4fysmapgr2q00p85ju252h6l7mmxu2jg9cqqhtvzd69jwhgv8d 200000 \"Hello from the command line\""); diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index 9f9fb02..1f130e4 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -436,16 +436,16 @@ impl LightClient { let z_addresses = wallet.zaddress.read().unwrap().iter().map( |ad| { let address = encode_payment_address(self.config.hrp_sapling_address(), &ad); object!{ - "address" => address.clone(), - "zbalance" => wallet.zbalance(Some(address.clone())), - "verified_zbalance" => wallet.verified_zbalance(Some(address)), + "address" => address.clone() , + "zbalance" => wallet.zbalance(Some(address.clone())) , + "verified_zbalance" => wallet.verified_zbalance(Some(address)) , } }).collect::>(); // Collect t addresses let t_addresses = wallet.taddresses.read().unwrap().iter().map( |address| { // Get the balance for this address - let balance = wallet.tbalance(Some(address.clone())); + let balance = wallet.tbalance(Some(address.clone())) ; object!{ "address" => address.clone(), @@ -456,7 +456,7 @@ impl LightClient { object!{ "zbalance" => wallet.zbalance(None), "verified_zbalance" => wallet.verified_zbalance(None), - "tbalance" => wallet.tbalance(None), + "tbalance" => wallet.tbalance(None), "z_addresses" => z_addresses, "t_addresses" => t_addresses, } diff --git a/lib/src/lightwallet.rs b/lib/src/lightwallet.rs index a1bcc3a..a978060 100644 --- a/lib/src/lightwallet.rs +++ b/lib/src/lightwallet.rs @@ -153,7 +153,7 @@ impl LightWallet { let extsk: ExtendedSpendingKey = ExtendedSpendingKey::from_path( &ExtendedSpendingKey::master(bip39_seed), &[ - ChildIndex::Hardened(31), + ChildIndex::Hardened(32), ChildIndex::Hardened(config.get_coin_type()), ChildIndex::Hardened(pos) ], @@ -1335,7 +1335,7 @@ impl LightWallet { let total_value = tos.iter().map(|to| to.1).sum::(); println!( - "0: Creating transaction sending {} ztoshis to {} addresses", + "0: Creating transaction sending {} puposhis to {} addresses", total_value, tos.len() );