From c620a5e23a9a7e1012f91d996450bdd558942408 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Sun, 6 Aug 2023 22:57:34 -0500 Subject: [PATCH] WIP nextChangeAddress WIP move reserve_change_addresses(int addresses) to fusion interface --- fusiondart | 2 +- .../coins/bitcoincash/bitcoincash_wallet.dart | 28 +++++++++++++++---- lib/services/mixins/fusion_interface.dart | 12 ++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/fusiondart b/fusiondart index b4209c152..ad107a683 160000 --- a/fusiondart +++ b/fusiondart @@ -1 +1 @@ -Subproject commit b4209c1523cf53d9db805ce0924e6902c716c0f3 +Subproject commit ad107a683cfdf72040270921062fc6f43ae63f6b diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index ea2341ffd..e0e6b095c 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -26,7 +26,8 @@ import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart'; import 'package:stackwallet/electrumx_rpc/electrumx.dart'; import 'package:stackwallet/models/balance.dart'; -import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; +import 'package:stackwallet/models/isar/models/blockchain_data/address.dart' + as stack_address; import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models; import 'package:stackwallet/models/paymint/fee_object_model.dart'; import 'package:stackwallet/models/signing_data.dart'; @@ -197,8 +198,25 @@ class BitcoinCashWallet extends CoinServiceAPI .findFirst()) ?? await _generateAddressForChain(0, 0, DerivePathTypeExt.primaryFor(coin)); - Future get currentChangeAddress async => - (await _currentChangeAddress).value; + Future get currentChangeAddress async => (await _currentChangeAddress) + .value; // could return Address to cast Stack's Address to Fusiondart's Address like `(await _currentChangeAddress).toFusionAddress();` + + Future get nextChangeAddress async { + // get change
+ final currentChange = await _currentChangeAddress; + // use
.derivationmIndex + 1 to get next change address derivation path + final int nextChangeIndex = currentChange.derivationIndex + 1; + // generate next change address + final stack_address.Address newChangeAddress = + await _generateAddressForChain( + 1, + nextChangeIndex, + DerivePathTypeExt.primaryFor( + coin)); // may need to pick other derive path type, eg 44, 49, 84 + + return newChangeAddress + .value; // could return Address to cast Stack's Address to Fusiondart's Address like `newChangeAddress.toFusionAddress();` + } Future get _currentChangeAddress async => (await db @@ -2147,10 +2165,10 @@ class BitcoinCashWallet extends CoinServiceAPI walletId: walletId, value: possible, publicKey: [], - type: AddressType.nonWallet, + type: stack_address.AddressType.nonWallet, derivationIndex: -1, derivationPath: null, - subType: AddressSubType.nonWallet, + subType: stack_address.AddressSubType.nonWallet, ); } } else { diff --git a/lib/services/mixins/fusion_interface.dart b/lib/services/mixins/fusion_interface.dart index fc721d781..dcab0096e 100644 --- a/lib/services/mixins/fusion_interface.dart +++ b/lib/services/mixins/fusion_interface.dart @@ -30,6 +30,18 @@ mixin FusionInterface { _getCurrentChangeAddress = getCurrentChangeAddress; } + static List
reserve_change_addresses(int number_addresses) { + // TODO + // get current change address + // get int number_addresses next addresses + return []; + } + + static List
unreserve_change_address(Address addr) { + //implement later based on wallet. + return []; + } + void fuse() async { // Initial attempt for CashFusion integration goes here. Fusion mainFusionObject = Fusion();