split notes into spent and unspent

This commit is contained in:
Aditya Kulkarni
2019-09-10 14:33:12 -07:00
parent 8cfa4401c0
commit c205f138f8

View File

@@ -138,7 +138,10 @@ impl LightClient {
// Return a list of all notes, spent and unspent // Return a list of all notes, spent and unspent
pub fn do_list_notes(&self) -> JsonValue { pub fn do_list_notes(&self) -> JsonValue {
JsonValue::Array( let mut unspent_notes: Vec<JsonValue> = vec![];
let mut spent_notes : Vec<JsonValue> = vec![];
let mut pending_notes: Vec<JsonValue> = vec![];
self.wallet.txs.read().unwrap().iter() self.wallet.txs.read().unwrap().iter()
.flat_map( |(txid, wtx)| { .flat_map( |(txid, wtx)| {
wtx.notes.iter().map(move |nd| wtx.notes.iter().map(move |nd|
@@ -153,8 +156,21 @@ impl LightClient {
} }
) )
}) })
.collect::<Vec<JsonValue>>() .for_each( |note| {
) if note["spent"].is_null() && note["unconfirmed_spent"].is_null() {
unspent_notes.push(note);
} else if !note["spent"].is_null() {
spent_notes.push(note);
} else {
pending_notes.push(note);
}
});
object!{
"spent_notes" => spent_notes,
"unspent_notes" => unspent_notes,
"pending_notes" => pending_notes
}
} }
pub fn do_list_transactions(&self) -> JsonValue { pub fn do_list_transactions(&self) -> JsonValue {