Skip to content

Commit

Permalink
Restore original enums and add new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Sep 15, 2023
1 parent 709ccb3 commit c598735
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
4 changes: 2 additions & 2 deletions zingo-testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ pub mod scenarios {
//! A "faucet" is a lightclient that receives mining rewards
let zingo_config = self.make_unique_data_dir_and_load_config();
LightClient::create_from_wallet_base_async(
WalletBase::MnemonicPhrase(self.seed.clone(), 0),
WalletBase::MnemonicPhrase(self.seed.clone()),
&zingo_config,
birthday,
overwrite,
Expand All @@ -416,7 +416,7 @@ pub mod scenarios {
) -> LightClient {
let zingo_config = self.make_unique_data_dir_and_load_config();
LightClient::create_from_wallet_base_async(
WalletBase::MnemonicPhrase(mnemonic_phrase, 0),
WalletBase::MnemonicPhrase(mnemonic_phrase),
&zingo_config,
birthday,
overwrite,
Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,7 @@ mod tests {
let wallet_name = data_dir.join("zingo-wallet.dat");
let config = ZingoConfig::create_unconnected(ChainType::FakeMainnet, Some(data_dir));
let lc = LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(TEST_SEED.to_string(), 0),
WalletBase::MnemonicPhrase(TEST_SEED.to_string()),
&config,
0,
false,
Expand All @@ -2124,7 +2124,7 @@ mod tests {
format!(
"{:?}",
LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(TEST_SEED.to_string(), 0),
WalletBase::MnemonicPhrase(TEST_SEED.to_string()),
&config,
0,
false
Expand Down
44 changes: 34 additions & 10 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ impl WalletOptions {
/// Data used to initialize new instance of LightWallet
pub enum WalletBase {
FreshEntropy,
SeedBytes([u8; 32], u32),
MnemonicPhrase(String, u32),
Mnemonic(Mnemonic, u32),
SeedBytes([u8; 32]),
MnemonicPhrase(String),
Mnemonic(Mnemonic),
SeedBytesAndIndex([u8; 32], u32),
MnemonicPhraseAndIndex(String, u32),
MnemonicAndIndex(Mnemonic, u32),
/// Unified full viewing key
Ufvk(String),
/// Unified spending key
Expand All @@ -203,7 +206,7 @@ impl WalletBase {
if (&base[0..5]) == "uview" {
WalletBase::Ufvk(base)
} else {
WalletBase::MnemonicPhrase(base, 0)
WalletBase::MnemonicPhrase(base)
}
}
}
Expand Down Expand Up @@ -580,18 +583,32 @@ impl LightWallet {
// Create a random seed.
let mut system_rng = OsRng;
system_rng.fill(&mut seed_bytes);
return Self::new(config, WalletBase::SeedBytes(seed_bytes, 0), height);
return Self::new(config, WalletBase::SeedBytes(seed_bytes), height);
}
WalletBase::SeedBytes(seed_bytes, position) => {
WalletBase::SeedBytes(seed_bytes) => {
return Self::new(config, WalletBase::SeedBytesAndIndex(seed_bytes, 0), height);
}
WalletBase::SeedBytesAndIndex(seed_bytes, position) => {
let mnemonic = Mnemonic::from_entropy(seed_bytes).map_err(|e| {
Error::new(
ErrorKind::InvalidData,
format!("Error parsing phrase: {}", e),
)
})?;
return Self::new(config, WalletBase::Mnemonic(mnemonic, position), height);
return Self::new(
config,
WalletBase::MnemonicAndIndex(mnemonic, position),
height,
);
}
WalletBase::MnemonicPhrase(phrase) => {
return Self::new(
config,
WalletBase::MnemonicPhraseAndIndex(phrase, 0),
height,
);
}
WalletBase::MnemonicPhrase(phrase, position) => {
WalletBase::MnemonicPhraseAndIndex(phrase, position) => {
let mnemonic = Mnemonic::from_phrase(phrase)
.and_then(|m| Mnemonic::from_entropy(m.entropy()))
.map_err(|e| {
Expand All @@ -604,9 +621,16 @@ impl LightWallet {
// should be a no-op, but seems to be needed on android for some reason
// TODO: Test the this cfg actually works
//#[cfg(target_os = "android")]
return Self::new(config, WalletBase::Mnemonic(mnemonic, position), height);
return Self::new(
config,
WalletBase::MnemonicAndIndex(mnemonic, position),
height,
);
}
WalletBase::Mnemonic(mnemonic) => {
return Self::new(config, WalletBase::MnemonicAndIndex(mnemonic, 0), height);
}
WalletBase::Mnemonic(mnemonic, position) => {
WalletBase::MnemonicAndIndex(mnemonic, position) => {
let wc = WalletCapability::new_from_phrase(&config, &mnemonic, position)
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
(wc, Some((mnemonic, position)))
Expand Down

0 comments on commit c598735

Please sign in to comment.