mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-02-01 03:12:15 +00:00
parent
2dce6b46ca
commit
f0e13e3caf
@ -633,8 +633,9 @@ impl Command for TransactionsCommand {
|
|||||||
let mut h = vec![];
|
let mut h = vec![];
|
||||||
h.push("List all incoming and outgoing transactions from this wallet");
|
h.push("List all incoming and outgoing transactions from this wallet");
|
||||||
h.push("Usage:");
|
h.push("Usage:");
|
||||||
h.push("list");
|
h.push("list [allmemos]");
|
||||||
h.push("");
|
h.push("");
|
||||||
|
h.push("If you include the 'allmemos' argument, all memos are returned in their raw hex format");
|
||||||
|
|
||||||
h.join("\n")
|
h.join("\n")
|
||||||
}
|
}
|
||||||
@ -643,8 +644,22 @@ impl Command for TransactionsCommand {
|
|||||||
"List all transactions in the wallet".to_string()
|
"List all transactions in the wallet".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
|
fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
|
||||||
format!("{}", lightclient.do_list_transactions().pretty(2))
|
if args.len() > 1 {
|
||||||
|
return format!("Didn't understand arguments\n{}", self.help());
|
||||||
|
}
|
||||||
|
|
||||||
|
let include_memo_hex = if args.len() == 1 {
|
||||||
|
if args[0] == "allmemos" || args[0] == "true" || args[0] == "yes" {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
return format!("Couldn't understand first argument '{}'\n{}", args[0], self.help());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
format!("{}", lightclient.do_list_transactions(include_memo_hex).pretty(2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -862,7 +862,7 @@ impl LightClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn do_list_transactions(&self) -> JsonValue {
|
pub fn do_list_transactions(&self, include_memo_hex: bool) -> JsonValue {
|
||||||
let wallet = self.wallet.read().unwrap();
|
let wallet = self.wallet.read().unwrap();
|
||||||
|
|
||||||
// Create a list of TransactionItems from wallet txns
|
// Create a list of TransactionItems from wallet txns
|
||||||
@ -882,11 +882,18 @@ impl LightClient {
|
|||||||
|
|
||||||
// Collect outgoing metadata
|
// Collect outgoing metadata
|
||||||
let outgoing_json = v.outgoing_metadata.iter()
|
let outgoing_json = v.outgoing_metadata.iter()
|
||||||
.map(|om|
|
.map(|om| {
|
||||||
object!{
|
let mut o = object!{
|
||||||
"address" => om.address.clone(),
|
"address" => om.address.clone(),
|
||||||
"value" => om.value,
|
"value" => om.value,
|
||||||
"memo" => LightWallet::memo_str(&Some(om.memo.clone())),
|
"memo" => LightWallet::memo_str(&Some(om.memo.clone()))
|
||||||
|
};
|
||||||
|
|
||||||
|
if include_memo_hex {
|
||||||
|
o.insert("memohex", hex::encode(om.memo.as_bytes())).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return o;
|
||||||
})
|
})
|
||||||
.collect::<Vec<JsonValue>>();
|
.collect::<Vec<JsonValue>>();
|
||||||
|
|
||||||
@ -905,15 +912,25 @@ impl LightClient {
|
|||||||
txns.extend(v.notes.iter()
|
txns.extend(v.notes.iter()
|
||||||
.filter( |nd| !nd.is_change )
|
.filter( |nd| !nd.is_change )
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map ( |(i, nd)|
|
.map ( |(i, nd)| {
|
||||||
object! {
|
let mut o = object! {
|
||||||
"block_height" => v.block,
|
"block_height" => v.block,
|
||||||
"datetime" => v.datetime,
|
"datetime" => v.datetime,
|
||||||
"position" => i,
|
"position" => i,
|
||||||
"txid" => format!("{}", v.txid),
|
"txid" => format!("{}", v.txid),
|
||||||
"amount" => nd.note.value as i64,
|
"amount" => nd.note.value as i64,
|
||||||
"address" => LightWallet::note_address(self.config.hrp_sapling_address(), nd),
|
"address" => LightWallet::note_address(self.config.hrp_sapling_address(), nd),
|
||||||
"memo" => LightWallet::memo_str(&nd.memo),
|
"memo" => LightWallet::memo_str(&nd.memo)
|
||||||
|
};
|
||||||
|
|
||||||
|
if include_memo_hex {
|
||||||
|
o.insert("memohex", match &nd.memo {
|
||||||
|
Some(m) => hex::encode(m.as_bytes()),
|
||||||
|
_ => "".to_string(),
|
||||||
|
}).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
return o;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1089,27 +1089,25 @@ impl LightWallet {
|
|||||||
Some(ret) => ret,
|
Some(ret) => ret,
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
info!("A sapling note was sent to wallet in {}", tx.txid());
|
||||||
|
|
||||||
|
// Do it in a short scope because of the write lock.
|
||||||
|
let mut txs = self.txs.write().unwrap();
|
||||||
|
|
||||||
if memo.to_utf8().is_some() {
|
// Update memo if we have this Tx.
|
||||||
info!("A sapling note was sent to wallet in {} that had a memo", tx.txid());
|
match txs.get_mut(&tx.txid())
|
||||||
|
.and_then(|t| {
|
||||||
// Do it in a short scope because of the write lock.
|
t.notes.iter_mut().find(|nd| nd.note == note)
|
||||||
let mut txs = self.txs.write().unwrap();
|
}) {
|
||||||
|
None => {
|
||||||
// Update memo if we have this Tx.
|
info!("No txid matched for incoming sapling funds while updating memo");
|
||||||
match txs.get_mut(&tx.txid())
|
()
|
||||||
.and_then(|t| {
|
},
|
||||||
t.notes.iter_mut().find(|nd| nd.note == note)
|
Some(nd) => {
|
||||||
}) {
|
nd.memo = Some(memo)
|
||||||
None => {
|
|
||||||
info!("No txid matched for incoming sapling funds while updating memo");
|
|
||||||
()
|
|
||||||
},
|
|
||||||
Some(nd) => {
|
|
||||||
nd.memo = Some(memo)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also scan the output to see if it can be decoded with our OutgoingViewKey
|
// Also scan the output to see if it can be decoded with our OutgoingViewKey
|
||||||
|
Loading…
Reference in New Issue
Block a user