mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
more address generation reliability fixes
This commit is contained in:
parent
d8d26a00a4
commit
2c38641d5c
4 changed files with 39 additions and 7 deletions
|
@ -2395,8 +2395,6 @@ class PublicKeyWithDerivationPath {
|
|||
}
|
||||
|
||||
BitcoinBaseAddress addressTypeFromStr(String address, BasedUtxoNetwork network) {
|
||||
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
// print(network);
|
||||
if (network is BitcoinCashNetwork) {
|
||||
if (!address.startsWith("bitcoincash:") &&
|
||||
(address.startsWith("q") || address.startsWith("p"))) {
|
||||
|
|
|
@ -223,8 +223,8 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
if (walletInfo.type == WalletType.bitcoinCash) {
|
||||
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
|
||||
} else if (walletInfo.type == WalletType.litecoin) {
|
||||
// await _generateInitialAddresses();
|
||||
// await _generateInitialAddresses(type: SegwitAddresType.mweb);
|
||||
await _generateInitialAddresses(type: SegwitAddresType.p2wpkh);
|
||||
await _generateInitialAddresses(type: SegwitAddresType.mweb);
|
||||
} else if (walletInfo.type == WalletType.bitcoin) {
|
||||
await _generateInitialAddresses();
|
||||
await _generateInitialAddresses(type: P2pkhAddressType.p2pkh);
|
||||
|
|
|
@ -250,6 +250,12 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
return;
|
||||
}
|
||||
|
||||
final mwebAddrs = (walletAddresses as LitecoinWalletAddresses).mwebAddrs;
|
||||
while (mwebAddrs.length < 1000) {
|
||||
print("waiting for mweb addresses to finish generating...");
|
||||
await Future.delayed(const Duration(milliseconds: 1000));
|
||||
}
|
||||
|
||||
await getStub();
|
||||
await updateUnspent();
|
||||
await updateBalance();
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:typed_data';
|
|||
import 'package:bech32/bech32.dart';
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:blockchain_utils/blockchain_utils.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_address_record.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||
import 'package:cw_bitcoin/utils.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet_addresses.dart';
|
||||
|
@ -33,7 +34,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
super.initialChangeAddressIndex,
|
||||
}) : super(walletInfo) {
|
||||
// start generating mweb addresses in the background:
|
||||
initMwebAddresses();
|
||||
// initMwebAddresses();
|
||||
}
|
||||
|
||||
final Bip32Slip10Secp256k1 mwebHd;
|
||||
|
@ -46,6 +47,12 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
List<int> get spendPubkey =>
|
||||
mwebHd.childKey(Bip32KeyIndex(0x80000001)).publicKey.pubKey.compressed;
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
await super.init();
|
||||
initMwebAddresses();
|
||||
}
|
||||
|
||||
Future<void> ensureMwebAddressUpToIndexExists(int index) async {
|
||||
Uint8List scan = Uint8List.fromList(scanSecret);
|
||||
Uint8List spend = Uint8List.fromList(spendPubkey);
|
||||
|
@ -66,10 +73,30 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
}
|
||||
|
||||
Future<void> initMwebAddresses() async {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
print("Initializing MWEB address timer!");
|
||||
Timer.periodic(const Duration(seconds: 2), (timer) async {
|
||||
print("Generating MWEB addresses...");
|
||||
await generateNumAddresses(250);
|
||||
await Future.delayed(const Duration(milliseconds: 1500));
|
||||
}
|
||||
|
||||
if (mwebAddrs.length > 1000) {
|
||||
// convert mwebAddrs to BitcoinAddressRecords:
|
||||
List<BitcoinAddressRecord> mwebAddresses = mwebAddrs
|
||||
.asMap()
|
||||
.entries
|
||||
.map((e) => BitcoinAddressRecord(
|
||||
e.value,
|
||||
index: e.key,
|
||||
type: SegwitAddresType.mweb,
|
||||
network: network,
|
||||
))
|
||||
.toList();
|
||||
// add them to the list of all addresses:
|
||||
addAddresses(mwebAddresses);
|
||||
print("MWEB addresses initialized ${mwebAddrs.length}");
|
||||
timer.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -126,6 +153,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
}
|
||||
|
||||
if (mwebEnabled) {
|
||||
await ensureMwebAddressUpToIndexExists(1);
|
||||
return mwebAddrs[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue