Browse Source

Notes command

checkpoints
Aditya Kulkarni 5 years ago
parent
commit
7b34d4fa7e
  1. 20
      rust-lightclient/src/commands.rs
  2. 20
      rust-lightclient/src/lightclient.rs
  3. 14
      rust-lightclient/src/lightwallet.rs
  4. 3
      rust-lightclient/src/main.rs

20
rust-lightclient/src/commands.rs

@ -147,6 +147,25 @@ impl Command for TransactionsCommand {
}
struct NotesCommand {}
impl Command for NotesCommand {
fn help(&self) {
println!("Show Notes");
}
fn short_help(&self) -> String {
"List all sapling notes in the wallet".to_string()
}
fn exec(&self, _args: &[String], lightclient: &mut LightClient) {
let txns = lightclient.do_list_notes();
println!("{}", txns.pretty(2));
}
}
struct QuitCommand {}
impl Command for QuitCommand {
fn help(&self) {
@ -174,6 +193,7 @@ pub fn get_commands() -> Box<HashMap<String, Box<dyn Command>>> {
map.insert("save".to_string(), Box::new(SaveCommand{}));
map.insert("quit".to_string(), Box::new(QuitCommand{}));
map.insert("list".to_string(), Box::new(TransactionsCommand{}));
map.insert("notes".to_string(), Box::new(NotesCommand{}));
map.insert("seed".to_string(), Box::new(SeedCommand{}));
Box::new(map)

20
rust-lightclient/src/lightclient.rs

@ -136,6 +136,26 @@ impl LightClient {
self.wallet.get_seed_phrase()
}
// Return a list of all notes, spent and unspent
pub fn do_list_notes(&self) -> JsonValue {
JsonValue::Array(
self.wallet.txs.read().unwrap().iter()
.flat_map( |(txid, wtx)| {
wtx.notes.iter().map(move |nd|
object!{
"created_in_block" => wtx.block,
"created_in_txid" => format!("{}", txid),
"value" => nd.note.value,
"is_change" => nd.is_change,
"address" => LightWallet::address_from_extfvk(&nd.extfvk, nd.diversifier),
"spent" => nd.spent.map(|spent_txid| format!("{}", spent_txid))
}
)
})
.collect::<Vec<JsonValue>>()
)
}
pub fn do_list_transactions(&self) -> JsonValue {
// Create a list of TransactionItems
let mut tx_list = self.wallet.txs.read().unwrap().iter()

14
rust-lightclient/src/lightwallet.rs

@ -42,7 +42,7 @@ use zcash_primitives::{
use crate::address;
use crate::prover;
const ANCHOR_OFFSET: u32 = 10;
const ANCHOR_OFFSET: u32 = 1;
const SAPLING_ACTIVATION_HEIGHT: i32 = 280_000;
@ -94,8 +94,8 @@ impl BlockData {
pub struct SaplingNoteData {
account: usize,
extfvk: ExtendedFullViewingKey, // Technically, this should be recoverable from the account number, but we're going to refactor this in the future, so I'll write it again here.
diversifier: Diversifier,
pub extfvk: ExtendedFullViewingKey, // Technically, this should be recoverable from the account number, but we're going to refactor this in the future, so I'll write it again here.
pub diversifier: Diversifier,
pub note: Note<Bls12>,
witnesses: Vec<IncrementalWitness<Node>>,
nullifier: [u8; 32],
@ -543,8 +543,9 @@ impl LightWallet {
}
}
pub fn address(&self, account: usize) -> String {
encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, &self.address[account])
pub fn address_from_extfvk(extfvk: &ExtendedFullViewingKey, diversifier: Diversifier) -> String {
encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS,
&extfvk.fvk.vk.into_payment_address(diversifier, &JUBJUB).unwrap())
}
pub fn get_seed_phrase(&self) -> String {
@ -879,8 +880,7 @@ impl LightWallet {
println!("{}: Adding output", now() - start_time);
if let Err(e) = match to {
address::RecipientAddress::Shielded(to) => {
// TODO Make it use encoded_memo
builder.add_sapling_output(ovk, to.clone(), value, None)
builder.add_sapling_output(ovk, to.clone(), value, encoded_memo)
}
address::RecipientAddress::Transparent(to) => {
builder.add_transparent_output(&to, value)

3
rust-lightclient/src/main.rs

@ -38,9 +38,6 @@ pub fn main() {
println!("Starting Light Client");
// At startup, read the wallet.dat
commands::do_user_command(&"read".to_string(), &mut lightclient);
// `()` can be used when no completer is required
let mut rl = Editor::<()>::new();
let _ = rl.load_history("history.txt");

Loading…
Cancel
Save