mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 06:38:52 +00:00
fix some rescan functionality
This commit is contained in:
parent
3cd31d1bf2
commit
6e4a23007b
1 changed files with 141 additions and 39 deletions
|
@ -275,13 +275,6 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> fullRescan(
|
|
||||||
int maxUnusedAddressGap, int maxNumberOfIndexesToCheck) {
|
|
||||||
refresh();
|
|
||||||
return Future.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> generateNewAddress() {
|
Future<bool> generateNewAddress() {
|
||||||
// TODO: implement generateNewAddress
|
// TODO: implement generateNewAddress
|
||||||
|
@ -321,11 +314,11 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
final address = Address(
|
final address = Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
value: newKeystore.address,
|
value: newKeystore.address,
|
||||||
publicKey: [], // TODO: Add public key
|
publicKey: [],
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: null,
|
derivationPath: null,
|
||||||
type: AddressType.unknown,
|
type: AddressType.unknown,
|
||||||
subType: AddressSubType.unknown,
|
subType: AddressSubType.receiving,
|
||||||
);
|
);
|
||||||
|
|
||||||
await db.putAddress(address);
|
await db.putAddress(address);
|
||||||
|
@ -369,13 +362,99 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
Future<String?> get mnemonicString =>
|
Future<String?> get mnemonicString =>
|
||||||
_secureStore.read(key: '${_walletId}_mnemonic');
|
_secureStore.read(key: '${_walletId}_mnemonic');
|
||||||
|
|
||||||
|
Future<void> _recoverWalletFromSeedPhrase({
|
||||||
|
required String mnemonic,
|
||||||
|
required String mnemonicPassphrase,
|
||||||
|
bool isRescan = false,
|
||||||
|
}) async {
|
||||||
|
final keystore = Keystore.fromMnemonic(
|
||||||
|
mnemonic,
|
||||||
|
password: mnemonicPassphrase,
|
||||||
|
);
|
||||||
|
|
||||||
|
final address = Address(
|
||||||
|
walletId: walletId,
|
||||||
|
value: keystore.address,
|
||||||
|
publicKey: [],
|
||||||
|
derivationIndex: 0,
|
||||||
|
derivationPath: null,
|
||||||
|
type: AddressType.unknown,
|
||||||
|
subType: AddressSubType.receiving,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isRescan) {
|
||||||
|
await db.updateOrPutAddresses([address]);
|
||||||
|
} else {
|
||||||
|
await db.putAddress(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool longMutex = false;
|
||||||
@override
|
@override
|
||||||
Future<void> recoverFromMnemonic(
|
Future<void> fullRescan(
|
||||||
{required String mnemonic,
|
int maxUnusedAddressGap,
|
||||||
|
int maxNumberOfIndexesToCheck,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
Logging.instance.log("Starting full rescan!", level: LogLevel.Info);
|
||||||
|
longMutex = true;
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
WalletSyncStatusChangedEvent(
|
||||||
|
WalletSyncStatus.syncing,
|
||||||
|
walletId,
|
||||||
|
coin,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final _mnemonic = await mnemonicString;
|
||||||
|
final _mnemonicPassphrase = await mnemonicPassphrase;
|
||||||
|
|
||||||
|
await db.deleteWalletBlockchainData(walletId);
|
||||||
|
|
||||||
|
await _recoverWalletFromSeedPhrase(
|
||||||
|
mnemonic: _mnemonic!,
|
||||||
|
mnemonicPassphrase: _mnemonicPassphrase!,
|
||||||
|
isRescan: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
await refresh();
|
||||||
|
Logging.instance.log("Full rescan complete!", level: LogLevel.Info);
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
WalletSyncStatusChangedEvent(
|
||||||
|
WalletSyncStatus.synced,
|
||||||
|
walletId,
|
||||||
|
coin,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
GlobalEventBus.instance.fire(
|
||||||
|
WalletSyncStatusChangedEvent(
|
||||||
|
WalletSyncStatus.unableToSync,
|
||||||
|
walletId,
|
||||||
|
coin,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Logging.instance.log(
|
||||||
|
"Exception rethrown from fullRescan(): $e\n$s",
|
||||||
|
level: LogLevel.Error,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
longMutex = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> recoverFromMnemonic({
|
||||||
|
required String mnemonic,
|
||||||
String? mnemonicPassphrase,
|
String? mnemonicPassphrase,
|
||||||
required int maxUnusedAddressGap,
|
required int maxUnusedAddressGap,
|
||||||
required int maxNumberOfIndexesToCheck,
|
required int maxNumberOfIndexesToCheck,
|
||||||
required int height}) async {
|
required int height,
|
||||||
|
}) async {
|
||||||
|
longMutex = true;
|
||||||
|
try {
|
||||||
if ((await mnemonicString) != null ||
|
if ((await mnemonicString) != null ||
|
||||||
(await this.mnemonicPassphrase) != null) {
|
(await this.mnemonicPassphrase) != null) {
|
||||||
throw Exception("Attempted to overwrite mnemonic on restore!");
|
throw Exception("Attempted to overwrite mnemonic on restore!");
|
||||||
|
@ -387,22 +466,27 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
value: mnemonicPassphrase ?? "",
|
value: mnemonicPassphrase ?? "",
|
||||||
);
|
);
|
||||||
|
|
||||||
final address = Address(
|
await _recoverWalletFromSeedPhrase(
|
||||||
walletId: walletId,
|
mnemonic: mnemonic,
|
||||||
value: Keystore.fromMnemonic(mnemonic).address,
|
mnemonicPassphrase: mnemonicPassphrase ?? "",
|
||||||
publicKey: [], // TODO: Add public key
|
isRescan: false,
|
||||||
derivationIndex: 0,
|
|
||||||
derivationPath: null,
|
|
||||||
type: AddressType.unknown,
|
|
||||||
subType: AddressSubType.unknown,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await db.putAddress(address);
|
|
||||||
|
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
updateCachedId(walletId),
|
updateCachedId(walletId),
|
||||||
updateCachedIsFavorite(false),
|
updateCachedIsFavorite(false),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await refresh();
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance.log(
|
||||||
|
"Exception rethrown from recoverFromMnemonic(): $e\n$s",
|
||||||
|
level: LogLevel.Error);
|
||||||
|
|
||||||
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
longMutex = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateBalance() async {
|
Future<void> updateBalance() async {
|
||||||
|
@ -438,10 +522,17 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
for (var tx in response as List) {
|
for (var tx in response as List) {
|
||||||
if (tx["type"] == "transaction") {
|
if (tx["type"] == "transaction") {
|
||||||
TransactionType txType;
|
TransactionType txType;
|
||||||
if (tx["sender"]["address"] == (await currentReceivingAddress)) {
|
final String myAddress = await currentReceivingAddress;
|
||||||
|
final String senderAddress = tx["sender"]["address"] as String;
|
||||||
|
final String targetAddress = tx["target"]["address"] as String;
|
||||||
|
if (senderAddress == myAddress && targetAddress == myAddress) {
|
||||||
|
txType = TransactionType.sentToSelf;
|
||||||
|
} else if (senderAddress == myAddress) {
|
||||||
txType = TransactionType.outgoing;
|
txType = TransactionType.outgoing;
|
||||||
} else {
|
} else if (targetAddress == myAddress) {
|
||||||
txType = TransactionType.incoming;
|
txType = TransactionType.incoming;
|
||||||
|
} else {
|
||||||
|
txType = TransactionType.unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
var theTx = Transaction(
|
var theTx = Transaction(
|
||||||
|
@ -470,14 +561,25 @@ class TezosWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
||||||
nonce: 0,
|
nonce: 0,
|
||||||
numberOfMessages: null,
|
numberOfMessages: null,
|
||||||
);
|
);
|
||||||
var theAddress = Address(
|
final AddressSubType subType;
|
||||||
|
switch (txType) {
|
||||||
|
case TransactionType.incoming:
|
||||||
|
case TransactionType.sentToSelf:
|
||||||
|
subType = AddressSubType.receiving;
|
||||||
|
break;
|
||||||
|
case TransactionType.outgoing:
|
||||||
|
case TransactionType.unknown:
|
||||||
|
subType = AddressSubType.unknown;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final theAddress = Address(
|
||||||
walletId: walletId,
|
walletId: walletId,
|
||||||
value: tx["target"]["address"].toString(),
|
value: targetAddress,
|
||||||
publicKey: [], // TODO: Add public key
|
publicKey: [],
|
||||||
derivationIndex: 0,
|
derivationIndex: 0,
|
||||||
derivationPath: null,
|
derivationPath: null,
|
||||||
type: AddressType.unknown,
|
type: AddressType.unknown,
|
||||||
subType: AddressSubType.unknown,
|
subType: subType,
|
||||||
);
|
);
|
||||||
txs.add(Tuple2(theTx, theAddress));
|
txs.add(Tuple2(theTx, theAddress));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue