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)
|
.where((addr) => addr.isHidden && !addr.isUsed)
|
||||||
.toList();
|
.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 {
|
Future<void> discoverAddresses() async {
|
||||||
await _discoverAddresses(mainHd, false);
|
await _discoverAddresses(mainHd, false);
|
||||||
await _discoverAddresses(sideHd, true);
|
await _discoverAddresses(sideHd, true);
|
||||||
|
@ -64,11 +72,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||||
await _generateInitialAddresses();
|
await _generateInitialAddresses();
|
||||||
|
|
||||||
if (receiveAddresses.isEmpty) {
|
if (receiveAddresses.isEmpty) {
|
||||||
final count = currentReceiveAddressIndex + gap;
|
|
||||||
final newAddresses = await _createNewAddresses(
|
final newAddresses = await _createNewAddresses(
|
||||||
count,
|
gap,
|
||||||
hd: mainHd,
|
hd: mainHd,
|
||||||
startIndex: currentReceiveAddressIndex,
|
startIndex: totalReceiveAddresses.length > 0
|
||||||
|
? totalReceiveAddresses.length - 1
|
||||||
|
: 0,
|
||||||
isHidden: false);
|
isHidden: false);
|
||||||
_addAddresses(newAddresses);
|
_addAddresses(newAddresses);
|
||||||
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
||||||
|
@ -82,11 +91,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||||
@action
|
@action
|
||||||
Future<void> nextReceiveAddress() async {
|
Future<void> nextReceiveAddress() async {
|
||||||
if (receiveAddresses.isEmpty) {
|
if (receiveAddresses.isEmpty) {
|
||||||
final count = currentReceiveAddressIndex + gap;
|
|
||||||
final newAddresses = await _createNewAddresses(
|
final newAddresses = await _createNewAddresses(
|
||||||
count,
|
gap,
|
||||||
hd: sideHd,
|
hd: mainHd,
|
||||||
startIndex: currentReceiveAddressIndex,
|
startIndex: totalReceiveAddresses.length > 0
|
||||||
|
? totalReceiveAddresses.length - 1
|
||||||
|
: 0,
|
||||||
isHidden: false);
|
isHidden: false);
|
||||||
_addAddresses(newAddresses);
|
_addAddresses(newAddresses);
|
||||||
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
} else if (currentReceiveAddressIndex >= receiveAddresses.length) {
|
||||||
|
@ -101,10 +111,12 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
||||||
@action
|
@action
|
||||||
Future<String> getChangeAddress() async {
|
Future<String> getChangeAddress() async {
|
||||||
if (changeAddresses.isEmpty) {
|
if (changeAddresses.isEmpty) {
|
||||||
final count = currentChangeAddressIndex + gap;
|
|
||||||
final newAddresses = await _createNewAddresses(
|
final newAddresses = await _createNewAddresses(
|
||||||
count,
|
gap,
|
||||||
startIndex: currentChangeAddressIndex,
|
hd: sideHd,
|
||||||
|
startIndex: totalChangeAddresses.length > 0
|
||||||
|
? totalChangeAddresses.length - 1
|
||||||
|
: 0,
|
||||||
isHidden: true);
|
isHidden: true);
|
||||||
_addAddresses(newAddresses);
|
_addAddresses(newAddresses);
|
||||||
} else if (currentChangeAddressIndex >= changeAddresses.length) {
|
} else if (currentChangeAddressIndex >= changeAddresses.length) {
|
||||||
|
|
Loading…
Reference in a new issue