From 57ebacd51988dde9ecbc5acb6753f291c9bfe35d Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 20 Jun 2024 10:16:12 -0600 Subject: [PATCH] fix issue where changing the primary/default address type for a coin would break older wallets with a mismatching type --- lib/db/migrate_wallets_to_isar.dart | 2 +- lib/pages/receive_view/receive_view.dart | 4 +- .../helpers/restore_create_backup.dart | 2 +- lib/wallets/crypto_currency/coins/banano.dart | 4 +- .../crypto_currency/coins/bitcoin.dart | 4 +- .../crypto_currency/coins/bitcoin_frost.dart | 4 +- .../crypto_currency/coins/bitcoincash.dart | 4 +- .../crypto_currency/coins/dogecoin.dart | 4 +- lib/wallets/crypto_currency/coins/ecash.dart | 4 +- .../crypto_currency/coins/epiccash.dart | 5 ++- .../crypto_currency/coins/ethereum.dart | 5 ++- lib/wallets/crypto_currency/coins/firo.dart | 4 +- .../crypto_currency/coins/litecoin.dart | 4 +- lib/wallets/crypto_currency/coins/monero.dart | 2 +- .../crypto_currency/coins/namecoin.dart | 4 +- lib/wallets/crypto_currency/coins/nano.dart | 4 +- .../crypto_currency/coins/particl.dart | 4 +- .../crypto_currency/coins/peercoin.dart | 4 +- lib/wallets/crypto_currency/coins/solana.dart | 4 +- .../crypto_currency/coins/stellar.dart | 4 +- lib/wallets/crypto_currency/coins/tezos.dart | 4 +- .../crypto_currency/coins/wownero.dart | 2 +- .../crypto_currency/crypto_currency.dart | 4 +- .../intermediate/cryptonote_currency.dart | 2 +- lib/wallets/isar/models/wallet_info.dart | 2 +- lib/wallets/wallet/impl/solana_wallet.dart | 2 +- lib/wallets/wallet/impl/tezos_wallet.dart | 7 ++-- .../wallet/intermediate/bip39_hd_wallet.dart | 40 +++++++++++++++++-- .../nano_interface.dart | 4 +- 29 files changed, 89 insertions(+), 54 deletions(-) diff --git a/lib/db/migrate_wallets_to_isar.dart b/lib/db/migrate_wallets_to_isar.dart index 11ae18e0a..cd54a4063 100644 --- a/lib/db/migrate_wallets_to_isar.dart +++ b/lib/db/migrate_wallets_to_isar.dart @@ -171,7 +171,7 @@ Future migrateWalletsToIsar({ walletId: old.walletId, name: old.name, mainAddressType: AppConfig.getCryptoCurrencyFor(old.coinIdentifier)! - .primaryAddressType, + .defaultAddressType, favouriteOrderIndex: favourites.indexOf(old.walletId), cachedChainHeight: walletBox.get( DBKeys.storedChainHeight, diff --git a/lib/pages/receive_view/receive_view.dart b/lib/pages/receive_view/receive_view.dart index 844950949..2be05937f 100644 --- a/lib/pages/receive_view/receive_view.dart +++ b/lib/pages/receive_view/receive_view.dart @@ -188,7 +188,7 @@ class _ReceiveViewState extends ConsumerState { wallet is Bip39HDWallet && wallet.supportedAddressTypes.length > 1); - _walletAddressTypes.add(coin.primaryAddressType); + _walletAddressTypes.add(wallet.info.mainAddressType); if (_showMultiType) { if (_supportsSpark) { @@ -197,7 +197,7 @@ class _ReceiveViewState extends ConsumerState { _walletAddressTypes.addAll( (wallet as Bip39HDWallet) .supportedAddressTypes - .where((e) => e != coin.primaryAddressType), + .where((e) => e != wallet.info.mainAddressType), ); } } diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/restore_create_backup.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/restore_create_backup.dart index 8a635e39a..3dcdd45d5 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/restore_create_backup.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/helpers/restore_create_backup.dart @@ -814,7 +814,7 @@ abstract class SWB { coinName: coin.identifier, walletId: walletId, name: walletName, - mainAddressType: coin.primaryAddressType, + mainAddressType: coin.defaultAddressType, restoreHeight: walletbackup['restoreHeight'] as int? ?? 0, otherDataJsonString: otherData == null ? null : jsonEncode(otherData), cachedChainHeight: walletbackup['storedChainHeight'] as int? ?? 0, diff --git a/lib/wallets/crypto_currency/coins/banano.dart b/lib/wallets/crypto_currency/coins/banano.dart index c372e760a..4bb5184d2 100644 --- a/lib/wallets/crypto_currency/coins/banano.dart +++ b/lib/wallets/crypto_currency/coins/banano.dart @@ -53,7 +53,7 @@ class Banano extends NanoCurrency { int get minConfirms => 1; @override - AddressType get primaryAddressType => AddressType.banano; + AddressType get defaultAddressType => AddressType.banano; @override String get defaultRepresentative => @@ -97,7 +97,7 @@ class Banano extends NanoCurrency { } @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); } diff --git a/lib/wallets/crypto_currency/coins/bitcoin.dart b/lib/wallets/crypto_currency/coins/bitcoin.dart index 88943d0ea..3b75e2186 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin.dart @@ -288,7 +288,7 @@ class Bitcoin extends Bip39HDCurrency List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2tr; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -297,7 +297,7 @@ class Bitcoin extends Bip39HDCurrency int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip86; + DerivePathType get defaultDerivePathType => DerivePathType.bip86; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/bitcoin_frost.dart b/lib/wallets/crypto_currency/coins/bitcoin_frost.dart index c5e0049b7..f09d1865e 100644 --- a/lib/wallets/crypto_currency/coins/bitcoin_frost.dart +++ b/lib/wallets/crypto_currency/coins/bitcoin_frost.dart @@ -195,7 +195,7 @@ class BitcoinFrost extends FrostCurrency { List get possibleMnemonicLengths => []; @override - AddressType get primaryAddressType => AddressType.frostMS; + AddressType get defaultAddressType => AddressType.frostMS; @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -204,7 +204,7 @@ class BitcoinFrost extends FrostCurrency { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/coins/bitcoincash.dart b/lib/wallets/crypto_currency/coins/bitcoincash.dart index c0014039d..5950fc913 100644 --- a/lib/wallets/crypto_currency/coins/bitcoincash.dart +++ b/lib/wallets/crypto_currency/coins/bitcoincash.dart @@ -336,7 +336,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2pkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -345,7 +345,7 @@ class Bitcoincash extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip44; + DerivePathType get defaultDerivePathType => DerivePathType.bip44; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/dogecoin.dart b/lib/wallets/crypto_currency/coins/dogecoin.dart index 461d70d95..1de949edc 100644 --- a/lib/wallets/crypto_currency/coins/dogecoin.dart +++ b/lib/wallets/crypto_currency/coins/dogecoin.dart @@ -225,7 +225,7 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2pkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -234,7 +234,7 @@ class Dogecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 60; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip44; + DerivePathType get defaultDerivePathType => DerivePathType.bip44; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/ecash.dart b/lib/wallets/crypto_currency/coins/ecash.dart index 533ed3747..102f509c8 100644 --- a/lib/wallets/crypto_currency/coins/ecash.dart +++ b/lib/wallets/crypto_currency/coins/ecash.dart @@ -314,7 +314,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2pkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100); @@ -323,7 +323,7 @@ class Ecash extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.eCash44; + DerivePathType get defaultDerivePathType => DerivePathType.eCash44; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/epiccash.dart b/lib/wallets/crypto_currency/coins/epiccash.dart index f90832473..6e47eb411 100644 --- a/lib/wallets/crypto_currency/coins/epiccash.dart +++ b/lib/wallets/crypto_currency/coins/epiccash.dart @@ -1,4 +1,5 @@ import 'package:flutter_libepiccash/lib.dart' as epic; + import '../../../models/isar/models/blockchain_data/address.dart'; import '../../../models/node_model.dart'; import '../../../utilities/default_nodes.dart'; @@ -102,7 +103,7 @@ class Epiccash extends Bip39Currency { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 12]; @override - AddressType get primaryAddressType => AddressType.mimbleWimble; + AddressType get defaultAddressType => AddressType.mimbleWimble; @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -111,7 +112,7 @@ class Epiccash extends Bip39Currency { int get targetBlockTimeSeconds => 60; @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/coins/ethereum.dart b/lib/wallets/crypto_currency/coins/ethereum.dart index eb20d05e3..5c0f5b06d 100644 --- a/lib/wallets/crypto_currency/coins/ethereum.dart +++ b/lib/wallets/crypto_currency/coins/ethereum.dart @@ -1,4 +1,5 @@ import 'package:ethereum_addresses/ethereum_addresses.dart'; + import '../../../models/isar/models/blockchain_data/address.dart'; import '../../../models/node_model.dart'; import '../../../utilities/default_nodes.dart'; @@ -86,7 +87,7 @@ class Ethereum extends Bip39Currency { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.ethereum; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(1000000000000000000); @@ -95,7 +96,7 @@ class Ethereum extends Bip39Currency { int get targetBlockTimeSeconds => 15; @override - DerivePathType get primaryDerivePathType => DerivePathType.eth; + DerivePathType get defaultDerivePathType => DerivePathType.eth; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/firo.dart b/lib/wallets/crypto_currency/coins/firo.dart index ae73f13b7..cf36840c7 100644 --- a/lib/wallets/crypto_currency/coins/firo.dart +++ b/lib/wallets/crypto_currency/coins/firo.dart @@ -243,7 +243,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2pkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -252,7 +252,7 @@ class Firo extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 150; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip44; + DerivePathType get defaultDerivePathType => DerivePathType.bip44; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/litecoin.dart b/lib/wallets/crypto_currency/coins/litecoin.dart index 7cf53837a..1c09a0c2a 100644 --- a/lib/wallets/crypto_currency/coins/litecoin.dart +++ b/lib/wallets/crypto_currency/coins/litecoin.dart @@ -256,7 +256,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2wpkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -265,7 +265,7 @@ class Litecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 150; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip84; + DerivePathType get defaultDerivePathType => DerivePathType.bip84; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/monero.dart b/lib/wallets/crypto_currency/coins/monero.dart index e0712d845..edd389ec3 100644 --- a/lib/wallets/crypto_currency/coins/monero.dart +++ b/lib/wallets/crypto_currency/coins/monero.dart @@ -100,7 +100,7 @@ class Monero extends CryptonoteCurrency { int get targetBlockTimeSeconds => 120; @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/coins/namecoin.dart b/lib/wallets/crypto_currency/coins/namecoin.dart index bae72281f..9f0134b9a 100644 --- a/lib/wallets/crypto_currency/coins/namecoin.dart +++ b/lib/wallets/crypto_currency/coins/namecoin.dart @@ -230,7 +230,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 12]; @override - AddressType get primaryAddressType => AddressType.p2wpkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -239,7 +239,7 @@ class Namecoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip84; + DerivePathType get defaultDerivePathType => DerivePathType.bip84; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/nano.dart b/lib/wallets/crypto_currency/coins/nano.dart index b11e68192..32f49cbec 100644 --- a/lib/wallets/crypto_currency/coins/nano.dart +++ b/lib/wallets/crypto_currency/coins/nano.dart @@ -53,7 +53,7 @@ class Nano extends NanoCurrency { int get minConfirms => 1; @override - AddressType get primaryAddressType => AddressType.nano; + AddressType get defaultAddressType => AddressType.nano; @override String get defaultRepresentative => @@ -85,7 +85,7 @@ class Nano extends NanoCurrency { } @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/coins/particl.dart b/lib/wallets/crypto_currency/coins/particl.dart index fd1aa946f..e83eaf4ed 100644 --- a/lib/wallets/crypto_currency/coins/particl.dart +++ b/lib/wallets/crypto_currency/coins/particl.dart @@ -208,7 +208,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2wpkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(100000000); @@ -217,7 +217,7 @@ class Particl extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip84; + DerivePathType get defaultDerivePathType => DerivePathType.bip84; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/peercoin.dart b/lib/wallets/crypto_currency/coins/peercoin.dart index a199460e7..ba291cc14 100644 --- a/lib/wallets/crypto_currency/coins/peercoin.dart +++ b/lib/wallets/crypto_currency/coins/peercoin.dart @@ -228,7 +228,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.p2wpkh; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(1000000); // 1*10^6. @@ -237,7 +237,7 @@ class Peercoin extends Bip39HDCurrency with ElectrumXCurrencyInterface { int get targetBlockTimeSeconds => 600; @override - DerivePathType get primaryDerivePathType => DerivePathType.bip84; + DerivePathType get defaultDerivePathType => DerivePathType.bip84; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/solana.dart b/lib/wallets/crypto_currency/coins/solana.dart index 7ae69ed43..1505abead 100644 --- a/lib/wallets/crypto_currency/coins/solana.dart +++ b/lib/wallets/crypto_currency/coins/solana.dart @@ -94,7 +94,7 @@ class Solana extends Bip39Currency { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 24]; @override - AddressType get primaryAddressType => AddressType.solana; + AddressType get defaultAddressType => defaultDerivePathType.getAddressType(); @override BigInt get satsPerCoin => BigInt.from(1000000000); @@ -103,7 +103,7 @@ class Solana extends Bip39Currency { int get targetBlockTimeSeconds => 1; @override - DerivePathType get primaryDerivePathType => DerivePathType.solana; + DerivePathType get defaultDerivePathType => DerivePathType.solana; @override Uri defaultBlockExplorer(String txid) { diff --git a/lib/wallets/crypto_currency/coins/stellar.dart b/lib/wallets/crypto_currency/coins/stellar.dart index e9749c515..f0606f1f0 100644 --- a/lib/wallets/crypto_currency/coins/stellar.dart +++ b/lib/wallets/crypto_currency/coins/stellar.dart @@ -108,7 +108,7 @@ class Stellar extends Bip39Currency { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 12]; @override - AddressType get primaryAddressType => AddressType.stellar; + AddressType get defaultAddressType => AddressType.stellar; @override BigInt get satsPerCoin => BigInt.from( @@ -119,7 +119,7 @@ class Stellar extends Bip39Currency { int get targetBlockTimeSeconds => 5; @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/coins/tezos.dart b/lib/wallets/crypto_currency/coins/tezos.dart index 96f2acc0d..e99831ca5 100644 --- a/lib/wallets/crypto_currency/coins/tezos.dart +++ b/lib/wallets/crypto_currency/coins/tezos.dart @@ -195,7 +195,7 @@ class Tezos extends Bip39Currency { List get possibleMnemonicLengths => [defaultSeedPhraseLength, 12]; @override - AddressType get primaryAddressType => AddressType.tezos; + AddressType get defaultAddressType => AddressType.tezos; @override BigInt get satsPerCoin => BigInt.from(1000000); @@ -204,7 +204,7 @@ class Tezos extends Bip39Currency { int get targetBlockTimeSeconds => 60; @override - DerivePathType get primaryDerivePathType => + DerivePathType get defaultDerivePathType => throw UnsupportedError("Is this even used?"); @override diff --git a/lib/wallets/crypto_currency/coins/wownero.dart b/lib/wallets/crypto_currency/coins/wownero.dart index dd1af1d7d..8624ecb75 100644 --- a/lib/wallets/crypto_currency/coins/wownero.dart +++ b/lib/wallets/crypto_currency/coins/wownero.dart @@ -95,7 +95,7 @@ class Wownero extends CryptonoteCurrency { int get targetBlockTimeSeconds => 120; @override - DerivePathType get primaryDerivePathType => throw UnsupportedError( + DerivePathType get defaultDerivePathType => throw UnsupportedError( "$runtimeType does not use bitcoin style derivation paths", ); diff --git a/lib/wallets/crypto_currency/crypto_currency.dart b/lib/wallets/crypto_currency/crypto_currency.dart index 5ea51e557..a498aa53d 100644 --- a/lib/wallets/crypto_currency/crypto_currency.dart +++ b/lib/wallets/crypto_currency/crypto_currency.dart @@ -71,10 +71,10 @@ abstract class CryptoCurrency { bool get hasBuySupport; bool get hasMnemonicPassphraseSupport; List get possibleMnemonicLengths; - AddressType get primaryAddressType; + AddressType get defaultAddressType; BigInt get satsPerCoin; int get targetBlockTimeSeconds; - DerivePathType get primaryDerivePathType; + DerivePathType get defaultDerivePathType; Uri defaultBlockExplorer(String txid); diff --git a/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart b/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart index b7bf7c645..496336235 100644 --- a/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart +++ b/lib/wallets/crypto_currency/intermediate/cryptonote_currency.dart @@ -10,5 +10,5 @@ abstract class CryptonoteCurrency extends CryptoCurrency { } @override - AddressType get primaryAddressType => AddressType.cryptonote; + AddressType get defaultAddressType => AddressType.cryptonote; } diff --git a/lib/wallets/isar/models/wallet_info.dart b/lib/wallets/isar/models/wallet_info.dart index 21ab499f0..6f6e12a42 100644 --- a/lib/wallets/isar/models/wallet_info.dart +++ b/lib/wallets/isar/models/wallet_info.dart @@ -458,7 +458,7 @@ class WalletInfo implements IsarId { coinName: coin.identifier, walletId: walletIdOverride ?? const Uuid().v1(), name: name, - mainAddressType: coin.primaryAddressType, + mainAddressType: coin.defaultAddressType, restoreHeight: restoreHeight, otherDataJsonString: otherDataJsonString, ); diff --git a/lib/wallets/wallet/impl/solana_wallet.dart b/lib/wallets/wallet/impl/solana_wallet.dart index 55ecafade..50ff0b31a 100644 --- a/lib/wallets/wallet/impl/solana_wallet.dart +++ b/lib/wallets/wallet/impl/solana_wallet.dart @@ -46,7 +46,7 @@ class SolanaWallet extends Bip39Wallet { publicKey: List.empty(), derivationIndex: 0, derivationPath: DerivationPath()..value = _addressDerivationPath, - type: cryptoCurrency.primaryAddressType, + type: info.mainAddressType, subType: AddressSubType.receiving, ); return addressStruct; diff --git a/lib/wallets/wallet/impl/tezos_wallet.dart b/lib/wallets/wallet/impl/tezos_wallet.dart index f4c8c0ebe..a1728c10a 100644 --- a/lib/wallets/wallet/impl/tezos_wallet.dart +++ b/lib/wallets/wallet/impl/tezos_wallet.dart @@ -1,6 +1,9 @@ import 'dart:io'; import 'package:isar/isar.dart'; +import 'package:tezart/tezart.dart' as tezart; +import 'package:tuple/tuple.dart'; + import '../../../models/balance.dart'; import '../../../models/isar/models/blockchain_data/address.dart'; import '../../../models/isar/models/blockchain_data/transaction.dart'; @@ -18,8 +21,6 @@ import '../../crypto_currency/crypto_currency.dart'; import '../../isar/models/wallet_info.dart'; import '../../models/tx_data.dart'; import '../intermediate/bip39_wallet.dart'; -import 'package:tezart/tezart.dart' as tezart; -import 'package:tuple/tuple.dart'; // const kDefaultTransactionStorageLimit = 496; // const kDefaultTransactionGasLimit = 10600; @@ -83,7 +84,7 @@ class TezosWallet extends Bip39Wallet { publicKey: keyStore.publicKey.toUint8ListFromBase58CheckEncoded, derivationIndex: 0, derivationPath: DerivationPath()..value = derivationPath, - type: info.coin.primaryAddressType, + type: info.mainAddressType, subType: AddressSubType.receiving, ); } diff --git a/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart b/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart index c276d758a..6d87b7ace 100644 --- a/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart +++ b/lib/wallets/wallet/intermediate/bip39_hd_wallet.dart @@ -1,13 +1,14 @@ import 'package:bip39/bip39.dart' as bip39; import 'package:coinlib_flutter/coinlib_flutter.dart' as coinlib; import 'package:isar/isar.dart'; + import '../../../models/balance.dart'; import '../../../models/isar/models/blockchain_data/address.dart'; import '../../../utilities/amount/amount.dart'; import '../../../utilities/enums/derive_path_type_enum.dart'; import '../../crypto_currency/intermediate/bip39_hd_currency.dart'; -import 'bip39_wallet.dart'; import '../wallet_mixin_interfaces/multi_address_interface.dart'; +import 'bip39_wallet.dart'; abstract class Bip39HDWallet extends Bip39Wallet with MultiAddressInterface { @@ -66,7 +67,7 @@ abstract class Bip39HDWallet extends Bip39Wallet final address = await _generateAddress( chain: chain, index: index, - derivePathType: info.coin.primaryDerivePathType, + derivePathType: _fromAddressType(info.mainAddressType), ); await mainDB.updateOrPutAddresses([address]); @@ -88,7 +89,7 @@ abstract class Bip39HDWallet extends Bip39Wallet final address = await _generateAddress( chain: chain, index: index, - derivePathType: info.coin.primaryDerivePathType, + derivePathType: _fromAddressType(info.mainAddressType), ); await mainDB.updateOrPutAddresses([address]); @@ -101,7 +102,7 @@ abstract class Bip39HDWallet extends Bip39Wallet final address = await _generateAddress( chain: 0, // receiving index: 0, // initial index - derivePathType: info.coin.primaryDerivePathType, + derivePathType: _fromAddressType(info.mainAddressType), ); await mainDB.updateOrPutAddresses([address]); @@ -118,6 +119,37 @@ abstract class Bip39HDWallet extends Bip39Wallet // ========== Private ======================================================== + DerivePathType _fromAddressType(AddressType addressType) { + switch (addressType) { + case AddressType.p2pkh: + // DerivePathType.bip44: + // DerivePathType.bch44: + // DerivePathType.eCash44: + // Should be one of the above due to silly case due to bch and ecash + return info.coin.defaultDerivePathType; + + case AddressType.p2sh: + return DerivePathType.bip49; + + case AddressType.p2wpkh: + return DerivePathType.bip84; + + case AddressType.p2tr: + return DerivePathType.bip86; + + case AddressType.solana: + return DerivePathType.solana; + + case AddressType.ethereum: + return DerivePathType.eth; + + default: + throw ArgumentError( + "Incompatible AddressType \"$addressType\" passed to DerivePathType.fromAddressType()", + ); + } + } + Future
_generateAddress({ required int chain, required int index, diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/nano_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/nano_interface.dart index 120f964ef..39d16497e 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/nano_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/nano_interface.dart @@ -93,7 +93,7 @@ mixin NanoInterface on Bip39Wallet { publicKey: publicKey.toUint8ListFromHex, derivationIndex: 0, derivationPath: null, - type: cryptoCurrency.primaryAddressType, + type: info.mainAddressType, subType: AddressSubType.receiving, ); } @@ -599,7 +599,7 @@ mixin NanoInterface on Bip39Wallet { value: tx["account"].toString(), derivationIndex: 0, derivationPath: null, - type: info.coin.primaryAddressType, + type: info.mainAddressType, subType: AddressSubType.nonWallet, ); final Tuple2 tuple = Tuple2(transaction, address);