2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1724,7 +1724,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "silentdragonlite-cli"
|
name = "silentdragonlite-cli"
|
||||||
version = "1.3.2"
|
version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "silentdragonlite-cli"
|
name = "silentdragonlite-cli"
|
||||||
version = "1.3.2"
|
version = "1.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use silentdragonlitelib::{commands,
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! configure_clapapp {
|
macro_rules! configure_clapapp {
|
||||||
( $freshapp: expr ) => {
|
( $freshapp: expr ) => {
|
||||||
$freshapp.version("1.3.2")
|
$freshapp.version("1.0.0")
|
||||||
.arg(Arg::with_name("dangerous")
|
.arg(Arg::with_name("dangerous")
|
||||||
.long("dangerous")
|
.long("dangerous")
|
||||||
.help("Disable server TLS certificate verification. Use this if you're running a local lightwalletd with a self-signed certificate. WARNING: This is dangerous, don't use it with a server that is not your own.")
|
.help("Disable server TLS certificate verification. Use this if you're running a local lightwalletd with a self-signed certificate. WARNING: This is dangerous, don't use it with a server that is not your own.")
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub const VERSION:&str = "1.3.2";
|
pub const VERSION:&str = "1.1.0";
|
||||||
@@ -241,7 +241,10 @@ impl Command for BalanceCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||||
format!("{}", lightclient.do_balance().pretty(2))
|
match lightclient.do_sync(true) {
|
||||||
|
Ok(_) => format!("{}", lightclient.do_balance().pretty(2)),
|
||||||
|
Err(e) => e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,7 +649,12 @@ impl Command for TransactionsCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||||
format!("{}", lightclient.do_list_transactions().pretty(2))
|
match lightclient.do_sync(true) {
|
||||||
|
Ok(_) => {
|
||||||
|
format!("{}", lightclient.do_list_transactions().pretty(2))
|
||||||
|
},
|
||||||
|
Err(e) => e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +680,14 @@ impl Command for HeightCommand {
|
|||||||
return format!("Didn't understand arguments\n{}", self.help());
|
return format!("Didn't understand arguments\n{}", self.help());
|
||||||
}
|
}
|
||||||
|
|
||||||
format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2))
|
if args.len() == 0 || (args.len() == 1 && args[0].trim() == "true") {
|
||||||
|
match lightclient.do_sync(true) {
|
||||||
|
Ok(_) => format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2)),
|
||||||
|
Err(e) => e
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
format!("{}", object! { "height" => lightclient.last_scanned_height()}.pretty(2))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,7 +785,12 @@ impl Command for NotesCommand {
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
format!("{}", lightclient.do_list_notes(all_notes).pretty(2))
|
match lightclient.do_sync(true) {
|
||||||
|
Ok(_) => {
|
||||||
|
format!("{}", lightclient.do_list_notes(all_notes).pretty(2))
|
||||||
|
},
|
||||||
|
Err(e) => e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct SaplingParams;
|
|||||||
pub struct PubCertificate;
|
pub struct PubCertificate;
|
||||||
|
|
||||||
|
|
||||||
pub const ANCHOR_OFFSET: u32 = 2;
|
pub const ANCHOR_OFFSET: u32 = 0;
|
||||||
|
|
||||||
pub mod grpc_client {
|
pub mod grpc_client {
|
||||||
tonic::include_proto!("cash.z.wallet.sdk.rpc");
|
tonic::include_proto!("cash.z.wallet.sdk.rpc");
|
||||||
|
|||||||
@@ -426,8 +426,8 @@ impl LightClient {
|
|||||||
let version = inp.read_u64::<LittleEndian>().unwrap();
|
let version = inp.read_u64::<LittleEndian>().unwrap();
|
||||||
println!("Reading wallet version {}", version);
|
println!("Reading wallet version {}", version);
|
||||||
|
|
||||||
// After version 5, we're writing the rest of the file as a compressed stream (gzip)
|
// At version 5, we're writing the rest of the file as a compressed stream (gzip)
|
||||||
let mut reader: Box<dyn Read> = if version <= 4 {
|
let mut reader: Box<dyn Read> = if version != 5 {
|
||||||
Box::new(inp)
|
Box::new(inp)
|
||||||
} else {
|
} else {
|
||||||
Box::new(Decoder::new(inp).unwrap())
|
Box::new(Decoder::new(inp).unwrap())
|
||||||
@@ -901,12 +901,8 @@ impl LightClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_new_sietchaddress(&self, addr_type: &str) -> Result<JsonValue, String> {
|
pub fn do_new_sietchaddress(&self, addr_type: &str) -> Result<JsonValue, String> {
|
||||||
if !self.wallet.read().unwrap().is_unlocked_for_spending() {
|
|
||||||
error!("Wallet is locked");
|
let zdust_address = {
|
||||||
return Err("Wallet is locked".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_address = {
|
|
||||||
let wallet = self.wallet.write().unwrap();
|
let wallet = self.wallet.write().unwrap();
|
||||||
|
|
||||||
match addr_type {
|
match addr_type {
|
||||||
@@ -920,9 +916,7 @@ impl LightClient {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.do_save()?;
|
Ok(array![zdust_address])
|
||||||
|
|
||||||
Ok(array![new_address])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_state(&self) {
|
pub fn clear_state(&self) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use log::{info, warn, error};
|
|||||||
|
|
||||||
use protobuf::parse_from_bytes;
|
use protobuf::parse_from_bytes;
|
||||||
|
|
||||||
use libflate::{gzip::{Decoder, Encoder}, finish::AutoFinishUnchecked};
|
use libflate::gzip::{Decoder};
|
||||||
use secp256k1::SecretKey;
|
use secp256k1::SecretKey;
|
||||||
use bip39::{Mnemonic, Language};
|
use bip39::{Mnemonic, Language};
|
||||||
|
|
||||||
@@ -38,9 +38,13 @@ use zcash_primitives::{
|
|||||||
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey, ChildIndex},
|
zip32::{ExtendedFullViewingKey, ExtendedSpendingKey, ChildIndex},
|
||||||
JUBJUB,
|
JUBJUB,
|
||||||
primitives::{PaymentAddress},
|
primitives::{PaymentAddress},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use crate::lightclient::{LightClientConfig};
|
use crate::lightclient::{LightClientConfig};
|
||||||
|
|
||||||
mod data;
|
mod data;
|
||||||
@@ -112,6 +116,7 @@ pub struct LightWallet {
|
|||||||
extfvks: Arc<RwLock<Vec<ExtendedFullViewingKey>>>,
|
extfvks: Arc<RwLock<Vec<ExtendedFullViewingKey>>>,
|
||||||
|
|
||||||
pub zaddress: Arc<RwLock<Vec<PaymentAddress<Bls12>>>>,
|
pub zaddress: Arc<RwLock<Vec<PaymentAddress<Bls12>>>>,
|
||||||
|
|
||||||
|
|
||||||
// Transparent keys. If the wallet is locked, then the secret keys will be encrypted,
|
// Transparent keys. If the wallet is locked, then the secret keys will be encrypted,
|
||||||
// but the addresses will be present.
|
// but the addresses will be present.
|
||||||
@@ -135,7 +140,7 @@ pub struct LightWallet {
|
|||||||
|
|
||||||
impl LightWallet {
|
impl LightWallet {
|
||||||
pub fn serialized_version() -> u64 {
|
pub fn serialized_version() -> u64 {
|
||||||
return 5;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_taddr_from_bip39seed(config: &LightClientConfig, bip39_seed: &[u8], pos: u32) -> SecretKey {
|
fn get_taddr_from_bip39seed(config: &LightClientConfig, bip39_seed: &[u8], pos: u32) -> SecretKey {
|
||||||
@@ -170,6 +175,25 @@ impl LightWallet {
|
|||||||
(extsk, extfvk, address)
|
(extsk, extfvk, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_sietch_from_bip39seed( bip39_seed: &[u8]) ->
|
||||||
|
|
||||||
|
|
||||||
|
PaymentAddress<Bls12> {
|
||||||
|
assert_eq!(bip39_seed.len(), 64);
|
||||||
|
|
||||||
|
let zdustextsk: ExtendedSpendingKey = ExtendedSpendingKey::from_path(
|
||||||
|
&ExtendedSpendingKey::master(bip39_seed),
|
||||||
|
&[
|
||||||
|
ChildIndex::Hardened(32),
|
||||||
|
|
||||||
|
],
|
||||||
|
);
|
||||||
|
let zdustextfvk = ExtendedFullViewingKey::from(&zdustextsk);
|
||||||
|
let zdustaddress = zdustextfvk.default_address().unwrap().1;
|
||||||
|
|
||||||
|
(zdustaddress)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_shielded_address(addr: &String, config: &LightClientConfig) -> bool {
|
pub fn is_shielded_address(addr: &String, config: &LightClientConfig) -> bool {
|
||||||
match address::RecipientAddress::from_str(addr,
|
match address::RecipientAddress::from_str(addr,
|
||||||
config.hrp_sapling_address(),
|
config.hrp_sapling_address(),
|
||||||
@@ -243,8 +267,8 @@ impl LightWallet {
|
|||||||
println!("Reading wallet version {}", version);
|
println!("Reading wallet version {}", version);
|
||||||
info!("Reading wallet version {}", version);
|
info!("Reading wallet version {}", version);
|
||||||
|
|
||||||
// After version 5, we're writing the rest of the file as a compressed stream (gzip)
|
// At version 5, we're writing the rest of the file as a compressed stream (gzip)
|
||||||
let mut reader: Box<dyn Read> = if version <= 4 {
|
let mut reader: Box<dyn Read> = if version !=5 {
|
||||||
info!("Reading direct");
|
info!("Reading direct");
|
||||||
Box::new(inp)
|
Box::new(inp)
|
||||||
} else {
|
} else {
|
||||||
@@ -342,17 +366,14 @@ impl LightWallet {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write<W: Write>(&self, mut out: W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, mut writer: W) -> io::Result<()> {
|
||||||
if self.encrypted && self.unlocked {
|
if self.encrypted && self.unlocked {
|
||||||
return Err(Error::new(ErrorKind::InvalidInput,
|
return Err(Error::new(ErrorKind::InvalidInput,
|
||||||
format!("Cannot write while wallet is unlocked while encrypted.")));
|
format!("Cannot write while wallet is unlocked while encrypted.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the version
|
// Write the version
|
||||||
out.write_u64::<LittleEndian>(LightWallet::serialized_version())?;
|
writer.write_u64::<LittleEndian>(LightWallet::serialized_version())?;
|
||||||
|
|
||||||
// Gzip encoder
|
|
||||||
let mut writer = AutoFinishUnchecked::new(Encoder::new(out).unwrap());
|
|
||||||
|
|
||||||
// Write if it is locked
|
// Write if it is locked
|
||||||
writer.write_u8(if self.encrypted {1} else {0})?;
|
writer.write_u8(if self.encrypted {1} else {0})?;
|
||||||
@@ -472,38 +493,34 @@ impl LightWallet {
|
|||||||
|
|
||||||
zaddr
|
zaddr
|
||||||
}
|
}
|
||||||
// Add a new Sietch Addr. This will derive a new zdust address from the seed
|
|
||||||
pub fn add_zaddrdust(&self) -> String {
|
|
||||||
if !self.unlocked {
|
|
||||||
return "".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let pos = self.extsks.read().unwrap().len() as u32;
|
// Add a new Sietch Addr. This will derive a new zdust address from manipluated seed
|
||||||
|
pub fn add_zaddrdust(&self) -> String {
|
||||||
|
|
||||||
|
let mut seed_bytes = [0u8; 32];
|
||||||
|
|
||||||
|
|
||||||
// Use random generator to create a new Sietch seed every time when call.
|
// Use random generator to create a new Sietch seed
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let letter: String = rng.gen_range(b'A', b'Z').to_string();
|
let letter: String = rng.gen_range(b'A', b'Z').to_string();
|
||||||
let number: String = rng.gen_range(0, 999999).to_string();
|
let number: String = rng.gen_range(0, 999999).to_string();
|
||||||
// let combi: String = letter.to_string() + number.to_string();
|
|
||||||
let s = format!("{}{:06}", letter, number);
|
let s = format!("{}{:06}", letter, number);
|
||||||
//println!("{}", s);
|
let my_string = String::from(s);
|
||||||
|
let dust: &str = &my_string;
|
||||||
let my_string = String::from(s);
|
|
||||||
// let my_immutable_string = &my_string; //This is a &String type
|
|
||||||
let dust: &str = &my_string; //This is an &str type
|
|
||||||
|
|
||||||
|
|
||||||
|
let mut system_rng = OsRng;
|
||||||
|
system_rng.fill(&mut seed_bytes);
|
||||||
|
|
||||||
|
let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&seed_bytes, Language::English).unwrap(), dust);
|
||||||
|
|
||||||
let bip39_seed = bip39::Seed::new(&Mnemonic::from_entropy(&self.seed, Language::English).unwrap(), dust);
|
let zdustaddress = LightWallet::get_sietch_from_bip39seed(&bip39_seed.as_bytes());
|
||||||
|
|
||||||
let (_extsk, _extfvk, address) =
|
let zdust = encode_payment_address("zs", &zdustaddress);
|
||||||
LightWallet::get_zaddr_from_bip39seed(&self.config, &bip39_seed.as_bytes(), pos);
|
|
||||||
|
|
||||||
let zaddr = encode_payment_address(self.config.hrp_sapling_address(), &address);
|
|
||||||
|
|
||||||
|
|
||||||
zaddr
|
zdust
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a new t address to the wallet. This will derive a new address from the seed
|
/// Add a new t address to the wallet. This will derive a new address from the seed
|
||||||
@@ -606,7 +623,7 @@ impl LightWallet {
|
|||||||
)
|
)
|
||||||
} {
|
} {
|
||||||
(Some(min_height), Some(max_height)) => {
|
(Some(min_height), Some(max_height)) => {
|
||||||
let target_height = max_height + 1;
|
let target_height = max_height;
|
||||||
|
|
||||||
// Select an anchor ANCHOR_OFFSET back from the target block,
|
// Select an anchor ANCHOR_OFFSET back from the target block,
|
||||||
// unless that would be before the earliest block we have.
|
// unless that would be before the earliest block we have.
|
||||||
|
|||||||
Reference in New Issue
Block a user