Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a178c8d08 | |||
| b780587d26 | |||
| ae059a7238 |
@@ -132,8 +132,16 @@ impl Command for ClearCommand {
|
||||
"Clear the wallet state, rolling back the wallet to an empty state.".to_string()
|
||||
}
|
||||
|
||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
||||
lightclient.clear_state();
|
||||
fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
|
||||
if !args.is_empty() {
|
||||
if let Ok(height) = args[0].parse::<u64>() {
|
||||
lightclient.clear_state_from(height);
|
||||
} else {
|
||||
return format!("Error: invalid height '{}'", args[0]);
|
||||
}
|
||||
} else {
|
||||
lightclient.clear_state();
|
||||
}
|
||||
|
||||
let result = object!{ "result" => "success" };
|
||||
|
||||
|
||||
@@ -1274,12 +1274,16 @@ pub fn start_mempool_monitor(lc: Arc<LightClient>) -> Result<(), String> {
|
||||
}
|
||||
|
||||
pub fn clear_state(&self) {
|
||||
self.clear_state_from(self.wallet.read().unwrap().get_birthday());
|
||||
}
|
||||
|
||||
pub fn clear_state_from(&self, height: u64) {
|
||||
// First, clear the state from the wallet
|
||||
self.wallet.read().unwrap().clear_blocks();
|
||||
|
||||
// Then set the initial block
|
||||
self.set_wallet_initial_state(self.wallet.read().unwrap().get_birthday());
|
||||
info!("Cleared wallet state");
|
||||
self.set_wallet_initial_state(height);
|
||||
info!("Cleared wallet state to height {}", height);
|
||||
}
|
||||
|
||||
pub fn do_rescan(&self) -> Result<JsonValue, String> {
|
||||
|
||||
@@ -1452,11 +1452,12 @@ pub fn scan_full_tx(&self, tx: &Transaction, height: i32, datetime: u64) {
|
||||
// Also scan the output to see if it can be decoded with our OutgoingViewKey
|
||||
// If it can, then we sent this transaction, so we should be able to get
|
||||
// the memo and value for our records
|
||||
// First, collect all our z addresses, to check for change
|
||||
// Collect z addresses
|
||||
let z_addresses = self.zkeys.read().unwrap().iter().map( |zk| {
|
||||
encode_payment_address(self.config.hrp_sapling_address(), &zk.zaddress)
|
||||
}).collect::<HashSet<String>>();
|
||||
|
||||
// Collect IVKs to detect change outputs to diversified addresses
|
||||
let ivks_for_change: Vec<_> = self.zkeys.read().unwrap().iter()
|
||||
.map(|zk| zk.extfvk.fvk.vk.ivk())
|
||||
.collect();
|
||||
|
||||
// Search all ovks that we have
|
||||
let ovks: Vec<_> = self.zkeys.read().unwrap().iter()
|
||||
.map(|zk| zk.extfvk.fvk.ovk.clone())
|
||||
@@ -1472,14 +1473,26 @@ pub fn scan_full_tx(&self, tx: &Transaction, height: i32, datetime: u64) {
|
||||
Some((note, payment_address, memo)) => {
|
||||
let address = encode_payment_address(self.config.hrp_sapling_address(),
|
||||
&payment_address);
|
||||
// Check if this is change, and if it also doesn't have a memo, don't add
|
||||
// to the outgoing metadata.
|
||||
// If this is change (i.e., funds sent to ourself) AND has a memo, then
|
||||
// presumably the users is writing a memo to themself, so we will add it to
|
||||
// the outgoing metadata, even though it might be confusing in the UI, but hopefully
|
||||
// the user can make sense of it.
|
||||
if z_addresses.contains(&address) && memo.to_utf8().is_none() {
|
||||
continue;
|
||||
|
||||
// Check if this output belongs to our wallet using IVK decryption.
|
||||
// This correctly detects change sent to diversified addresses,
|
||||
// not just the wallet's default z-address.
|
||||
let epk_prime = output.ephemeral_key.as_prime_order(&JUBJUB).unwrap();
|
||||
let is_to_self = ivks_for_change.iter().any(|ivk| {
|
||||
try_sapling_note_decryption(ivk, &epk_prime, &output.cmu, &output.enc_ciphertext).is_some()
|
||||
});
|
||||
|
||||
// If this is change (funds to ourself) without a meaningful memo, skip it.
|
||||
// memo.to_utf8() returns Some(Ok("")) for empty memos (all-zero bytes),
|
||||
// so we must also check for empty strings, not just None.
|
||||
if is_to_self {
|
||||
let has_memo = match memo.to_utf8() {
|
||||
Some(Ok(ref s)) if !s.is_empty() => true,
|
||||
_ => false,
|
||||
};
|
||||
if !has_memo {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Update the WalletTx
|
||||
// Do it in a short scope because of the write lock.
|
||||
|
||||
Reference in New Issue
Block a user