mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
Update logic for creation receive and change addresses
This commit is contained in:
parent
751d5066b9
commit
31a67fa30d
1 changed files with 22 additions and 10 deletions
|
@ -53,6 +53,14 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
.where((addr) => addr.isHidden && !addr.isUsed)
|
||||
.toList();
|
||||
|
||||
List<BitcoinAddressRecord> get totalReceiveAddresses => addresses
|
||||
.where((addr) => !addr.isHidden)
|
||||
.toList();
|
||||
|
||||
List<BitcoinAddressRecord> get totalChangeAddresses => addresses
|
||||
.where((addr) => addr.isHidden)
|
||||
.toList();
|
||||
|
||||
Future<void> discoverAddresses() async {
|
||||
await _discoverAddresses(mainHd, false);
|
||||
await _discoverAddresses(sideHd, true);
|
||||
|
@ -64,11 +72,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
await _generateInitialAddresses();
|
||||
|
||||
if (receiveAddresses.isEmpty) {
|
||||
final count = currentReceiveAddressIndex + gap;
|
||||
final newAddresses = await _createNewAddresses(
|
||||
count,
|
||||
gap,
|
||||
hd: mainHd,
|
||||
startIndex: currentReceiveAddressIndex,
|
||||
startIndex: totalReceiveAddresses.length > 0
|
||||
? totalReceiveAddresses.length - 1
|
||||
: 0,
|
||||
isHidden: false);
|
||||
_addAddresses(newAddresses);
|
||||
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
||||
|
@ -82,11 +91,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
@action
|
||||
Future<void> nextReceiveAddress() async {
|
||||
if (receiveAddresses.isEmpty) {
|
||||
final count = currentReceiveAddressIndex + gap;
|
||||
final newAddresses = await _createNewAddresses(
|
||||
count,
|
||||
hd: sideHd,
|
||||
startIndex: currentReceiveAddressIndex,
|
||||
gap,
|
||||
hd: mainHd,
|
||||
startIndex: totalReceiveAddresses.length > 0
|
||||
? totalReceiveAddresses.length - 1
|
||||
: 0,
|
||||
isHidden: false);
|
||||
_addAddresses(newAddresses);
|
||||
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
||||
|
@ -101,10 +111,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
@action
|
||||
Future<String> getChangeAddress() async {
|
||||
if (changeAddresses.isEmpty) {
|
||||
final count = currentChangeAddressIndex + gap;
|
||||
final newAddresses = await _createNewAddresses(
|
||||
count,
|
||||
startIndex: currentChangeAddressIndex,
|
||||
gap,
|
||||
hd: sideHd,
|
||||
startIndex: totalChangeAddresses.length > 0
|
||||
? totalChangeAddresses.length - 1
|
||||
: 0,
|
||||
isHidden: true);
|
||||
_addAddresses(newAddresses);
|
||||
} else if (currentChangeAddressIndex >= changeAddresses.length) {
|
||||
|
|
Loading…
Reference in a new issue