From 745abe0f1043ab2b4ee003586be399eea120b4c2 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 30 Nov 2022 09:22:58 -0600 Subject: [PATCH] do not check server features on wallet creation (allow offline new wallet creation) --- .../coins/bitcoin/bitcoin_wallet.dart | 42 +++++++-------- .../coins/bitcoincash/bitcoincash_wallet.dart | 42 +++++++-------- .../coins/dogecoin/dogecoin_wallet.dart | 42 +++++++-------- lib/services/coins/firo/firo_wallet.dart | 51 ++++++++----------- .../coins/litecoin/litecoin_wallet.dart | 44 ++++++++-------- .../coins/namecoin/namecoin_wallet.dart | 41 ++++++--------- 6 files changed, 122 insertions(+), 140 deletions(-) diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 25ec6b519..fae55e7b5 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -1516,27 +1516,27 @@ class BitcoinWallet extends CoinServiceAPI { } Future _generateNewWallet() async { - Logging.instance - .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.bitcoin: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - throw Exception("genesis hash does not match main net!"); - } - break; - case Coin.bitcoinTestNet: - if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - throw Exception("genesis hash does not match test net!"); - } - break; - default: - throw Exception( - "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); - } - } + // Logging.instance + // .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.bitcoin: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // case Coin.bitcoinTestNet: + // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + // throw Exception("genesis hash does not match test net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); + // } + // } // this should never fail if ((await _secureStore.read(key: '${_walletId}_mnemonic')) != null) { diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 59b2454b4..e3e93e28c 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -1402,27 +1402,27 @@ class BitcoinCashWallet extends CoinServiceAPI { } Future _generateNewWallet() async { - Logging.instance - .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.bitcoincash: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - throw Exception("genesis hash does not match main net!"); - } - break; - case Coin.bitcoincashTestnet: - if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - throw Exception("genesis hash does not match test net!"); - } - break; - default: - throw Exception( - "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); - } - } + // Logging.instance + // .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.bitcoincash: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // case Coin.bitcoincashTestnet: + // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + // throw Exception("genesis hash does not match test net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); + // } + // } // this should never fail if ((await _secureStore.read(key: '${_walletId}_mnemonic')) != null) { diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index f7372752b..11cee6f1b 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -1265,27 +1265,27 @@ class DogecoinWallet extends CoinServiceAPI { } Future _generateNewWallet() async { - Logging.instance - .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.dogecoin: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - throw Exception("genesis hash does not match main net!"); - } - break; - case Coin.dogecoinTestNet: - if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - throw Exception("genesis hash does not match test net!"); - } - break; - default: - throw Exception( - "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); - } - } + // Logging.instance + // .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.dogecoin: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // case Coin.dogecoinTestNet: + // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + // throw Exception("genesis hash does not match test net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a BitcoinWallet using a non bitcoin coin type: ${coin.name}"); + // } + // } // this should never fail if ((await _secureStore.read(key: '${_walletId}_mnemonic')) != null) { diff --git a/lib/services/coins/firo/firo_wallet.dart b/lib/services/coins/firo/firo_wallet.dart index 3e0cba75d..37fa07166 100644 --- a/lib/services/coins/firo/firo_wallet.dart +++ b/lib/services/coins/firo/firo_wallet.dart @@ -2145,36 +2145,27 @@ class FiroWallet extends CoinServiceAPI { /// Generates initial wallet values such as mnemonic, chain (receive/change) arrays and indexes. Future _generateNewWallet() async { - Logging.instance - .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.firo: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - throw Exception("genesis hash does not match main net!"); - } - break; - case Coin.firoTestNet: - if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - throw Exception("genesis hash does not match test net!"); - } - break; - default: - throw Exception( - "Attempted to generate a FiroWallet using a non firo coin type: ${coin.name}"); - } - // if (_networkType == BasicNetworkType.main) { - // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - // throw Exception("genesis hash does not match!"); - // } - // } else if (_networkType == BasicNetworkType.test) { - // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - // throw Exception("genesis hash does not match!"); - // } - // } - } + // Logging.instance + // .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.firo: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // case Coin.firoTestNet: + // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + // throw Exception("genesis hash does not match test net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a FiroWallet using a non firo coin type: ${coin.name}"); + // } + // } // this should never fail as overwriting a mnemonic is big bad assert((await _secureStore.read(key: '${_walletId}_mnemonic')) == null); diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index 9c4bb2305..429a443d1 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -1518,28 +1518,28 @@ class LitecoinWallet extends CoinServiceAPI { } Future _generateNewWallet() async { - Logging.instance - .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.litecoin: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - print(features['genesis_hash']); - throw Exception("genesis hash does not match main net!"); - } - break; - case Coin.litecoinTestNet: - if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - throw Exception("genesis hash does not match test net!"); - } - break; - default: - throw Exception( - "Attempted to generate a LitecoinWallet using a non litecoin coin type: ${coin.name}"); - } - } + // Logging.instance + // .log("IS_INTEGRATION_TEST: $integrationTestFlag", level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.litecoin: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // print(features['genesis_hash']); + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // case Coin.litecoinTestNet: + // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { + // throw Exception("genesis hash does not match test net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a LitecoinWallet using a non litecoin coin type: ${coin.name}"); + // } + // } // this should never fail if ((await _secureStore.read(key: '${_walletId}_mnemonic')) != null) { diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 142bfb379..ebc702a39 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -341,31 +341,22 @@ class NamecoinWallet extends CoinServiceAPI { longMutex = true; final start = DateTime.now(); try { - Logging.instance.log("IS_INTEGRATION_TEST: $integrationTestFlag", - level: LogLevel.Info); - if (!integrationTestFlag) { - final features = await electrumXClient.getServerFeatures(); - Logging.instance.log("features: $features", level: LogLevel.Info); - switch (coin) { - case Coin.namecoin: - if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - throw Exception("genesis hash does not match main net!"); - } - break; - default: - throw Exception( - "Attempted to generate a NamecoinWallet using a non namecoin coin type: ${coin.name}"); - } - // if (_networkType == BasicNetworkType.main) { - // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { - // throw Exception("genesis hash does not match main net!"); - // } - // } else if (_networkType == BasicNetworkType.test) { - // if (features['genesis_hash'] != GENESIS_HASH_TESTNET) { - // throw Exception("genesis hash does not match test net!"); - // } - // } - } + // Logging.instance.log("IS_INTEGRATION_TEST: $integrationTestFlag", + // level: LogLevel.Info); + // if (!integrationTestFlag) { + // final features = await electrumXClient.getServerFeatures(); + // Logging.instance.log("features: $features", level: LogLevel.Info); + // switch (coin) { + // case Coin.namecoin: + // if (features['genesis_hash'] != GENESIS_HASH_MAINNET) { + // throw Exception("genesis hash does not match main net!"); + // } + // break; + // default: + // throw Exception( + // "Attempted to generate a NamecoinWallet using a non namecoin coin type: ${coin.name}"); + // } + // } // check to make sure we aren't overwriting a mnemonic // this should never fail if ((await _secureStore.read(key: '${_walletId}_mnemonic')) != null) {