Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(faucet): write foundation cash note to disk
Browse files Browse the repository at this point in the history
joshuef committed Jun 3, 2024
1 parent 148c8f3 commit 42ae17d
Showing 3 changed files with 41 additions and 7 deletions.
23 changes: 16 additions & 7 deletions sn_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -19,6 +19,14 @@ test-utils = ["sn_peers_acquisition", "lazy_static", "eyre"]
websockets = ["sn_networking/websockets", "sn_protocol/websockets"]

[dependencies]
tokio = { version = "1.35.0", features = [
"io-util",
"macros",
"rt",
"sync",
"fs",
"time",
] }
bip39 = "2.0.0"
curv = { version = "0.10.1", package = "sn_curv", default-features = false, features = [
"num-bigint",
@@ -49,13 +57,6 @@ sn_transfers = { path = "../sn_transfers", version = "0.18.1" }
tempfile = "3.6.0"
thiserror = "1.0.23"
tiny-keccak = "~2.0.2"
tokio = { version = "1.35.0", features = [
"io-util",
"macros",
"rt",
"sync",
"time",
] }
tracing = { version = "~0.1.26" }
xor_name = "5.0.0"
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.2.12", optional = true }
@@ -89,3 +90,11 @@ console_error_panic_hook = "0.1.6"
tracing-wasm = "0.2.1"
wasmtimer = "0.2.0"
web-sys = { version = "0.3.22", features = ["console"] }
# no fs for tokio on wasm
tokio = { version = "1.35.0", features = [
"io-util",
"macros",
"rt",
"sync",
"time",
] }
21 changes: 21 additions & 0 deletions sn_client/src/faucet.rs
Original file line number Diff line number Diff line change
@@ -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);

@@ -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.");
}

4 changes: 4 additions & 0 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
@@ -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<()> {

0 comments on commit 42ae17d

Please sign in to comment.