Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions lib/pages/receive_view/receive_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import '../../wallets/isar/providers/wallet_info_provider.dart';
import '../../wallets/wallet/impl/bitcoin_wallet.dart';
import '../../wallets/wallet/intermediate/bip39_hd_wallet.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/bcash_interface.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/multi_address_interface.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
import '../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart';
Expand Down Expand Up @@ -109,11 +110,29 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {

final Address? address;
if (wallet is Bip39HDWallet && wallet is! BCashInterface) {
final type = DerivePathType.values.firstWhere(
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
);
DerivePathType? type;
if (wallet.isViewOnly && wallet is ExtendedKeysInterface) {
final voData = await wallet.getViewOnlyWalletData()
as ExtendedKeysViewOnlyWalletData;
for (final t in wallet.cryptoCurrency.supportedDerivationPathTypes) {
final testPath = wallet.cryptoCurrency.constructDerivePath(
derivePathType: t,
chain: 0,
index: 0,
);
if (testPath.startsWith(voData.xPubs.first.path)) {
type = t;
break;
}
}
} else {
type = DerivePathType.values.firstWhere(
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
);
}

address = await wallet.generateNextReceivingAddress(
derivePathType: type,
derivePathType: type!,
);
final isar = ref.read(mainDBProvider).isar;
await isar.writeTxn(() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import '../../../../wallets/isar/providers/wallet_info_provider.dart';
import '../../../../wallets/wallet/impl/bitcoin_wallet.dart';
import '../../../../wallets/wallet/intermediate/bip39_hd_wallet.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/bcash_interface.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/extended_keys_interface.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/multi_address_interface.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
import '../../../../wallets/wallet/wallet_mixin_interfaces/view_only_option_interface.dart';
Expand Down Expand Up @@ -106,11 +107,28 @@ class _DesktopReceiveState extends ConsumerState<DesktopReceive> {

final Address? address;
if (wallet is Bip39HDWallet && wallet is! BCashInterface) {
final type = DerivePathType.values.firstWhere(
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
);
DerivePathType? type;
if (wallet.isViewOnly && wallet is ExtendedKeysInterface) {
final voData = await wallet.getViewOnlyWalletData()
as ExtendedKeysViewOnlyWalletData;
for (final t in wallet.cryptoCurrency.supportedDerivationPathTypes) {
final testPath = wallet.cryptoCurrency.constructDerivePath(
derivePathType: t,
chain: 0,
index: 0,
);
if (testPath.startsWith(voData.xPubs.first.path)) {
type = t;
break;
}
}
} else {
type = DerivePathType.values.firstWhere(
(e) => e.getAddressType() == _walletAddressTypes[_currentIndex],
);
}
address = await wallet.generateNextReceivingAddress(
derivePathType: type,
derivePathType: type!,
);
final isar = ref.read(mainDBProvider).isar;
await isar.writeTxn(() async {
Expand Down
28 changes: 28 additions & 0 deletions lib/wallets/wallet/intermediate/bip39_hd_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ abstract class Bip39HDWallet<T extends Bip39HDCurrency> extends Bip39Wallet<T>
return address;
}

@override
List<FilterOperation> get standardReceivingAddressFilters => [
// view only only have a single derivation path currently
if (!isViewOnly)
FilterCondition.equalTo(
property: r"type",
value: info.mainAddressType,
),
const FilterCondition.equalTo(
property: r"subType",
value: AddressSubType.receiving,
),
];

@override
List<FilterOperation> get standardChangeAddressFilters => [
// view only only have a single derivation path currently
if (!isViewOnly)
FilterCondition.equalTo(
property: r"type",
value: info.mainAddressType,
),
const FilterCondition.equalTo(
property: r"subType",
value: AddressSubType.change,
),
];

/// Generates a receiving address. If none
/// are in the current wallet db it will generate at index 0, otherwise the
/// highest index found in the current wallet db.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@ import 'electrumx_interface.dart';
abstract class XKey {
XKey({required this.path});
final String path;

@override
String toString() => "Path: $path";
}

class XPub extends XKey {
XPub({required super.path, required this.encoded});
final String encoded;

@override
String toString() => "XPub { path: $path, encoded: $encoded }";
}

class XPriv extends XKey {
XPriv({required super.path, required this.encoded});
final String encoded;

@override
String toString() => "XPriv { path: $path, encoded: $encoded }";
}

mixin ExtendedKeysInterface<T extends ElectrumXCurrencyInterface>
Expand Down
Loading