Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
2024-11-04 22:29:25 +00:00
|
|
|
import 'package:blockchain_utils/blockchain_utils.dart';
|
2024-11-07 16:01:32 +00:00
|
|
|
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
2021-12-24 12:52:08 +00:00
|
|
|
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
|
|
|
|
part 'bitcoin_wallet_addresses.g.dart';
|
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
class BitcoinWalletAddresses = BitcoinWalletAddressesBase with _$BitcoinWalletAddresses;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2023-10-12 22:50:16 +00:00
|
|
|
abstract class BitcoinWalletAddressesBase extends ElectrumWalletAddresses with Store {
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
BitcoinWalletAddressesBase(
|
|
|
|
WalletInfo walletInfo, {
|
|
|
|
required super.network,
|
2024-10-23 15:38:31 +00:00
|
|
|
required super.isHardwareWallet,
|
2024-11-04 22:29:25 +00:00
|
|
|
required super.hdWallets,
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
super.initialAddresses,
|
2024-11-07 16:01:32 +00:00
|
|
|
List<BitcoinSilentPaymentAddressRecord>? initialSilentAddresses,
|
|
|
|
List<BitcoinReceivedSPAddressRecord>? initialReceivedSPAddresses,
|
|
|
|
}) : silentPaymentAddresses = ObservableList<BitcoinSilentPaymentAddressRecord>.of(
|
|
|
|
(initialSilentAddresses ?? []).toSet(),
|
|
|
|
),
|
|
|
|
receivedSPAddresses = ObservableList<BitcoinReceivedSPAddressRecord>.of(
|
|
|
|
(initialReceivedSPAddresses ?? []).toSet(),
|
|
|
|
),
|
|
|
|
super(walletInfo) {
|
|
|
|
silentPaymentWallet = SilentPaymentOwner.fromBip32(hdWallet);
|
2024-11-16 17:53:00 +00:00
|
|
|
silentPaymentWallets = [silentPaymentWallet!];
|
2024-11-07 16:01:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
2024-11-16 17:53:00 +00:00
|
|
|
SilentPaymentOwner? silentPaymentWallet;
|
2024-11-07 16:01:32 +00:00
|
|
|
final ObservableList<BitcoinSilentPaymentAddressRecord> silentPaymentAddresses;
|
|
|
|
final ObservableList<BitcoinReceivedSPAddressRecord> receivedSPAddresses;
|
|
|
|
|
2024-11-16 17:53:00 +00:00
|
|
|
@observable
|
|
|
|
List<SilentPaymentOwner> silentPaymentWallets = [];
|
|
|
|
|
2024-11-07 16:01:32 +00:00
|
|
|
@observable
|
|
|
|
String? activeSilentAddress;
|
2021-12-24 12:52:08 +00:00
|
|
|
|
2024-10-29 23:52:19 +00:00
|
|
|
@override
|
|
|
|
Future<void> init() async {
|
2024-11-07 16:01:32 +00:00
|
|
|
await generateInitialAddresses(addressType: SegwitAddresType.p2wpkh);
|
2024-10-29 23:52:19 +00:00
|
|
|
|
|
|
|
if (!isHardwareWallet) {
|
2024-11-07 16:01:32 +00:00
|
|
|
await generateInitialAddresses(addressType: P2pkhAddressType.p2pkh);
|
|
|
|
await generateInitialAddresses(addressType: P2shAddressType.p2wpkhInP2sh);
|
|
|
|
await generateInitialAddresses(addressType: SegwitAddresType.p2tr);
|
|
|
|
await generateInitialAddresses(addressType: SegwitAddresType.p2wsh);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (silentPaymentAddresses.length == 0) {
|
2024-11-16 17:53:00 +00:00
|
|
|
Bip32Path? oldSpendPath;
|
|
|
|
Bip32Path? oldScanPath;
|
|
|
|
|
|
|
|
for (final derivationInfo in walletInfo.derivations ?? <DerivationInfo>[]) {
|
|
|
|
if (derivationInfo.description?.contains("SP") ?? false) {
|
|
|
|
if (derivationInfo.description?.toLowerCase().contains("spend") ?? false) {
|
|
|
|
oldSpendPath = Bip32PathParser.parse(derivationInfo.derivationPath ?? "");
|
|
|
|
} else if (derivationInfo.description?.toLowerCase().contains("scan") ?? false) {
|
|
|
|
oldScanPath = Bip32PathParser.parse(derivationInfo.derivationPath ?? "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldSpendPath != null && oldScanPath != null) {
|
|
|
|
final oldSpendPriv = hdWallet.derive(oldSpendPath).privateKey;
|
|
|
|
final oldScanPriv = hdWallet.derive(oldScanPath).privateKey;
|
|
|
|
|
|
|
|
final oldSilentPaymentWallet = SilentPaymentOwner(
|
|
|
|
b_scan: ECPrivate(oldScanPriv),
|
|
|
|
b_spend: ECPrivate(oldSpendPriv),
|
|
|
|
B_scan: ECPublic.fromBip32(oldScanPriv.publicKey),
|
|
|
|
B_spend: ECPublic.fromBip32(oldSpendPriv.publicKey),
|
|
|
|
version: 0,
|
|
|
|
);
|
|
|
|
silentPaymentWallets.add(oldSilentPaymentWallet);
|
|
|
|
|
|
|
|
silentPaymentAddresses.addAll(
|
|
|
|
[
|
|
|
|
BitcoinSilentPaymentAddressRecord(
|
|
|
|
oldSilentPaymentWallet.toString(),
|
|
|
|
labelIndex: 1,
|
|
|
|
name: "",
|
|
|
|
addressType: SilentPaymentsAddresType.p2sp,
|
|
|
|
derivationPath: oldSpendPath.toString(),
|
|
|
|
isHidden: true,
|
|
|
|
),
|
|
|
|
BitcoinSilentPaymentAddressRecord(
|
|
|
|
oldSilentPaymentWallet.toLabeledSilentPaymentAddress(0).toString(),
|
|
|
|
name: "",
|
|
|
|
labelIndex: 0,
|
|
|
|
labelHex: BytesUtils.toHexString(oldSilentPaymentWallet.generateLabel(0)),
|
|
|
|
addressType: SilentPaymentsAddresType.p2sp,
|
|
|
|
derivationPath: oldSpendPath.toString(),
|
|
|
|
isHidden: true,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
silentPaymentAddresses.addAll([
|
|
|
|
BitcoinSilentPaymentAddressRecord(
|
|
|
|
silentPaymentWallet.toString(),
|
|
|
|
labelIndex: 1,
|
|
|
|
name: "",
|
|
|
|
addressType: SilentPaymentsAddresType.p2sp,
|
|
|
|
),
|
|
|
|
BitcoinSilentPaymentAddressRecord(
|
|
|
|
silentPaymentWallet!.toLabeledSilentPaymentAddress(0).toString(),
|
|
|
|
name: "",
|
|
|
|
labelIndex: 0,
|
|
|
|
labelHex: BytesUtils.toHexString(silentPaymentWallet!.generateLabel(0)),
|
|
|
|
addressType: SilentPaymentsAddresType.p2sp,
|
|
|
|
),
|
|
|
|
]);
|
2024-10-29 23:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateAddressesInBox();
|
|
|
|
}
|
|
|
|
|
2024-11-07 16:01:32 +00:00
|
|
|
@override
|
|
|
|
@computed
|
|
|
|
String get address {
|
|
|
|
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
|
|
|
if (activeSilentAddress != null) {
|
|
|
|
return activeSilentAddress!;
|
|
|
|
}
|
|
|
|
|
|
|
|
return silentPaymentWallet.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
set address(String addr) {
|
|
|
|
if (addr == "Silent Payments" && SilentPaymentsAddresType.p2sp != addressPageType) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
|
|
|
late BitcoinSilentPaymentAddressRecord selected;
|
|
|
|
try {
|
|
|
|
selected =
|
|
|
|
silentPaymentAddresses.firstWhere((addressRecord) => addressRecord.address == addr);
|
|
|
|
} catch (_) {
|
|
|
|
selected = silentPaymentAddresses[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected.labelHex != null) {
|
|
|
|
activeSilentAddress =
|
2024-11-16 17:53:00 +00:00
|
|
|
silentPaymentWallet!.toLabeledSilentPaymentAddress(selected.labelIndex).toString();
|
2024-11-07 16:01:32 +00:00
|
|
|
} else {
|
|
|
|
activeSilentAddress = silentPaymentWallet.toString();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.address = addr;
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
2024-10-04 14:49:49 +00:00
|
|
|
BitcoinBaseAddress generateAddress({
|
2024-11-04 22:29:25 +00:00
|
|
|
required CWBitcoinDerivationType derivationType,
|
2024-10-29 23:52:19 +00:00
|
|
|
required bool isChange,
|
2024-10-04 14:49:49 +00:00
|
|
|
required int index,
|
|
|
|
required BitcoinAddressType addressType,
|
2024-10-30 15:13:59 +00:00
|
|
|
required BitcoinDerivationInfo derivationInfo,
|
2024-10-04 14:49:49 +00:00
|
|
|
}) {
|
2024-11-04 22:29:25 +00:00
|
|
|
final hdWallet = hdWallets[derivationType]!;
|
|
|
|
|
2024-11-16 17:53:00 +00:00
|
|
|
// if (OLD_DERIVATION_TYPES.contains(derivationType)) {
|
|
|
|
// final pub = hdWallet
|
|
|
|
// .childKey(Bip32KeyIndex(isChange ? 1 : 0))
|
|
|
|
// .childKey(Bip32KeyIndex(index))
|
|
|
|
// .publicKey;
|
|
|
|
|
|
|
|
// switch (addressType) {
|
|
|
|
// case P2pkhAddressType.p2pkh:
|
|
|
|
// return ECPublic.fromBip32(pub).toP2pkhAddress();
|
|
|
|
// case SegwitAddresType.p2tr:
|
|
|
|
// return ECPublic.fromBip32(pub).toP2trAddress();
|
|
|
|
// case SegwitAddresType.p2wsh:
|
|
|
|
// return ECPublic.fromBip32(pub).toP2wshAddress();
|
|
|
|
// case P2shAddressType.p2wpkhInP2sh:
|
|
|
|
// return ECPublic.fromBip32(pub).toP2wpkhInP2sh();
|
|
|
|
// case SegwitAddresType.p2wpkh:
|
|
|
|
// return ECPublic.fromBip32(pub).toP2wpkhAddress();
|
|
|
|
// default:
|
|
|
|
// throw ArgumentError('Invalid address type');
|
|
|
|
// }
|
|
|
|
// }
|
2024-11-04 22:29:25 +00:00
|
|
|
|
2024-10-04 14:49:49 +00:00
|
|
|
switch (addressType) {
|
|
|
|
case P2pkhAddressType.p2pkh:
|
2024-10-30 15:13:59 +00:00
|
|
|
return P2pkhAddress.fromDerivation(
|
2024-11-04 22:29:25 +00:00
|
|
|
bip32: hdWallet,
|
2024-10-30 15:13:59 +00:00
|
|
|
derivationInfo: derivationInfo,
|
|
|
|
isChange: isChange,
|
|
|
|
index: index,
|
|
|
|
);
|
2024-10-04 14:49:49 +00:00
|
|
|
case SegwitAddresType.p2tr:
|
2024-10-30 15:13:59 +00:00
|
|
|
return P2trAddress.fromDerivation(
|
2024-11-04 22:29:25 +00:00
|
|
|
bip32: hdWallet,
|
2024-10-30 15:13:59 +00:00
|
|
|
derivationInfo: derivationInfo,
|
|
|
|
isChange: isChange,
|
|
|
|
index: index,
|
|
|
|
);
|
2024-10-04 14:49:49 +00:00
|
|
|
case SegwitAddresType.p2wsh:
|
2024-10-30 15:13:59 +00:00
|
|
|
return P2wshAddress.fromDerivation(
|
2024-11-04 22:29:25 +00:00
|
|
|
bip32: hdWallet,
|
2024-10-30 15:13:59 +00:00
|
|
|
derivationInfo: derivationInfo,
|
|
|
|
isChange: isChange,
|
|
|
|
index: index,
|
|
|
|
);
|
2024-10-04 14:49:49 +00:00
|
|
|
case P2shAddressType.p2wpkhInP2sh:
|
2024-10-30 15:13:59 +00:00
|
|
|
return P2shAddress.fromDerivation(
|
2024-11-04 22:29:25 +00:00
|
|
|
bip32: hdWallet,
|
2024-10-30 15:13:59 +00:00
|
|
|
derivationInfo: derivationInfo,
|
2024-10-29 23:52:19 +00:00
|
|
|
isChange: isChange,
|
2024-10-04 14:49:49 +00:00
|
|
|
index: index,
|
|
|
|
type: P2shAddressType.p2wpkhInP2sh,
|
|
|
|
);
|
|
|
|
case SegwitAddresType.p2wpkh:
|
2024-10-30 15:13:59 +00:00
|
|
|
return P2wpkhAddress.fromDerivation(
|
2024-11-04 22:29:25 +00:00
|
|
|
bip32: hdWallet,
|
2024-10-30 15:13:59 +00:00
|
|
|
derivationInfo: derivationInfo,
|
2024-10-29 23:52:19 +00:00
|
|
|
isChange: isChange,
|
2024-10-28 15:16:23 +00:00
|
|
|
index: index,
|
2024-10-29 23:52:19 +00:00
|
|
|
);
|
2024-10-04 14:49:49 +00:00
|
|
|
default:
|
|
|
|
throw ArgumentError('Invalid address type');
|
|
|
|
}
|
Btc address types (#1263)
* inital migration changes
* feat: rest of changes
* minor fix [skip ci]
* fix: P2wshAddress & wallet address index
* fix: address review comments
* fix: address type restore
* feat: add testnet
* Fix review comments
Remove bitcoin_base from cw_core
* Fix address not matching selected type on start
* remove un-necessary parameter [skip ci]
* Remove bitcoin specific code from main lib
Fix possible runtime exception from list wrong access
* Minor fix
* fix: fixes for Testnet
* fix: bitcoin receive option dependency breaks monerocom
* Fix issues when building Monero.com
* feat: Transaction Builder changes
* fix: discover addresses, testnet restoring, duplicate unspent coins, and taproot address vs schnorr sig tweak
* fix: remove print
* feat: improve error when failed broadcast response
* feat: create fish shell env script
* fix: unmodifiable maps
* fix: build
* fix: build
* fix: computed observable side effect bug
* feat: add nix script for android build_all
* fix: wrong keypairs used for signing
* fix: wrong addresses when using fromScriptPubKey scripts
* fix(actual commit): testnet tx expanded + wrong addresses when using fromScriptPubKey scripts (update bitcoin_base deps)
* fix: self-send [skip ci]
* fix: p2wsh
* fix: testnet fees
* New versions
* Update macos build number
Minor UI fix
* fix: use new bitcoin_base ref, fix tx list wrong hex value & refactor hidden vs hd use
- if always use sideHd for isHidden, it is easier to simplify the functions instead of passing both which can be error prone
- (ps: now this could probably be changed, for example from isHidden to isChange since with address list we now see "hidden" addresses)
* Fix if condition to handle litecoin case
* fix: self-send, change address was always making direction incoming
* refactor: improve estimation function, add more inputs if balance missing
* fix: new bitcoin_base update, fixes script issues
* Update evm chain wallet service arguments
* Fix translation [skip ci]
* Fix translation [skip ci]
* Update strings_fr.arb [skip ci]
* fix: async isChange function not being awaited, refactor to reduce looping into a single place
* fix: _address vs address, missing p2sh
* fix: minor mistake in storing p2sh page type [skip ci]
* refactor: use already matched addresses property
* feat: improved perfomance for fetching transaction histories
* feat: continue perfomance change, improve address discovery only to last address by type with history
* fix: make sure transaction list is sorted by date
* refactor: isTestnet only for bitcoin
* fix: walletInfo type null case
* fix: deprecated p2pk
* refactor: make condition more readable
* refactor: remove unnecessary Str variant
* refactor: make condition more readable
* fix: infinite loop possible
* Revert removing isTestnet from other wallets [skip ci]
* refactor: rename addresses when matched by receive type
* Make the beta build [skip ci]
Remove app_env.fish
---------
Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-02-23 16:13:30 +00:00
|
|
|
}
|
2024-11-07 16:01:32 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
BaseBitcoinAddressRecord generateNewAddress({String label = ''}) {
|
|
|
|
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
|
|
|
final currentSPLabelIndex = silentPaymentAddresses
|
|
|
|
.where((addressRecord) => addressRecord.addressType != SegwitAddresType.p2tr)
|
|
|
|
.length -
|
|
|
|
1;
|
|
|
|
|
|
|
|
final address = BitcoinSilentPaymentAddressRecord(
|
2024-11-16 17:53:00 +00:00
|
|
|
silentPaymentWallet!.toLabeledSilentPaymentAddress(currentSPLabelIndex).toString(),
|
2024-11-07 16:01:32 +00:00
|
|
|
labelIndex: currentSPLabelIndex,
|
|
|
|
name: label,
|
2024-11-16 17:53:00 +00:00
|
|
|
labelHex: BytesUtils.toHexString(silentPaymentWallet!.generateLabel(currentSPLabelIndex)),
|
2024-11-07 16:01:32 +00:00
|
|
|
addressType: SilentPaymentsAddresType.p2sp,
|
|
|
|
);
|
|
|
|
|
|
|
|
silentPaymentAddresses.add(address);
|
|
|
|
Future.delayed(Duration.zero, () => updateAddressesByMatch());
|
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.generateNewAddress(label: label);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void addBitcoinAddressTypes() {
|
|
|
|
super.addBitcoinAddressTypes();
|
|
|
|
|
|
|
|
silentPaymentAddresses.forEach((addressRecord) {
|
|
|
|
if (addressRecord.addressType != SilentPaymentsAddresType.p2sp || addressRecord.isChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addressRecord.address != address) {
|
|
|
|
addressesMap[addressRecord.address] = addressRecord.name.isEmpty
|
|
|
|
? "Silent Payments" + ': ${addressRecord.address}'
|
|
|
|
: "Silent Payments - " + addressRecord.name + ': ${addressRecord.address}';
|
|
|
|
} else {
|
|
|
|
addressesMap[address] = 'Active - Silent Payments' + ': $address';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void updateAddress(String address, String label) {
|
|
|
|
super.updateAddress(address, label);
|
|
|
|
|
|
|
|
BaseBitcoinAddressRecord? foundAddress;
|
|
|
|
silentPaymentAddresses.forEach((addressRecord) {
|
|
|
|
if (addressRecord.address == address) {
|
|
|
|
foundAddress = addressRecord;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (foundAddress != null) {
|
|
|
|
foundAddress!.setNewName(label);
|
|
|
|
|
|
|
|
final index =
|
|
|
|
silentPaymentAddresses.indexOf(foundAddress as BitcoinSilentPaymentAddressRecord);
|
|
|
|
silentPaymentAddresses.remove(foundAddress);
|
|
|
|
silentPaymentAddresses.insert(index, foundAddress as BitcoinSilentPaymentAddressRecord);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
@action
|
|
|
|
void updateAddressesByMatch() {
|
|
|
|
if (addressPageType == SilentPaymentsAddresType.p2sp) {
|
|
|
|
addressesByReceiveType.clear();
|
|
|
|
addressesByReceiveType.addAll(silentPaymentAddresses);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.updateAddressesByMatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
void addSilentAddresses(Iterable<BitcoinSilentPaymentAddressRecord> addresses) {
|
|
|
|
final addressesSet = this.silentPaymentAddresses.toSet();
|
|
|
|
addressesSet.addAll(addresses);
|
|
|
|
this.silentPaymentAddresses.clear();
|
|
|
|
this.silentPaymentAddresses.addAll(addressesSet);
|
|
|
|
updateAddressesByMatch();
|
|
|
|
}
|
|
|
|
|
2024-11-16 17:53:00 +00:00
|
|
|
@action
|
|
|
|
void addReceivedSPAddresses(Iterable<BitcoinReceivedSPAddressRecord> addresses) {
|
|
|
|
final addressesSet = this.receivedSPAddresses.toSet();
|
|
|
|
addressesSet.addAll(addresses);
|
|
|
|
this.receivedSPAddresses.clear();
|
|
|
|
this.receivedSPAddresses.addAll(addressesSet);
|
|
|
|
updateAddressesByMatch();
|
|
|
|
}
|
|
|
|
|
2024-11-07 16:01:32 +00:00
|
|
|
@action
|
|
|
|
void deleteSilentPaymentAddress(String address) {
|
|
|
|
final addressRecord = silentPaymentAddresses.firstWhere((addressRecord) =>
|
|
|
|
addressRecord.addressType == SilentPaymentsAddresType.p2sp &&
|
|
|
|
addressRecord.address == address);
|
|
|
|
|
|
|
|
silentPaymentAddresses.remove(addressRecord);
|
|
|
|
updateAddressesByMatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, String> get labels {
|
|
|
|
final G = ECPublic.fromBytes(BigintUtils.toBytes(Curves.generatorSecp256k1.x, length: 32));
|
|
|
|
final labels = <String, String>{};
|
|
|
|
for (int i = 0; i < silentPaymentAddresses.length; i++) {
|
|
|
|
final silentAddressRecord = silentPaymentAddresses[i];
|
|
|
|
final silentPaymentTweak = silentAddressRecord.labelHex;
|
|
|
|
|
|
|
|
if (silentPaymentTweak != null &&
|
|
|
|
SilentPaymentAddress.regex.hasMatch(silentAddressRecord.address)) {
|
|
|
|
labels[G
|
|
|
|
.tweakMul(BigintUtils.fromBytes(BytesUtils.fromHexString(silentPaymentTweak)))
|
|
|
|
.toHex()] = silentPaymentTweak;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return labels;
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final json = super.toJson();
|
|
|
|
json['silentPaymentAddresses'] =
|
|
|
|
silentPaymentAddresses.map((address) => address.toJSON()).toList();
|
|
|
|
json['receivedSPAddresses'] = receivedSPAddresses.map((address) => address.toJSON()).toList();
|
|
|
|
return json;
|
|
|
|
}
|
2023-10-12 22:50:16 +00:00
|
|
|
}
|