Compare commits

...

9 Commits

Author SHA1 Message Date
Jonathan "Duke" Leto 04eb253704 lightwallet tbalance 2 years ago
Jonathan "Duke" Leto 741d37002c lightwallet get_utxos 2 years ago
Jonathan "Duke" Leto 1eedfb6a0f lightwallet zbalance 2 years ago
Jonathan "Duke" Leto cb0df74dde Add mempool stuff to CompactTxStreamer 2 years ago
Jonathan "Duke" Leto e5f486bfd8 mempool changes to lib/src/lightwallet/walletzkey.rs 2 years ago
Jonathan "Duke" Leto 0f99b8de5d mempool changes to cli/src/lib.rs 2 years ago
Jonathan "Duke" Leto ef2bf42fbe create new wallets with height - 100 2 years ago
Jonathan "Duke" Leto 3bb8708278 do not hardcode version number 2 years ago
Jonathan "Duke" Leto adacbdb564 bump version to 1.1.2 2 years ago
  1. 37
      cli/src/lib.rs
  2. 2
      cli/src/version.rs
  3. 16
      lib/proto/service.proto
  4. 70
      lib/src/lightwallet.rs
  5. 3
      lib/src/lightwallet/walletzkey.rs

37
cli/src/lib.rs

@ -8,10 +8,12 @@ use silentdragonlitelib::{commands,
lightclient::{LightClient, LightClientConfig},
};
pub mod version;
#[macro_export]
macro_rules! configure_clapapp {
( $freshapp: expr ) => {
$freshapp.version("1.1.1")
$freshapp.version(VERSION)
.arg(Arg::with_name("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.")
@ -91,7 +93,9 @@ pub fn startup(server: http::Uri, dangerous: bool, seed: Option<String>, birthda
Arc::new(LightClient::read_from_disk(&config)?)
} else {
println!("Creating a new wallet");
Arc::new(LightClient::new(&config, latest_block_height)?)
// Create a wallet with height - 100, to protect against reorgs
Arc::new(LightClient::new(&config, latest_block_height.saturating_sub(100))?)
}
}
};
@ -208,27 +212,21 @@ pub fn command_loop(lightclient: Arc<LightClient>) -> (Sender<(String, Vec<Strin
let lc = lightclient.clone();
std::thread::spawn(move || {
LightClient::start_mempool_monitor(lc.clone());
loop {
match command_rx.recv_timeout(std::time::Duration::from_secs(5 * 60)) {
Ok((cmd, args)) => {
let args = args.iter().map(|s| s.as_ref()).collect();
if let Ok((cmd, args)) = command_rx.recv() {
let args = args.iter().map(|s| s.as_ref()).collect();
let cmd_response = commands::do_user_command(&cmd, &args, lc.as_ref());
resp_tx.send(cmd_response).unwrap();
let cmd_response = commands::do_user_command(&cmd, &args, lc.as_ref());
resp_tx.send(cmd_response).unwrap();
if cmd == "quit" {
info!("Quit");
break;
}
},
Err(_) => {
// Timeout. Do a sync to keep the wallet up-to-date. False to whether to print updates on the console
info!("Timeout, doing a sync");
match lc.do_sync(false) {
Ok(_) => {},
Err(e) => {error!("{}", e)}
}
if cmd == "quit" {
info!("Quit");
break;
}
} else {
break;
}
}
});
@ -244,6 +242,7 @@ pub fn attempt_recover_seed(password: Option<String>) {
sapling_activation_height: 0,
consensus_branch_id: "000000".to_string(),
anchor_offset: 0,
monitor_mempool: false,
no_cert_verification: false,
data_dir: None,
};

2
cli/src/version.rs

@ -1 +1 @@
pub const VERSION:&str = "1.1.1";
pub const VERSION:&str = "1.1.2";

16
lib/proto/service.proto

@ -77,8 +77,11 @@ message TransparentAddressBlockFilter {
service CompactTxStreamer {
// Compact Blocks
// Return the height of the tip of the best chain
rpc GetLatestBlock(ChainSpec) returns (BlockID) {}
// Return the compact block corresponding to the given block identifier
rpc GetBlock(BlockID) returns (CompactBlock) {}
// Return a list of consecutive compact blocks
rpc GetBlockRange(BlockRange) returns (stream CompactBlock) {}
// Transactions
@ -88,6 +91,19 @@ service CompactTxStreamer {
// t-Address support
rpc GetAddressTxids(TransparentAddressBlockFilter) returns (stream RawTransaction) {}
// Return the compact transactions currently in the mempool; the results
// can be a few seconds out of date. If the Exclude list is empty, return
// all transactions; otherwise return all *except* those in the Exclude list
// (if any); this allows the client to avoid receiving transactions that it
// already has (from an earlier call to this rpc). The transaction IDs in the
// Exclude list can be shortened to any number of bytes to make the request
// more bandwidth-efficient; if two or more transactions in the mempool
// match a shortened txid, they are all sent (none is excluded). Transactions
// in the exclude list that don't exist in the mempool are ignored.
rpc GetMempoolTx(Exclude) returns (stream CompactTx) {}
rpc GetMempoolStream(Empty) returns (stream RawTransaction) {}
// Misc
rpc GetLightdInfo(Empty) returns (LightdInfo) {}
rpc GetCoinsupply(Empty) returns (Coinsupply) {}

70
lib/src/lightwallet.rs

@ -1047,50 +1047,58 @@ impl LightWallet {
return self.unlocked;
}
pub fn zbalance(&self, addr: Option<String>) -> u64 {
self.txs.read().unwrap()
pub async fn zbalance(&self, addr: Option<String>) -> u64 {
self.txns
.read()
.await
.current
.values()
.map (|tx| {
tx.notes.iter()
.filter(|nd| { // TODO, this whole section is shared with verified_balance. Refactor it.
match addr.clone() {
Some(a) => a == encode_payment_address(
self.config.hrp_sapling_address(),
&nd.extfvk.fvk.vk
.into_payment_address(nd.diversifier, &JUBJUB).unwrap()
),
None => true
.map(|tx| {
tx.notes
.iter()
.filter(|nd| match addr.as_ref() {
Some(a) => {
*a == encode_payment_address(
self.config.hrp_sapling_address(),
&nd.extfvk.fvk.vk.to_payment_address(nd.diversifier).unwrap(),
)
}
None => true,
})
.map(|nd| {
if nd.spent.is_none() && nd.unconfirmed_spent.is_none() {
nd.note.value
} else {
0
}
})
.map(|nd| if nd.spent.is_none() { nd.note.value } else { 0 })
.sum::<u64>()
})
.sum::<u64>() as u64
.sum::<u64>()
}
// Get all (unspent) utxos. Unconfirmed spent utxos are included
pub fn get_utxos(&self) -> Vec<Utxo> {
let txs = self.txs.read().unwrap();
txs.values()
.flat_map(|tx| {
tx.utxos.iter().filter(|utxo| utxo.spent.is_none())
})
pub async fn get_utxos(&self) -> Vec<Utxo> {
self.txns
.read()
.await
.current
.values()
.flat_map(|tx| tx.utxos.iter().filter(|utxo| utxo.spent.is_none()))
.map(|utxo| utxo.clone())
.collect::<Vec<Utxo>>()
}
pub fn tbalance(&self, addr: Option<String>) -> u64 {
self.get_utxos().iter()
.filter(|utxo| {
match addr.clone() {
Some(a) => utxo.address == a,
None => true,
}
pub async fn tbalance(&self, addr: Option<String>) -> u64 {
self.get_utxos()
.await
.iter()
.filter(|utxo| match addr.as_ref() {
Some(a) => utxo.address == *a,
None => true,
})
.map(|utxo| utxo.value )
.sum::<u64>() as u64
.map(|utxo| utxo.value)
.sum::<u64>()
}
pub fn verified_zbalance(&self, addr: Option<String>) -> u64 {

3
lib/src/lightwallet/walletzkey.rs

@ -451,6 +451,7 @@ pub mod tests {
LightClientConfig {
server: "0.0.0.0:0".parse().unwrap(),
chain_name: "main".to_string(),
monitor_mempool: false,
sapling_activation_height: 0,
consensus_branch_id: "000000".to_string(),
anchor_offset: 0,
@ -582,4 +583,4 @@ pub mod tests {
}
}
}

Loading…
Cancel
Save