mirror of
https://github.com/Qortal/piratewallet-light-cli.git
synced 2025-01-30 18:42:15 +00:00
Add guards around updating memo, save wallet
This commit is contained in:
parent
7bcc266e70
commit
703192f45b
@ -342,6 +342,9 @@ impl LightClient {
|
||||
info!("Created new wallet with a new seed!");
|
||||
info!("Created LightClient to {}", &config.server);
|
||||
|
||||
// Save
|
||||
l.do_save().map_err(|s| io::Error::new(ErrorKind::PermissionDenied, s))?;
|
||||
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
@ -367,6 +370,9 @@ impl LightClient {
|
||||
info!("Created new wallet!");
|
||||
info!("Created LightClient to {}", &config.server);
|
||||
|
||||
// Save
|
||||
l.do_save().map_err(|s| io::Error::new(ErrorKind::PermissionDenied, s))?;
|
||||
|
||||
Ok(l)
|
||||
}
|
||||
|
||||
@ -576,14 +582,18 @@ impl LightClient {
|
||||
1_000_000, // 1 MB write buffer
|
||||
File::create(self.config.get_wallet_path()).unwrap());
|
||||
|
||||
match self.wallet.write().unwrap().write(&mut file_buffer) {
|
||||
let r = match self.wallet.write().unwrap().write(&mut file_buffer) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => {
|
||||
let err = format!("ERR: {}", e);
|
||||
error!("{}", err);
|
||||
Err(e.to_string())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
file_buffer.flush().map_err(|e| format!("{}", e))?;
|
||||
|
||||
r
|
||||
}
|
||||
|
||||
pub fn get_server_uri(&self) -> http::Uri {
|
||||
|
@ -1062,14 +1062,21 @@ impl LightWallet {
|
||||
};
|
||||
|
||||
{
|
||||
info!("A sapling note was spent in {}", tx.txid());
|
||||
// Update the WalletTx
|
||||
info!("A sapling note was sent in {}, getting memo", tx.txid());
|
||||
|
||||
// Do it in a short scope because of the write lock.
|
||||
let mut txs = self.txs.write().unwrap();
|
||||
txs.get_mut(&tx.txid()).unwrap()
|
||||
.notes.iter_mut()
|
||||
.find(|nd| nd.note == note).unwrap()
|
||||
.memo = Some(memo);
|
||||
|
||||
// Update memo if we have this Tx.
|
||||
match txs.get_mut(&tx.txid())
|
||||
.and_then(|t| {
|
||||
t.notes.iter_mut().find(|nd| nd.note == note)
|
||||
}) {
|
||||
None => (),
|
||||
Some(nd) => {
|
||||
nd.memo = Some(memo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user