Skip to content

Commit

Permalink
Revert "feat: keep transfers in mem instead of mem and i/o heavy cash…
Browse files Browse the repository at this point in the history
…notes"

This reverts commit 9eb32bb.
  • Loading branch information
joshuef committed Oct 18, 2023
1 parent 3e620a7 commit 72a41ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
10 changes: 6 additions & 4 deletions sn_client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ impl WalletClient {
pub fn get_payment_transfers(&self, address: &NetworkAddress) -> WalletResult<Vec<Transfer>> {
match &address.as_xorname() {
Some(xorname) => {
let transfers = self.wallet.get_payment_transfers(xorname);
let cash_notes = self.wallet.get_payment_cash_notes(xorname);

info!(
"Payment transfers retrieved for {xorname:?} from wallet: {:?}",
transfers.len()
"Payment cash notes retrieved from wallet: {:?}",
cash_notes.len()
);
Ok(transfers)
Ok(Transfer::transfers_from_cash_notes(cash_notes)?)
}
None => Err(WalletError::InvalidAddressType),
}
Expand Down Expand Up @@ -207,6 +207,8 @@ impl WalletClient {
all_data_payments: BTreeMap<XorName, Vec<(MainPubkey, NanoTokens)>>,
verify_store: bool,
) -> WalletResult<NanoTokens> {
// TODO:
// Check for any existing payment CashNotes, and use them if they exist, only topping up if needs be
let mut total_cost = NanoTokens::zero();
for (_data, costs) in all_data_payments.iter() {
for (_target, cost) in costs {
Expand Down
4 changes: 2 additions & 2 deletions sn_transfers/src/transfers/offline_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::{
rng, CashNote, DerivationIndex, DerivedSecretKey, Hash, Input, MainPubkey, NanoTokens,
SignedSpend, Transaction, TransactionBuilder, Transfer, UniquePubkey,
SignedSpend, Transaction, TransactionBuilder, UniquePubkey,
};
use crate::{Error, Result};

Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct OfflineTransfer {
pub all_spend_requests: Vec<SignedSpend>,
}

pub type PaymentDetails = (Transfer, MainPubkey, NanoTokens);
pub type PaymentDetails = (UniquePubkey, MainPubkey, NanoTokens);

/// Xorname of data from which the content was fetched, mapping to the CashNote UniquePubkey (its id on disk)
/// the main key for that CashNote and the value
Expand Down
27 changes: 17 additions & 10 deletions sn_transfers/src/wallet/local_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,24 @@ impl LocalWallet {
}

/// Return the payment cash_note ids for the given content address name if cached.
pub fn get_payment_transfers(&self, name: &XorName) -> Vec<Transfer> {
let mut transfers: Vec<Transfer> = vec![];

if let Some(payment) = self.get_payment_unique_pubkeys_and_values(name) {
for (trans, _main_pub_key, value) in payment {
trace!("Current transfer for chunk {name:?} is of {value:?} tokens.");
transfers.push(trans.to_owned());
pub fn get_payment_cash_notes(&self, name: &XorName) -> Vec<CashNote> {
let ids = self.get_payment_unique_pubkeys_and_values(name);
// now grab all those cash_notes
let mut cash_notes: Vec<CashNote> = vec![];

if let Some(ids) = ids {
for (id, _main_pub_key, _value) in ids {
if let Some(cash_note) = load_created_cash_note(id, &self.wallet_dir) {
trace!(
"Current cash_note of chunk {name:?} is paying {:?} tokens.",
cash_note.value()
);
cash_notes.push(cash_note);
}
}
}

transfers
cash_notes
}

/// Make a transfer and return all created cash_notes
Expand Down Expand Up @@ -326,7 +333,7 @@ impl LocalWallet {
for (content_addr, payees) in all_data_payments {
for (payee, token) in payees {
if let Some(cash_note) =
offline_transfer
&offline_transfer
.created_cash_notes
.iter()
.find(|cash_note| {
Expand All @@ -340,7 +347,7 @@ impl LocalWallet {
let cash_notes_for_content: &mut Vec<PaymentDetails> =
all_transfers_per_address.entry(content_addr).or_default();
cash_notes_for_content.push((
Transfer::transfers_from_cash_note(cash_note.to_owned())?,
cash_note.unique_pubkey(),
*cash_note.main_pubkey(),
cash_note.value()?,
));
Expand Down

0 comments on commit 72a41ea

Please sign in to comment.