mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-30 22:46:10 +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:crypto/crypto.dart';
|
||||||
import 'package:cw_core/cake_hive.dart';
|
import 'package:cw_core/cake_hive.dart';
|
||||||
import 'package:cw_core/mweb_utxo.dart';
|
import 'package:cw_core/mweb_utxo.dart';
|
||||||
|
import 'package:cw_mweb/mwebd.pbgrpc.dart';
|
||||||
import 'package:fixnum/fixnum.dart';
|
import 'package:fixnum/fixnum.dart';
|
||||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||||
|
@ -211,32 +212,19 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
await mwebUtxosBox.clear();
|
await mwebUtxosBox.clear();
|
||||||
transactionHistory.clear();
|
transactionHistory.clear();
|
||||||
mwebUtxosHeight = height;
|
mwebUtxosHeight = height;
|
||||||
walletInfo.restoreHeight = height;
|
await walletInfo.updateRestoreHeight(height);
|
||||||
await walletInfo.save();
|
|
||||||
// processMwebUtxos();
|
// processMwebUtxos();
|
||||||
|
print("STARTING SYNC");
|
||||||
await startSync();
|
await startSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await transactionHistory.init();
|
await super.init();
|
||||||
await initMwebUtxosBox();
|
await initMwebUtxosBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> processMwebUtxos() async {
|
Future<void> handleIncoming(MwebUtxo utxo, RpcClient stub) 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
final status = await stub.status(StatusRequest());
|
final status = await stub.status(StatusRequest());
|
||||||
var date = DateTime.now();
|
var date = DateTime.now();
|
||||||
var confirmations = 0;
|
var confirmations = 0;
|
||||||
|
@ -278,7 +266,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
|
.firstWhereOrNull((addressRecord) => addressRecord.address == utxo.address);
|
||||||
if (addressRecord == null) {
|
if (addressRecord == null) {
|
||||||
print("addressRecord is null! TODO: handle this case 1");
|
print("addressRecord is null! TODO: handle this case 1");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) addressRecord.txCount++;
|
if (!(tx.inputAddresses?.contains(utxo.address) ?? false)) addressRecord.txCount++;
|
||||||
addressRecord.balance += utxo.value.toInt();
|
addressRecord.balance += utxo.value.toInt();
|
||||||
|
@ -286,6 +274,28 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
}
|
}
|
||||||
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@");
|
print("BEING ADDED HERE@@@@@@@@@@@@@@@@@@@@@@@");
|
||||||
transactionHistory.addOne(tx);
|
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) {
|
if (initDone) {
|
||||||
await updateUnspent();
|
await updateUnspent();
|
||||||
await updateBalance();
|
await updateBalance();
|
||||||
|
@ -316,7 +326,10 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
if (!mwebAddrs.contains(utxo.address) && utxo.address.isNotEmpty) {
|
if (!mwebAddrs.contains(utxo.address) && utxo.address.isNotEmpty) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await mwebUtxosBox.put(utxo.outputId, utxo);
|
await mwebUtxosBox.put(utxo.outputId, utxo);
|
||||||
|
|
||||||
|
await handleIncoming(utxo, stub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,8 +440,14 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final unspent = BitcoinUnspent(
|
final unspent = BitcoinUnspent(
|
||||||
addressRecord, outputId, utxo.value.toInt(), mwebAddrs.indexOf(utxo.address));
|
addressRecord,
|
||||||
if (unspent.vout == 0) unspent.isChange = true;
|
outputId,
|
||||||
|
utxo.value.toInt(),
|
||||||
|
mwebAddrs.indexOf(utxo.address),
|
||||||
|
);
|
||||||
|
if (unspent.vout == 0) {
|
||||||
|
unspent.isChange = true;
|
||||||
|
}
|
||||||
unspentCoins.add(unspent);
|
unspentCoins.add(unspent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,8 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with
|
||||||
@override
|
@override
|
||||||
Future<String> getChangeAddress() async {
|
Future<String> getChangeAddress() async {
|
||||||
// super.getChangeAddress();
|
// super.getChangeAddress();
|
||||||
updateChangeAddresses();
|
// updateChangeAddresses();
|
||||||
|
print("getChangeAddress @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
|
||||||
// this means all change addresses used will be mweb addresses!:
|
// this means all change addresses used will be mweb addresses!:
|
||||||
await topUpMweb(0);
|
await topUpMweb(0);
|
||||||
return mwebAddrs[0];
|
return mwebAddrs[0];
|
||||||
|
|
Loading…
Reference in a new issue