From 157c7874f58126774e85cb2c652559fbf03f23da Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 14 Nov 2023 14:42:46 -0600 Subject: [PATCH] bch tweaks --- .../crypto_currency/coins/bitcoincash.dart | 25 ++++++++++++++++--- .../wallet/impl/bitcoincash_wallet.dart | 14 ++++++++--- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/wallets/crypto_currency/coins/bitcoincash.dart b/lib/wallets/crypto_currency/coins/bitcoincash.dart index 3deb24252..60019a106 100644 --- a/lib/wallets/crypto_currency/coins/bitcoincash.dart +++ b/lib/wallets/crypto_currency/coins/bitcoincash.dart @@ -28,6 +28,10 @@ class Bitcoincash extends Bip39HDCurrency { @override int get maxNumberOfIndexesToCheck => 10000000; + @override + // change this to change the number of confirms a tx needs in order to show as confirmed + int get minConfirms => 0; // bch zeroconf + @override List get supportedDerivationPathTypes => [ DerivePathType.bip44, @@ -80,6 +84,23 @@ class Bitcoincash extends Bip39HDCurrency { } } + @override + String addressToScriptHash({required String address}) { + try { + if (bitbox.Address.detectFormat(address) == + bitbox.Address.formatCashAddr && + _validateCashAddr(address)) { + address = bitbox.Address.toLegacyAddress(address); + } + + final addr = coinlib.Address.fromString(address, networkParams); + return Bip39HDCurrency.convertBytesToScriptHash( + addr.program.script.compiled); + } catch (e) { + rethrow; + } + } + @override String constructDerivePath({ required DerivePathType derivePathType, @@ -143,10 +164,6 @@ class Bitcoincash extends Bip39HDCurrency { } } - @override - // change this to change the number of confirms a tx needs in order to show as confirmed - int get minConfirms => 0; // bch zeroconf - // TODO: [prio=med] bch p2sh addresses (complaints regarding sending to) @override bool validateAddress(String address) { diff --git a/lib/wallets/wallet/impl/bitcoincash_wallet.dart b/lib/wallets/wallet/impl/bitcoincash_wallet.dart index 8bd3388ce..f2ad44416 100644 --- a/lib/wallets/wallet/impl/bitcoincash_wallet.dart +++ b/lib/wallets/wallet/impl/bitcoincash_wallet.dart @@ -28,9 +28,12 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumX { [ ...standardChangeAddressFilters, FilterGroup.not( - const FilterCondition.startsWith( + const ObjectFilter( property: "derivationPath", - value: "m/44'/0'", + filter: FilterCondition.startsWith( + property: "value", + value: "m/44'/0'", + ), ), ), ], @@ -41,9 +44,12 @@ class BitcoincashWallet extends Bip39HDWallet with ElectrumX { [ ...standardReceivingAddressFilters, FilterGroup.not( - const FilterCondition.startsWith( + const ObjectFilter( property: "derivationPath", - value: "m/44'/0'", + filter: FilterCondition.startsWith( + property: "value", + value: "m/44'/0'", + ), ), ), ],