From 6b08acf225b10f5ac71f7784d3d8155d464acec6 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 25 Jan 2023 12:08:48 -0600 Subject: [PATCH] single DerivePathType enum declaration --- lib/services/coins/bitcoin/bitcoin_wallet.dart | 3 +-- .../coins/bitcoincash/bitcoincash_wallet.dart | 14 +++++++++----- lib/services/coins/dogecoin/dogecoin_wallet.dart | 16 ++++++++++------ lib/services/coins/litecoin/litecoin_wallet.dart | 3 +-- lib/services/coins/namecoin/namecoin_wallet.dart | 3 +-- lib/services/coins/particl/particl_wallet.dart | 11 +++++++++-- lib/utilities/enums/derive_path_type_enum.dart | 1 + 7 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 lib/utilities/enums/derive_path_type_enum.dart diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index d0b114829..2194c5a19 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"; -enum DerivePathType { bip44, bip49, bip84 } - bip32.BIP32 getBip32Node( int chain, int index, diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index 70e3a5d55..84f302dec 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -34,6 +34,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"; -enum DerivePathType { bip44, bip49 } - bip32.BIP32 getBip32Node(int chain, int index, String mnemonic, NetworkType network, DerivePathType derivePathType) { final root = getBip32Root(mnemonic, network); @@ -1421,9 +1420,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { .address!; addrType = isar_models.AddressType.p2sh; break; - // default: - // // should never hit this due to all enum cases handled - // return null; + case DerivePathType.bip84: + throw UnsupportedError("bip84 not supported by BCH"); } // add generated address & info to derivations @@ -1466,6 +1464,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip49: type = isar_models.AddressType.p2sh; break; + case DerivePathType.bip84: + throw UnsupportedError("bip84 not supported by BCH"); } final address = await db @@ -1491,6 +1491,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip49: key = "${walletId}_${chainId}DerivationsP2SH"; break; + case DerivePathType.bip84: + throw UnsupportedError("bip84 not supported by BCH"); } return key; } @@ -2611,6 +2613,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip49: addressesP2SH.add(address); break; + case DerivePathType.bip84: + throw UnsupportedError("bip84 not supported by BCH"); } } } diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index c47ad8947..c8cc68f8e 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -34,6 +34,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e"; -enum DerivePathType { bip44 } - bip32.BIP32 getBip32Node(int chain, int index, String mnemonic, NetworkType network, DerivePathType derivePathType) { final root = getBip32Root(mnemonic, network); @@ -90,7 +89,7 @@ bip32.BIP32 getBip32NodeFromRoot( case DerivePathType.bip44: return root.derivePath("m/44'/$coinType'/0'/$chain/$index"); default: - throw Exception("DerivePathType must not be null."); + throw Exception("Unsupported DerivePathType"); } } @@ -1273,9 +1272,8 @@ class DogecoinWallet extends CoinServiceAPI case DerivePathType.bip44: address = P2PKH(data: data, network: network).data.address!; break; - // default: - // // should never hit this due to all enum cases handled - // return null; + default: + throw Exception("Unsupported DerivePathType"); } // add generated address & info to derivations @@ -1320,6 +1318,8 @@ class DogecoinWallet extends CoinServiceAPI .sortByDerivationIndexDesc() .findFirst(); break; + default: + throw Exception("Unsupported DerivePathType"); } return address!.value; } @@ -1332,6 +1332,8 @@ class DogecoinWallet extends CoinServiceAPI case DerivePathType.bip44: key = "${walletId}_${chainId}DerivationsP2PKH"; break; + default: + throw Exception("Unsupported DerivePathType"); } return key; } @@ -2339,6 +2341,8 @@ class DogecoinWallet extends CoinServiceAPI case DerivePathType.bip44: addressesP2PKH.add(address); break; + default: + throw Exception("Unsupported DerivePathType"); } } } diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index fe1fdf13c..aed4182a8 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0"; -enum DerivePathType { bip44, bip49, bip84 } - bip32.BIP32 getBip32Node( int chain, int index, diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index cae6cf29a..2805f5412 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"; -enum DerivePathType { bip44, bip49, bip84 } - bip32.BIP32 getBip32Node( int chain, int index, diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index d19fdf769..22b90d05f 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -32,6 +32,7 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; +import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/format.dart'; @@ -48,8 +49,6 @@ const String GENESIS_HASH_MAINNET = const String GENESIS_HASH_TESTNET = "0000594ada5310b367443ee0afd4fa3d0bbd5850ea4e33cdc7d6a904a7ec7c90"; -enum DerivePathType { bip44, bip84 } - bip32.BIP32 getBip32Node( int chain, int index, @@ -1407,6 +1406,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { address = P2WPKH(network: _network, data: data).data.address!; addrType = isar_models.AddressType.p2wpkh; break; + default: + throw Exception("Unsupported DerivePathType"); } // add generated address & info to derivations @@ -1450,6 +1451,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip84: type = isar_models.AddressType.p2wpkh; break; + default: + throw Exception("Unsupported DerivePathType"); } address = await db .getAddresses(walletId) @@ -1475,6 +1478,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip84: key = "${walletId}_${chainId}DerivationsP2WPKH"; break; + default: + throw Exception("Unsupported DerivePathType"); } return key; } @@ -2743,6 +2748,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { case DerivePathType.bip84: addressesP2WPKH.add(address); break; + default: + throw Exception("Unsupported DerivePathType"); } } } diff --git a/lib/utilities/enums/derive_path_type_enum.dart b/lib/utilities/enums/derive_path_type_enum.dart new file mode 100644 index 000000000..694b9158f --- /dev/null +++ b/lib/utilities/enums/derive_path_type_enum.dart @@ -0,0 +1 @@ +enum DerivePathType { bip44, bip49, bip84 }