mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-18 08:45:05 +00:00
fix some rescan and address gen issues
This commit is contained in:
parent
dee77a6752
commit
a1dbe3bf2b
2 changed files with 72 additions and 52 deletions
|
@ -5,6 +5,7 @@ import 'package:convert/convert.dart';
|
|||
import 'package:crypto/crypto.dart';
|
||||
import 'package:cw_core/cake_hive.dart';
|
||||
import 'package:cw_core/mweb_utxo.dart';
|
||||
import 'package:cw_mweb/mwebd.pbgrpc.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||
|
@ -211,32 +212,19 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
await mwebUtxosBox.clear();
|
||||
transactionHistory.clear();
|
||||
mwebUtxosHeight = height;
|
||||
walletInfo.restoreHeight = height;
|
||||
await walletInfo.save();
|
||||
await walletInfo.updateRestoreHeight(height);
|
||||
// processMwebUtxos();
|
||||
print("STARTING SYNC");
|
||||
await startSync();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
await transactionHistory.init();
|
||||
await super.init();
|
||||
await initMwebUtxosBox();
|
||||
}
|
||||
|
||||
Future<void> processMwebUtxos() async {
|
||||
final stub = await CwMweb.stub();
|
||||
final scanSecret = mwebHd.derive(0x80000000).privKey!;
|
||||
int restoreHeight = walletInfo.restoreHeight;
|
||||
print("SCANNING FROM HEIGHT: $restoreHeight");
|
||||
final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight);
|
||||
bool initDone = false;
|
||||
|
||||
for (final utxo in mwebUtxosBox.values) {
|
||||
if (utxo.address.isEmpty) {
|
||||
initDone = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
Future<void> handleIncoming(MwebUtxo utxo, RpcClient stub) async {
|
||||
final status = await stub.status(StatusRequest());
|
||||
var date = DateTime.now();
|
||||
var confirmations = 0;
|
||||
|
@ -278,7 +266,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
|
||||
if (addressRecord == null) {
|
||||
print("addressRecord is null! TODO: handle this case 1");
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) addressRecord.txCount++;
|
||||
addressRecord.balance += utxo.value.toInt();
|
||||
|
@ -286,6 +274,28 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
}
|
||||
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
transactionHistory.addOne(tx);
|
||||
}
|
||||
|
||||
Future<void> processMwebUtxos() async {
|
||||
final stub = await CwMweb.stub();
|
||||
final scanSecret = mwebHd.derive(0x80000000).privKey!;
|
||||
int restoreHeight = walletInfo.restoreHeight;
|
||||
print("SCANNING FROM HEIGHT: $restoreHeight");
|
||||
final req = UtxosRequest(scanSecret: hex.decode(scanSecret), fromHeight: restoreHeight);
|
||||
bool initDone = false;
|
||||
|
||||
for (final utxo in mwebUtxosBox.values) {
|
||||
if (utxo.address.isEmpty) {
|
||||
initDone = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (walletInfo.restoreHeight > utxo.height) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await handleIncoming(utxo, stub);
|
||||
|
||||
if (initDone) {
|
||||
await updateUnspent();
|
||||
await updateBalance();
|
||||
|
@ -316,7 +326,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
if (!mwebAddrs.contains(utxo.address) && utxo.address.isNotEmpty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await mwebUtxosBox.put(utxo.outputId, utxo);
|
||||
|
||||
await handleIncoming(utxo, stub);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -427,8 +440,14 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
|||
return;
|
||||
}
|
||||
final unspent = BitcoinUnspent(
|
||||
addressRecord, outputId, utxo.value.toInt(), mwebAddrs.indexOf(utxo.address));
|
||||
if (unspent.vout == 0) unspent.isChange = true;
|
||||
addressRecord,
|
||||
outputId,
|
||||
utxo.value.toInt(),
|
||||
mwebAddrs.indexOf(utxo.address),
|
||||
);
|
||||
if (unspent.vout == 0) {
|
||||
unspent.isChange = true;
|
||||
}
|
||||
unspentCoins.add(unspent);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
|||
@override
|
||||
Future<String> getChangeAddress() async {
|
||||
// super.getChangeAddress();
|
||||
updateChangeAddresses();
|
||||
// updateChangeAddresses();
|
||||
print("getChangeAddress @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||
// this means all change addresses used will be mweb addresses!:
|
||||
await topUpMweb(0);
|
||||
return mwebAddrs[0];
|
||||
|
|
Loading…
Reference in a new issue