Skip to content

Commit

Permalink
feat(faucet): write foundation cash note to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Jun 3, 2024
1 parent 148c8f3 commit e4db3d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions sn_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tokio = { version = "1.35.0", features = [
"macros",
"rt",
"sync",
"fs",
"time",
] }
tracing = { version = "~0.1.26" }
Expand Down
21 changes: 21 additions & 0 deletions sn_client/src/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use crate::{wallet::send, Client, Error, Result};
use sn_transfers::{load_genesis_wallet, HotWallet, NanoTokens, FOUNDATION_PK};
#[cfg(not(target_arch = "wasm32"))]
use tokio::fs;

const INITIAL_FAUCET_BALANCE: NanoTokens = NanoTokens::from(900000000000000000);

Expand Down Expand Up @@ -92,6 +94,25 @@ pub async fn fund_faucet_from_genesis_wallet(
println!(
"Successfully verified the transfer from genesis to foundation on the second try."
);

#[cfg(not(target_arch = "wasm32"))]
{
// write the foundation cashnote to disk
let root_dir = faucet_wallet.api().wallet_dir();

let foundation_cashnote_path = root_dir.join("foundation_cashnote.cash_note");

debug!("Writing cash note to: {foundation_cashnote_path:?}");
let hex = foundation_cashnote
.to_hex()
.map_err(|_| Error::GenesisDisbursement)?;

if let Err(error) = fs::write(foundation_cashnote_path, hex).await {
error!("Could not write the foundation cashnote to disk: {error}.");
return Err(Error::from(error));
}
}

info!("Successfully verified the transfer from genesis to foundation on the second try.");
}

Expand Down
4 changes: 4 additions & 0 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ impl HotWallet {
self.watchonly_wallet.api()
}

pub fn root_dir(&self) -> &Path {
self.watchonly_wallet.api().wallet_dir()
}

/// Stores the wallet to disk.
/// This requires having exclusive access to the wallet to prevent concurrent processes from writing to it
fn store(&self, exclusive_access: WalletExclusiveAccess) -> Result<()> {
Expand Down

0 comments on commit e4db3d9

Please sign in to comment.