Add historical utxos in notes all cmd

This commit is contained in:
Aditya Kulkarni 2019-09-13 18:43:26 -07:00
parent cb44b4a2a6
commit bee501bae0
2 changed files with 22 additions and 1 deletions

View File

@ -11,7 +11,6 @@ pub trait Command {
} }
struct SyncCommand {} struct SyncCommand {}
impl Command for SyncCommand { impl Command for SyncCommand {
fn help(&self) { fn help(&self) {
println!("Type sync for syncing"); println!("Type sync for syncing");

View File

@ -218,6 +218,28 @@ impl LightClient {
res["spent_notes"] = JsonValue::Array(spent_notes); res["spent_notes"] = JsonValue::Array(spent_notes);
} }
// If all notes, also add historical utxos
if all_notes {
res["spent_utxos"] = JsonValue::Array(self.wallet.txs.read().unwrap().values()
.flat_map(|wtx| {
wtx.utxos.iter()
.filter(|utxo| utxo.spent.is_some())
.map(|utxo| {
object!{
"created_in_block" => wtx.block,
"created_in_txid" => format!("{}", utxo.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)),
}
}).collect::<Vec<JsonValue>>()
}).collect::<Vec<JsonValue>>()
);
}
res res
} }