mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-07-31 20:31:24 +00:00
Store exspk with the SpendableNote
This commit is contained in:
@@ -597,11 +597,11 @@ impl LightWallet {
|
|||||||
None => {
|
None => {
|
||||||
let address = self.address_from_pubkeyhash(vout.script_pubkey.address());
|
let address = self.address_from_pubkeyhash(vout.script_pubkey.address());
|
||||||
if address.is_none() {
|
if address.is_none() {
|
||||||
println!("Couldn't determine address for output!");
|
error!("Couldn't determine address for output!");
|
||||||
}
|
} else {
|
||||||
info!("Added to wallet {}:{}", txid, n);
|
info!("Added to wallet {}:{}", txid, n);
|
||||||
// Add the utxo
|
// Add the utxo
|
||||||
tx_entry.utxos.push(Utxo{
|
tx_entry.utxos.push(Utxo {
|
||||||
address: address.unwrap(),
|
address: address.unwrap(),
|
||||||
txid: txid.clone(),
|
txid: txid.clone(),
|
||||||
output_index: n,
|
output_index: n,
|
||||||
@@ -614,6 +614,7 @@ impl LightWallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Scan the full Tx and update memos for incoming shielded transactions
|
// Scan the full Tx and update memos for incoming shielded transactions
|
||||||
pub fn scan_full_tx(&self, tx: &Transaction, height: i32) {
|
pub fn scan_full_tx(&self, tx: &Transaction, height: i32) {
|
||||||
@@ -622,10 +623,6 @@ impl LightWallet {
|
|||||||
// TODO: Save this object
|
// TODO: Save this object
|
||||||
let secp = secp256k1::Secp256k1::new();
|
let secp = secp256k1::Secp256k1::new();
|
||||||
|
|
||||||
// TODO: Iterate over all transparent addresses. This is currently looking only at
|
|
||||||
// the first one.
|
|
||||||
let pubkey = secp256k1::PublicKey::from_secret_key(&secp, &self.tkeys.read().unwrap()[0]).serialize();
|
|
||||||
|
|
||||||
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() {
|
||||||
@@ -667,6 +664,9 @@ impl LightWallet {
|
|||||||
.total_transparent_value_spent = total_transparent_spend;
|
.total_transparent_value_spent = total_transparent_spend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Iterate over all transparent addresses. This is currently looking only at
|
||||||
|
// the first one.
|
||||||
|
let pubkey = secp256k1::PublicKey::from_secret_key(&secp, &self.tkeys.read().unwrap()[0]).serialize();
|
||||||
// Scan for t outputs
|
// Scan for t outputs
|
||||||
for (n, vout) in tx.vout.iter().enumerate() {
|
for (n, vout) in tx.vout.iter().enumerate() {
|
||||||
match vout.script_pubkey.address() {
|
match vout.script_pubkey.address() {
|
||||||
@@ -782,9 +782,9 @@ impl LightWallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the WalletTx
|
// Update the WalletTx
|
||||||
info!("A sapling output was sent in {}", tx.txid());
|
|
||||||
{
|
|
||||||
// Do it in a short scope because of the write lock.
|
// Do it in a short scope because of the write lock.
|
||||||
|
{
|
||||||
|
info!("A sapling output was sent in {}", tx.txid());
|
||||||
|
|
||||||
let mut txs = self.txs.write().unwrap();
|
let mut txs = self.txs.write().unwrap();
|
||||||
if txs.get(&tx.txid()).unwrap().outgoing_metadata.iter()
|
if txs.get(&tx.txid()).unwrap().outgoing_metadata.iter()
|
||||||
@@ -1059,11 +1059,6 @@ impl LightWallet {
|
|||||||
to
|
to
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: This only spends from the first address right now.
|
|
||||||
let extsk = &self.extsks.read().unwrap()[0];
|
|
||||||
let extfvk = &self.extfvks.read().unwrap()[0];
|
|
||||||
let ovk = extfvk.fvk.ovk;
|
|
||||||
|
|
||||||
let to = match address::RecipientAddress::from_str(to,
|
let to = match address::RecipientAddress::from_str(to,
|
||||||
self.config.hrp_sapling_address(),
|
self.config.hrp_sapling_address(),
|
||||||
self.config.base58_pubkey_address(),
|
self.config.base58_pubkey_address(),
|
||||||
@@ -1091,7 +1086,9 @@ impl LightWallet {
|
|||||||
let notes: Vec<_> = self.txs.read().unwrap().iter()
|
let notes: Vec<_> = self.txs.read().unwrap().iter()
|
||||||
.map(|(txid, tx)| tx.notes.iter().map(move |note| (*txid, note)))
|
.map(|(txid, tx)| tx.notes.iter().map(move |note| (*txid, note)))
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter_map(|(txid, note)| SpendableNote::from(txid, note, anchor_offset))
|
.filter_map(|(txid, note)|
|
||||||
|
SpendableNote::from(txid, note, anchor_offset, &self.extsks.read().unwrap()[note.account])
|
||||||
|
)
|
||||||
.scan(0, |running_total, spendable| {
|
.scan(0, |running_total, spendable| {
|
||||||
let value = spendable.note.value;
|
let value = spendable.note.value;
|
||||||
let ret = if *running_total < u64::from(target_value) {
|
let ret = if *running_total < u64::from(target_value) {
|
||||||
@@ -1160,7 +1157,7 @@ impl LightWallet {
|
|||||||
|
|
||||||
for selected in notes.iter() {
|
for selected in notes.iter() {
|
||||||
if let Err(e) = builder.add_sapling_spend(
|
if let Err(e) = builder.add_sapling_spend(
|
||||||
extsk.clone(),
|
selected.extsk.clone(),
|
||||||
selected.diversifier,
|
selected.diversifier,
|
||||||
selected.note.clone(),
|
selected.note.clone(),
|
||||||
selected.witness.clone(),
|
selected.witness.clone(),
|
||||||
@@ -1183,6 +1180,10 @@ impl LightWallet {
|
|||||||
let encoded_memo = memo.map(|s| Memo::from_str(&s).unwrap() );
|
let encoded_memo = memo.map(|s| Memo::from_str(&s).unwrap() );
|
||||||
|
|
||||||
println!("{}: Adding output", now() - start_time);
|
println!("{}: Adding output", now() - start_time);
|
||||||
|
|
||||||
|
// TODO: We're using the first ovk to encrypt outgoing Txns. Is that Ok?
|
||||||
|
let ovk = self.extfvks.read().unwrap()[0].fvk.ovk;
|
||||||
|
|
||||||
if let Err(e) = match to {
|
if let Err(e) = match to {
|
||||||
address::RecipientAddress::Shielded(to) => {
|
address::RecipientAddress::Shielded(to) => {
|
||||||
builder.add_sapling_output(ovk, to.clone(), value, encoded_memo)
|
builder.add_sapling_output(ovk, to.clone(), value, encoded_memo)
|
||||||
|
@@ -22,6 +22,7 @@ use zcash_primitives::{
|
|||||||
fs::{Fs, FsRepr},
|
fs::{Fs, FsRepr},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
use zcash_primitives::zip32::ExtendedSpendingKey;
|
||||||
|
|
||||||
|
|
||||||
pub struct BlockData {
|
pub struct BlockData {
|
||||||
@@ -468,10 +469,11 @@ pub struct SpendableNote {
|
|||||||
pub diversifier: Diversifier,
|
pub diversifier: Diversifier,
|
||||||
pub note: Note<Bls12>,
|
pub note: Note<Bls12>,
|
||||||
pub witness: IncrementalWitness<Node>,
|
pub witness: IncrementalWitness<Node>,
|
||||||
|
pub extsk: ExtendedSpendingKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpendableNote {
|
impl SpendableNote {
|
||||||
pub fn from(txid: TxId, nd: &SaplingNoteData, anchor_offset: usize) -> Option<Self> {
|
pub fn from(txid: TxId, nd: &SaplingNoteData, anchor_offset: usize, extsk: &ExtendedSpendingKey) -> Option<Self> {
|
||||||
// Include only notes that haven't been spent, or haven't been included in an unconfirmed spend yet.
|
// Include only notes that haven't been spent, or haven't been included in an unconfirmed spend yet.
|
||||||
if nd.spent.is_none() && nd.unconfirmed_spent.is_none() {
|
if nd.spent.is_none() && nd.unconfirmed_spent.is_none() {
|
||||||
let witness = nd.witnesses.get(nd.witnesses.len() - anchor_offset - 1);
|
let witness = nd.witnesses.get(nd.witnesses.len() - anchor_offset - 1);
|
||||||
@@ -482,6 +484,7 @@ impl SpendableNote {
|
|||||||
diversifier: nd.diversifier,
|
diversifier: nd.diversifier,
|
||||||
note: nd.note.clone(),
|
note: nd.note.clone(),
|
||||||
witness: w.clone(),
|
witness: w.clone(),
|
||||||
|
extsk: extsk.clone(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
Reference in New Issue
Block a user