mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-07-30 03:41:28 +00:00
Scan vin without relying on pubkey
This commit is contained in:
@@ -896,57 +896,30 @@ impl LightWallet {
|
|||||||
let mut total_transparent_spend: u64 = 0;
|
let mut total_transparent_spend: u64 = 0;
|
||||||
|
|
||||||
for vin in tx.vin.iter() {
|
for vin in tx.vin.iter() {
|
||||||
match vin.script_sig.public_key() {
|
// Find the txid in the list of utxos that we have.
|
||||||
Some(pk) => {
|
let txid = TxId {0: vin.prevout.hash};
|
||||||
//println!("One of our transparent inputs was spent. {}, {}", hex::encode(pk.to_vec()), hex::encode(pubkey.to_vec()));
|
match self.txs.write().unwrap().get_mut(&txid) {
|
||||||
if pk[..] == pubkey[..] {
|
Some(wtx) => {
|
||||||
// Find the txid in the list of utxos that we have.
|
//println!("Looking for {}, {}", txid, vin.prevout.n);
|
||||||
let txid = TxId {0: vin.prevout.hash};
|
|
||||||
|
|
||||||
// println!("Looking for {}, {}", txid, vin.prevout.n);
|
// One of the tx outputs is a match
|
||||||
|
let spent_utxo = wtx.utxos.iter_mut()
|
||||||
|
.find(|u| u.txid == txid && u.output_index == (vin.prevout.n as u64));
|
||||||
|
|
||||||
let value = match self.txs.write().unwrap().get_mut(&txid) {
|
match spent_utxo {
|
||||||
Some(wtx) => {
|
Some(su) => {
|
||||||
// One of the tx outputs is a match
|
su.spent = Some(txid.clone());
|
||||||
let spent_utxo = wtx.utxos.iter_mut()
|
su.unconfirmed_spent = None;
|
||||||
.find(|u| u.txid == txid && u.output_index == (vin.prevout.n as u64));
|
|
||||||
|
|
||||||
match spent_utxo {
|
total_transparent_spend += su.value;
|
||||||
Some(su) => {
|
},
|
||||||
su.spent = Some(txid.clone());
|
_ => {}
|
||||||
su.unconfirmed_spent = None;
|
|
||||||
su.value // Return the value of the note
|
|
||||||
},
|
|
||||||
None => 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if value == 0 {
|
|
||||||
println!("One of the inputs was a transparent address we have, but the UTXO wasn't found");
|
|
||||||
}
|
|
||||||
|
|
||||||
total_transparent_spend += value;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan for t outputs
|
|
||||||
for (n, vout) in tx.vout.iter().enumerate() {
|
|
||||||
match vout.script_pubkey.address() {
|
|
||||||
Some(TransparentAddress::PublicKey(hash)) => {
|
|
||||||
if hash[..] == ripemd160::Ripemd160::digest(&Sha256::digest(&pubkey))[..] {
|
|
||||||
// This is out address. Add this as an output to the txid
|
|
||||||
self.add_toutput_to_wtx(height, &tx.txid(), &vout, n as u64);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if total_transparent_spend > 0 {
|
if total_transparent_spend > 0 {
|
||||||
// Update the WalletTx. Do it in a short scope because of the write lock.
|
// Update the WalletTx. Do it in a short scope because of the write lock.
|
||||||
let mut txs = self.txs.write().unwrap();
|
let mut txs = self.txs.write().unwrap();
|
||||||
@@ -960,6 +933,19 @@ impl LightWallet {
|
|||||||
.total_transparent_value_spent = total_transparent_spend;
|
.total_transparent_value_spent = total_transparent_spend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan for t outputs
|
||||||
|
for (n, vout) in tx.vout.iter().enumerate() {
|
||||||
|
match vout.script_pubkey.address() {
|
||||||
|
Some(TransparentAddress::PublicKey(hash)) => {
|
||||||
|
if hash[..] == ripemd160::Ripemd160::digest(&Sha256::digest(&pubkey))[..] {
|
||||||
|
// This is out address. Add this as an output to the txid
|
||||||
|
self.add_toutput_to_wtx(height, &tx.txid(), &vout, n as u64);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Scan shielded sapling outputs to see if anyone of them is us, and if it is, extract the memo
|
// Scan shielded sapling outputs to see if anyone of them is us, and if it is, extract the memo
|
||||||
for output in tx.shielded_outputs.iter() {
|
for output in tx.shielded_outputs.iter() {
|
||||||
let ivks: Vec<_> = self.extfvks.iter().map(|extfvk| extfvk.fvk.vk.ivk()).collect();
|
let ivks: Vec<_> = self.extfvks.iter().map(|extfvk| extfvk.fvk.vk.ivk()).collect();
|
||||||
|
Reference in New Issue
Block a user