Skip to content

Commit

Permalink
chore: fix doc code for creating new wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
iancoleman committed Mar 12, 2024
1 parent 4a6bace commit 19a812d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion sn_client/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ impl Client {
/// use sn_transfers::HotWallet;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client.clone(), wallet);
/// // Set up an address
/// let mut rng = rand::thread_rng();
Expand Down
24 changes: 12 additions & 12 deletions sn_client/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ impl ClientRegister {
/// # async fn main() -> Result<(),Error>{
/// # let mut rng = rand::thread_rng();
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// let address = XorName::random(&mut rng);
/// let mut wallet_client = WalletClient::new(client.clone(), wallet);
Expand Down Expand Up @@ -183,8 +183,8 @@ impl ClientRegister {
/// # async fn main() -> Result<(),Error>{
/// # let mut rng = rand::thread_rng();
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let address = XorName::random(&mut rng);
/// # let mut wallet_client = WalletClient::new(client.clone(), wallet);
Expand Down Expand Up @@ -218,8 +218,8 @@ impl ClientRegister {
/// # async fn main() -> Result<(),Error>{
/// # let mut rng = rand::thread_rng();
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let address = XorName::random(&mut rng);
/// # let mut wallet_client = WalletClient::new(client.clone(), wallet);
Expand Down Expand Up @@ -253,8 +253,8 @@ impl ClientRegister {
/// # async fn main() -> Result<(),Error>{
/// # let mut rng = rand::thread_rng();
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let address = XorName::random(&mut rng);
/// let mut wallet_client = WalletClient::new(client.clone(), wallet);
Expand Down Expand Up @@ -289,8 +289,8 @@ impl ClientRegister {
/// # async fn main() -> Result<(),Error>{
/// # let mut rng = rand::thread_rng();
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let address = XorName::random(&mut rng);
/// # let mut wallet_client = WalletClient::new(client.clone(), wallet);
Expand Down Expand Up @@ -479,8 +479,8 @@ impl ClientRegister {
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// let address = XorName::random(&mut rng);
/// # let temporary_path = TempDir::new()?.path().to_owned();
/// # let main_secret_key = Some(MainSecretKey::new(SecretKey::random()));
/// # let mut wallet = HotWallet::load_from_path(&temporary_path,main_secret_key)?;
/// # let main_secret_key = MainSecretKey::new(SecretKey::random());
/// # let mut wallet = HotWallet::create_from_key(&temporary_path,main_secret_key)?;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// let mut wallet_client = WalletClient::new(client.clone(), wallet);
/// // Run sync of a Client Register instance
Expand Down
36 changes: 18 additions & 18 deletions sn_client/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// # Ok(())
/// # }
Expand All @@ -79,7 +79,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// wallet_client.store_local_wallet()?;
/// # Ok(())
Expand All @@ -100,7 +100,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// println!("{}" ,wallet_client.balance());
/// # Ok(())
Expand All @@ -121,7 +121,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// if wallet_client.unconfirmed_spend_requests_exist() {println!("Unconfirmed spends exist!")};
/// # Ok(())
Expand Down Expand Up @@ -152,7 +152,7 @@ impl WalletClient {
/// # use std::io::Bytes;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// use libp2p_identity::PeerId;
/// use sn_protocol::NetworkAddress;
///
Expand Down Expand Up @@ -201,7 +201,7 @@ impl WalletClient {
/// # use std::io::Bytes;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// use libp2p_identity::PeerId;
/// use sn_protocol::NetworkAddress;
///
Expand Down Expand Up @@ -246,7 +246,7 @@ impl WalletClient {
/// # use std::io::Bytes;
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// use sn_transfers::NanoTokens;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// let nano = NanoTokens::from(10);
Expand Down Expand Up @@ -362,7 +362,7 @@ impl WalletClient {
/// use sn_registers::{Permissions, RegisterAddress};
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// # let mut rng = rand::thread_rng();
/// # let xor_name = XorName::random(&mut rng);
/// let network_address = NetworkAddress::from_peer(PeerId::random());
Expand Down Expand Up @@ -403,7 +403,7 @@ impl WalletClient {
/// use sn_registers::{Permissions, RegisterAddress};
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client.clone(), wallet);
/// let mut rng = rand::thread_rng();
/// let xor_name = XorName::random(&mut rng);
Expand Down Expand Up @@ -537,7 +537,7 @@ impl WalletClient {
/// use sn_transfers::{MainPubkey, Payment, PaymentQuote};
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// let mut cost_map:BTreeMap<XorName,(MainPubkey,PaymentQuote,Vec<u8>)> = BTreeMap::new();
/// wallet_client.pay_for_records(&cost_map,true).await?;
Expand Down Expand Up @@ -649,7 +649,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// let paying_wallet = wallet_client.into_wallet();
/// // Display the wallet balance in the terminal
Expand All @@ -674,7 +674,7 @@ impl WalletClient {
/// # async fn main() -> Result<(),Error>{
/// # let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// # let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// # let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut wallet_client = WalletClient::new(client, wallet);
/// let paying_wallet = wallet_client.mut_wallet();
/// // Display the mutable wallet balance in the terminal
Expand Down Expand Up @@ -704,7 +704,7 @@ impl Client {
/// # async fn main() -> Result<(),Error>{
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// // An example of sending storage payment transfers over the network with validation
/// client.send_spends(wallet.unconfirmed_spend_requests().iter(),true).await?;
/// # Ok(())
Expand Down Expand Up @@ -802,7 +802,7 @@ impl Client {
/// use sn_transfers::Transfer;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let transfer = Transfer::from_hex("13abc").unwrap();
/// // An example for using client.receive() for cashNotes
/// let cash_notes = match client.receive(&transfer, &wallet).await {
Expand Down Expand Up @@ -891,7 +891,7 @@ impl Client {
/// use sn_transfers::Transfer;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let transfer = Transfer::from_hex("").unwrap();
/// let cash_notes = client.receive(&transfer, &wallet).await?;
/// // Verification:
Expand Down Expand Up @@ -957,8 +957,8 @@ impl Client {
/// use sn_transfers::Transfer;
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut first_wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut second_wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut first_wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let mut second_wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let tokens = send(
/// first_wallet, // From
/// second_wallet.balance(), // To
Expand Down Expand Up @@ -1076,7 +1076,7 @@ pub async fn send(
/// use sn_transfers::{Transaction, Transfer, UniquePubkey};
/// let client = Client::new(SecretKey::random(), None, false, None, None).await?;
/// # let tmp_path = TempDir::new()?.path().to_owned();
/// let mut wallet = HotWallet::load_from_path(&tmp_path,Some(MainSecretKey::new(SecretKey::random())))?;
/// let mut wallet = HotWallet::create_from_key(&tmp_path,MainSecretKey::new(SecretKey::random()))?;
/// let transaction = Transaction {inputs: Vec::new(),outputs: Vec::new(),};
/// let secret_key = UniquePubkey::new(SecretKey::random().public_key());
///
Expand Down

0 comments on commit 19a812d

Please sign in to comment.