mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-19 01:04:43 +00:00
[skip ci] wip
This commit is contained in:
parent
3963233c0e
commit
1061b7de01
2 changed files with 68 additions and 12 deletions
|
@ -335,6 +335,13 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
}) =>
|
||||
'';
|
||||
|
||||
Future<String> getAddressAsync({
|
||||
required int index,
|
||||
required Bip32Slip10Secp256k1 hd,
|
||||
BitcoinAddressType? addressType,
|
||||
}) async =>
|
||||
getAddress(index: index, hd: hd, addressType: addressType);
|
||||
|
||||
void addBitcoinAddressTypes() {
|
||||
final lastP2wpkh = _addresses
|
||||
.where((addressRecord) =>
|
||||
|
@ -569,7 +576,7 @@ abstract class ElectrumWalletAddressesBase extends WalletAddresses with Store {
|
|||
|
||||
for (var i = startIndex; i < count + startIndex; i++) {
|
||||
final address = BitcoinAddressRecord(
|
||||
getAddress(index: i, hd: _getHd(isHidden), addressType: type ?? addressPageType),
|
||||
await getAddressAsync(index: i, hd: _getHd(isHidden), addressType: type ?? addressPageType),
|
||||
index: i,
|
||||
isHidden: isHidden,
|
||||
type: type ?? addressPageType,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:bech32/bech32.dart';
|
||||
|
@ -30,29 +31,63 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
super.initialRegularAddressIndex,
|
||||
super.initialChangeAddressIndex,
|
||||
}) : super(walletInfo) {
|
||||
topUpMweb(0);
|
||||
initMwebAddresses();
|
||||
// topUpMweb(0);
|
||||
print("initialized LitecoinWalletAddressesBase");
|
||||
}
|
||||
|
||||
final Bip32Slip10Secp256k1 mwebHd;
|
||||
bool mwebEnabled;
|
||||
int mwebTopUpIndex = 1000;
|
||||
List<String> mwebAddrs = [];
|
||||
static Timer? mwebTopUpTimer;
|
||||
|
||||
List<int> get scanSecret => mwebHd.childKey(Bip32KeyIndex(0x80000000)).privateKey.privKey.raw;
|
||||
List<int> get spendPubkey =>
|
||||
mwebHd.childKey(Bip32KeyIndex(0x80000001)).publicKey.pubKey.compressed;
|
||||
|
||||
List<String> mwebAddrs = [];
|
||||
// Future<void> topUpMweb(int index) async {
|
||||
// // generate up to index + 1000 addresses:
|
||||
// while (mwebAddrs.length - index < 1000) {
|
||||
// final length = mwebAddrs.length;
|
||||
// final address = await CwMweb.address(
|
||||
// Uint8List.fromList(scanSecret),
|
||||
// Uint8List.fromList(spendPubkey),
|
||||
// length,
|
||||
// );
|
||||
// mwebAddrs.add(address!);
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> topUpMweb(int index) async {
|
||||
// generate up to index + 1000 addresses:
|
||||
while (mwebAddrs.length - index < 1000) {
|
||||
final length = mwebAddrs.length;
|
||||
Future<void> initMwebAddresses() async {
|
||||
print("mweb addresses: ${mwebAddrs.length}");
|
||||
const int INITIAL_MWEB_ADDRESSES = 25;
|
||||
// make sure we have at least 20 addresses:
|
||||
while (mwebAddrs.length < INITIAL_MWEB_ADDRESSES) {
|
||||
final address = await CwMweb.address(
|
||||
Uint8List.fromList(scanSecret),
|
||||
Uint8List.fromList(spendPubkey),
|
||||
length,
|
||||
mwebAddrs.length,
|
||||
);
|
||||
mwebAddrs.add(address!);
|
||||
}
|
||||
|
||||
// set up a periodic task to fill up the mweb addresses to 1000:
|
||||
mwebTopUpTimer?.cancel();
|
||||
mwebTopUpTimer = Timer.periodic(Duration(seconds: 5), (timer) async {
|
||||
if (mwebAddrs.length >= mwebTopUpIndex) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final address = await CwMweb.address(
|
||||
Uint8List.fromList(scanSecret),
|
||||
Uint8List.fromList(spendPubkey),
|
||||
mwebAddrs.length,
|
||||
);
|
||||
mwebAddrs.add(address!);
|
||||
}
|
||||
print("mweb addresses: ${mwebAddrs.length}");
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -62,13 +97,28 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
BitcoinAddressType? addressType,
|
||||
}) {
|
||||
if (addressType == SegwitAddresType.mweb) {
|
||||
topUpMweb(index).then((value) {
|
||||
return hd == sideHd ? mwebAddrs[0] : mwebAddrs[index + 1];
|
||||
});
|
||||
return hd == sideHd ? mwebAddrs[0] : mwebAddrs[index + 1];
|
||||
}
|
||||
return generateP2WPKHAddress(hd: hd, index: index, network: network);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> getAddressAsync({
|
||||
required int index,
|
||||
required Bip32Slip10Secp256k1 hd,
|
||||
BitcoinAddressType? addressType,
|
||||
}) async {
|
||||
if (addressType == SegwitAddresType.mweb) {
|
||||
if (index + 1000 > mwebTopUpIndex) {
|
||||
mwebTopUpIndex = index + 1000;
|
||||
}
|
||||
while (mwebAddrs.length <= index) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
}
|
||||
return getAddress(index: index, hd: hd, addressType: addressType);
|
||||
}
|
||||
|
||||
@action
|
||||
@override
|
||||
Future<String> getChangeAddress({List<BitcoinOutput>? outputs, UtxoDetails? utxoDetails}) async {
|
||||
|
@ -99,7 +149,6 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
}
|
||||
|
||||
if (mwebEnabled) {
|
||||
await topUpMweb(0);
|
||||
return mwebAddrs[0];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue