mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-07-29 19:31:25 +00:00
Mark pending utxos
This commit is contained in:
@@ -208,10 +208,33 @@ impl LightClient {
|
||||
})
|
||||
.collect::<Vec<JsonValue>>();
|
||||
|
||||
// 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::<Vec<JsonValue>>();;
|
||||
|
||||
let mut res = object!{
|
||||
"unspent_notes" => unspent_notes,
|
||||
"pending_notes" => pending_notes,
|
||||
"utxos" => utxos,
|
||||
"pending_utxos" => pending_utxos,
|
||||
};
|
||||
|
||||
if all_notes {
|
||||
|
@@ -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() },
|
||||
|
Reference in New Issue
Block a user