Skip to content

Commit

Permalink
hmmm
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Aug 28, 2023
1 parent 6cb10ad commit 8dea972
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 37 deletions.
10 changes: 4 additions & 6 deletions sn_cli/src/subcommands/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

use super::wallet::{chunk_and_pay_for_storage, ChunkedFile};

use bytes::{Bytes, BytesMut};
use bytes::Bytes;
use clap::Parser;
use color_eyre::Result;
use libp2p::futures::future::join_all;
use sn_client::{Client, Files, WalletClient, MAX_CONCURRENT_CHUNK_UPLOAD};
use sn_client::{Client, Files, MAX_CONCURRENT_CHUNK_UPLOAD};
use sn_protocol::storage::{Chunk, ChunkAddress};
use sn_transfers::client_transfers::ContentPaymentsMap;
use tokio::{fs, io::AsyncReadExt, sync::Semaphore};
use tokio::{fs, sync::Semaphore};

use std::{
// fs,
Expand Down Expand Up @@ -98,8 +97,7 @@ async fn upload_files(
let file_names_path = root_dir.join("uploaded_files");

// Payment shall always be verified.
let (chunks_to_upload, wallet_client) =
chunk_and_pay_for_storage(&client, root_dir, &files_path, true).await?;
let chunks_to_upload = chunk_and_pay_for_storage(&client, root_dir, &files_path, true).await?;

let chunk_semaphore = Arc::new(Semaphore::new(MAX_CONCURRENT_CHUNK_UPLOAD));

Expand Down
11 changes: 3 additions & 8 deletions sn_cli/src/subcommands/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
use sn_client::{Client, Files, WalletClient};
use sn_dbc::Token;
use sn_protocol::storage::ChunkAddress;
use sn_transfers::{
client_transfers::ContentPaymentsMap,
wallet::{parse_public_address, LocalWallet},
};
use sn_transfers::wallet::{parse_public_address, LocalWallet};

use bytes::Bytes;
use clap::Parser;
Expand Down Expand Up @@ -240,7 +237,7 @@ pub(super) async fn chunk_and_pay_for_storage(
root_dir: &Path,
files_path: &Path,
verify_store: bool,
) -> Result<(BTreeMap<XorName, ChunkedFile>, WalletClient)> {
) -> Result<BTreeMap<XorName, ChunkedFile>> {
trace!("Starting to chunk_and_pay_for_storage");
let wallet = LocalWallet::load_from(root_dir)
.await
Expand Down Expand Up @@ -325,8 +322,6 @@ pub(super) async fn chunk_and_pay_for_storage(
chunked_files.len(),
);

// let wallet = wallet_client.into_wallet();

if let Err(err) = wallet_client.store_local_wallet().await {
println!("Failed to store wallet: {err:?}");
} else {
Expand All @@ -337,5 +332,5 @@ pub(super) async fn chunk_and_pay_for_storage(
}

println!("Successfully paid for storage and generated the proofs. They can now be sent to the storage nodes when uploading paid chunks.");
Ok((chunked_files, wallet_client))
Ok(chunked_files)
}
2 changes: 1 addition & 1 deletion sn_client/src/file_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sn_protocol::{
storage::{Chunk, ChunkAddress},
NetworkAddress, PrettyPrintRecordKey,
};
use sn_transfers::{client_transfers::ContentPaymentsMap, wallet::LocalWallet};
use sn_transfers::wallet::LocalWallet;

use bincode::deserialize;
use bytes::Bytes;
Expand Down
21 changes: 3 additions & 18 deletions sn_client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use sn_transfers::client_transfers::{ContentPaymentsIdMap, ContentPaymentsMap, SpendRequest};
use sn_transfers::client_transfers::SpendRequest;

use super::Client;

Expand All @@ -19,7 +19,7 @@ use sn_transfers::{

use futures::future::join_all;
use std::{
collections::{BTreeMap, HashMap},
collections::BTreeMap,
iter::Iterator,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -181,21 +181,6 @@ impl WalletClient {
}
}

/// TODO: get the client payment dbcs from the wallet direct. No copying.
///
/// Use those when paying....
///
///
///
/// profit?
///
///
///
///
///
///
///
///
self.wallet
.local_send_storage_payment(all_data_payments, None)
.await?;
Expand Down Expand Up @@ -260,7 +245,7 @@ impl WalletClient {
.is_ok()
{
// println!("All pending txs were successfully republished!");
let _ = self.wallet.clear_unconfirmed_txs();
self.wallet.clear_unconfirmed_txs();
// We might want to be _really_ sure and do the below
// as well, but it's not necessary.
// use crate::domain::wallet::VerifyingClient;
Expand Down
1 change: 0 additions & 1 deletion sn_transfers/src/client_transfers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use sn_dbc::{
use sn_protocol::NetworkAddress;

pub type ContentPaymentsIdMap = BTreeMap<NetworkAddress, Vec<DbcId>>;
pub type ContentPaymentsMap = BTreeMap<NetworkAddress, Vec<Dbc>>;

/// The input details necessary to
/// carry out a transfer of tokens.
Expand Down
6 changes: 3 additions & 3 deletions sn_transfers/src/wallet/local_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl LocalWallet {
let mut available_dbcs = vec![];

for id in self.wallet.available_dbcs.iter() {
let held_dbc = self.wallet.dbc(&id);
let held_dbc = self.wallet.dbc(id);
if let Some(dbc) = held_dbc {
if let Ok(derived_key) = dbc.derived_key(&self.key) {
available_dbcs.push((dbc.clone(), derived_key));
Expand Down Expand Up @@ -350,7 +350,7 @@ impl KeyLessWallet {
return Ok(());
}

if !dbc.derived_key(key).is_ok() {
if dbc.derived_key(key).is_err() {
continue;
}

Expand All @@ -361,7 +361,7 @@ impl KeyLessWallet {
let mut new_balance = 0;
// get the total of all available dbcs we're holding
for dbc_id in self.available_dbcs.iter() {
if let Some(dbc) = self.dbc(&dbc_id) {
if let Some(dbc) = self.dbc(dbc_id) {
let token = dbc.token()?;
new_balance += token.as_nano();
}
Expand Down

0 comments on commit 8dea972

Please sign in to comment.