diff --git a/rust-lightclient/src/lightclient.rs b/rust-lightclient/src/lightclient.rs index d90eeef..2a671f3 100644 --- a/rust-lightclient/src/lightclient.rs +++ b/rust-lightclient/src/lightclient.rs @@ -208,10 +208,33 @@ impl LightClient { }) .collect::>(); + // Collect pending UTXOs + let pending_utxos = self.wallet.txs.read().unwrap().iter() + .flat_map( |(txid, wtx)| { + wtx.utxos.iter().filter_map(move |utxo| + if utxo.unconfirmed_spent.is_some() { + Some(object!{ + "created_in_block" => wtx.block, + "created_in_txid" => format!("{}", txid), + "value" => utxo.value, + "scriptkey" => hex::encode(utxo.script.clone()), + "is_change" => false, // TODO: Identify notes as change + "address" => utxo.address.clone(), + "spent" => utxo.spent.map(|spent_txid| format!("{}", spent_txid)), + "unconfirmed_spent" => utxo.unconfirmed_spent.map(|spent_txid| format!("{}", spent_txid)), + }) + } else { + None + } + ) + }) + .collect::>();; + let mut res = object!{ "unspent_notes" => unspent_notes, "pending_notes" => pending_notes, "utxos" => utxos, + "pending_utxos" => pending_utxos, }; if all_notes { diff --git a/rust-lightclient/src/lightwallet.rs b/rust-lightclient/src/lightwallet.rs index 68c5e05..2aab8bc 100644 --- a/rust-lightclient/src/lightwallet.rs +++ b/rust-lightclient/src/lightwallet.rs @@ -913,6 +913,7 @@ impl LightWallet { match spent_utxo { Some(su) => { su.spent = Some(txid.clone()); + su.unconfirmed_spent = None; su.value // Return the value of the note }, None => 0 @@ -1212,6 +1213,13 @@ impl LightWallet { .map(|utxo| { let outpoint: OutPoint = utxo.to_outpoint(); + // Mark this utxo as uncofirmed spent + let mut txs = self.txs.write().unwrap(); + let mut spent_utxo = txs.get_mut(&utxo.txid).unwrap().utxos.iter_mut() + .find(|u| utxo.txid == u.txid && utxo.output_index == u.output_index) + .unwrap(); + spent_utxo.unconfirmed_spent = Some(utxo.txid); + let coin = TxOut { value: Amount::from_u64(utxo.value).unwrap(), script_pubkey: Script { 0: utxo.script.clone() },