Edit Contacts
This commit is contained in:
parent
653cc44a49
commit
9907c38bb3
14
src/db.rs
14
src/db.rs
|
@ -143,7 +143,7 @@ impl DbAdapter {
|
|||
account INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
PRIMARY KEY (account, name))", NO_PARAMS
|
||||
PRIMARY KEY (account, address))", NO_PARAMS
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -537,8 +537,16 @@ impl DbAdapter {
|
|||
}
|
||||
|
||||
pub fn store_contact(&self, account: u32, contact: &Contact) -> anyhow::Result<()> {
|
||||
self.connection.execute("INSERT INTO contacts(account, name, address)
|
||||
VALUES (?1, ?2, ?3) ON CONFLICT DO NOTHING", params![account, &contact.name, &contact.address])?;
|
||||
log::info!("{:?}", contact);
|
||||
if contact.name.is_empty() {
|
||||
self.connection.execute("DELETE FROM contacts WHERE account = ?1 AND address = ?2",
|
||||
params![account, contact.address])?;
|
||||
}
|
||||
else {
|
||||
self.connection.execute("INSERT INTO contacts(account, name, address)
|
||||
VALUES (?1, ?2, ?3) ON CONFLICT (account, address) DO UPDATE SET
|
||||
name = excluded.name", params![account, &contact.name, &contact.address])?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ pub mod lw_rpc;
|
|||
pub const NETWORK: Network = Network::MainNetwork;
|
||||
|
||||
// Mainnet
|
||||
pub const LWD_URL: &str = "https://mainnet.lightwalletd.com:9067";
|
||||
// pub const LWD_URL: &str = "https://mainnet.lightwalletd.com:9067";
|
||||
// pub const LWD_URL: &str = "https://lwdv3.zecwallet.co";
|
||||
// pub const LWD_URL: &str = "http://lwd.hanh.me:9067";
|
||||
// pub const LWD_URL: &str = "http://127.0.0.1:9067";
|
||||
pub const LWD_URL: &str = "http://127.0.0.1:9067";
|
||||
|
||||
// Testnet
|
||||
// pub const LWD_URL: &str = "https://testnet.lightwalletd.com:9067";
|
||||
|
|
|
@ -157,7 +157,7 @@ pub async fn sync_async(
|
|||
let mut my_nfs: Vec<Nf> = vec![];
|
||||
for nf in b.spends.iter() {
|
||||
if let Some(&nf_ref) = nfs.get(nf) {
|
||||
log::info!("NF FOUND {} {}", nf_ref.id_note, b.height);
|
||||
log::debug!("NF FOUND {} {}", nf_ref.id_note, b.height);
|
||||
db.mark_spent(nf_ref.id_note, b.height)?;
|
||||
my_nfs.push(*nf);
|
||||
}
|
||||
|
|
|
@ -109,9 +109,6 @@ pub async fn decode_transaction(
|
|||
|
||||
pub async fn retrieve_tx_info(tx_ids: &[u32], ld_url: &str, db_path: &str) -> anyhow::Result<()> {
|
||||
let mut tx_ids_set: HashSet<u32> = HashSet::new();
|
||||
for &tx_id in tx_ids.iter() {
|
||||
tx_ids_set.insert(tx_id);
|
||||
}
|
||||
let mut client = connect_lightwalletd(ld_url).await?;
|
||||
let db = DbAdapter::new(db_path)?;
|
||||
let nfs = db.get_nullifiers_raw()?;
|
||||
|
@ -119,7 +116,9 @@ pub async fn retrieve_tx_info(tx_ids: &[u32], ld_url: &str, db_path: &str) -> an
|
|||
for nf in nfs.iter() {
|
||||
nf_map.insert((nf.0, nf.2.clone()), nf.1);
|
||||
}
|
||||
for &id_tx in tx_ids_set.iter() {
|
||||
for &id_tx in tx_ids.iter() { // need to keep tx order
|
||||
if tx_ids_set.contains(&id_tx) { continue }
|
||||
tx_ids_set.insert(id_tx);
|
||||
let (account, height, tx_hash) = db.get_txhash(id_tx)?;
|
||||
let fvk = db.get_ivk(account)?;
|
||||
let tx_info =
|
||||
|
@ -137,9 +136,9 @@ pub async fn retrieve_tx_info(tx_ids: &[u32], ld_url: &str, db_path: &str) -> an
|
|||
|
||||
fn decode_contact(address: &str, memo: &str) -> anyhow::Result<Option<Contact>> {
|
||||
let res = if let Some(memo_line) = memo.lines().next() {
|
||||
let name = memo_line.strip_prefix("Contact: ");
|
||||
let name = memo_line.strip_prefix("Contact:");
|
||||
name.map(|name| Contact {
|
||||
name: name.to_string(),
|
||||
name: name.trim().to_string(),
|
||||
address: address.to_string(),
|
||||
})
|
||||
} else { None };
|
||||
|
|
Loading…
Reference in New Issue