mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-04-17 19:51:58 +00:00
commit
7cf966c443
3 changed files with 87 additions and 61 deletions
crypto_plugins
lib/wallets/wallet
|
@ -1 +1 @@
|
|||
Subproject commit 8830be2ba661828d743be12df6f33d560448ed6a
|
||||
Subproject commit 0bb1b1ced6e0d3c66e383698f89825754c692986
|
|
@ -27,6 +27,8 @@ import '../intermediate/lib_xelis_wallet.dart';
|
|||
import '../wallet.dart';
|
||||
|
||||
class XelisWallet extends LibXelisWallet {
|
||||
Completer<void>? _initCompleter;
|
||||
|
||||
XelisWallet(CryptoCurrencyNetwork network) : super(Xelis(network));
|
||||
// ==================== Overrides ============================================
|
||||
|
||||
|
@ -65,6 +67,8 @@ class XelisWallet extends LibXelisWallet {
|
|||
);
|
||||
|
||||
libXelisWallet = wallet;
|
||||
|
||||
await _finishInit();
|
||||
}
|
||||
|
||||
Future<void> _createNewWallet() async {
|
||||
|
@ -97,68 +101,93 @@ class XelisWallet extends LibXelisWallet {
|
|||
);
|
||||
|
||||
libXelisWallet = wallet;
|
||||
|
||||
await _finishInit();
|
||||
}
|
||||
|
||||
Future<void> _existingWallet() async {
|
||||
print("EXISTING");
|
||||
Logging.instance.i("Xelis: opening existing wallet");
|
||||
final tablePath = await getPrecomputedTablesPath();
|
||||
final tableState = await getTableState();
|
||||
final xelisDir = await StackFileSystem.applicationXelisDirectory();
|
||||
final String name = walletId;
|
||||
final String directory = xelisDir.path;
|
||||
final password = await secureStorageInterface.read(
|
||||
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
|
||||
);
|
||||
|
||||
libXelisWallet = await x_wallet.openXelisWallet(
|
||||
name: name,
|
||||
directory: directory,
|
||||
password: password!,
|
||||
network: cryptoCurrency.network.xelisNetwork,
|
||||
precomputedTablesPath: tablePath,
|
||||
l1Low: tableState.currentSize.isLow,
|
||||
);
|
||||
|
||||
await _finishInit();
|
||||
}
|
||||
|
||||
Future<void> _finishInit() async {
|
||||
if (await isTableUpgradeAvailable()) {
|
||||
unawaited(updateTablesToDesiredSize());
|
||||
}
|
||||
|
||||
final newReceivingAddress =
|
||||
await getCurrentReceivingAddress() ??
|
||||
Address(
|
||||
walletId: walletId,
|
||||
derivationIndex: 0,
|
||||
derivationPath: null,
|
||||
value: libXelisWallet!.getAddressStr(),
|
||||
publicKey: [],
|
||||
type: AddressType.xelis,
|
||||
subType: AddressSubType.receiving,
|
||||
);
|
||||
|
||||
await mainDB.updateOrPutAddresses([newReceivingAddress]);
|
||||
|
||||
if (info.cachedReceivingAddress != newReceivingAddress.value) {
|
||||
await info.updateReceivingAddress(
|
||||
newAddress: newReceivingAddress.value,
|
||||
isar: mainDB.isar,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> init({bool? isRestore}) async {
|
||||
Logging.instance.d("Xelis: init");
|
||||
|
||||
if (libXelisWallet == null) {
|
||||
if (isRestore == true) {
|
||||
await _restoreWallet();
|
||||
} else {
|
||||
final bool walletExists = await LibXelisWallet.checkWalletExists(walletId);
|
||||
if (!walletExists) {
|
||||
await _createNewWallet();
|
||||
} else {
|
||||
Logging.instance.i("Xelis: opening existing wallet");
|
||||
final tablePath = await getPrecomputedTablesPath();
|
||||
final tableState = await getTableState();
|
||||
final xelisDir = await StackFileSystem.applicationXelisDirectory();
|
||||
final String name = walletId;
|
||||
final String directory = xelisDir.path;
|
||||
final password = await secureStorageInterface.read(
|
||||
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
|
||||
);
|
||||
|
||||
libXelisWallet = await x_wallet.openXelisWallet(
|
||||
name: name,
|
||||
directory: directory,
|
||||
password: password!,
|
||||
network: cryptoCurrency.network.xelisNetwork,
|
||||
precomputedTablesPath: tablePath,
|
||||
l1Low: tableState.currentSize.isLow,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (await isTableUpgradeAvailable()) {
|
||||
unawaited(updateTablesToDesiredSize());
|
||||
}
|
||||
|
||||
final newReceivingAddress =
|
||||
await getCurrentReceivingAddress() ??
|
||||
Address(
|
||||
walletId: walletId,
|
||||
derivationIndex: 0,
|
||||
derivationPath: null,
|
||||
value: libXelisWallet!.getAddressStr(),
|
||||
publicKey: [],
|
||||
type: AddressType.xelis,
|
||||
subType: AddressSubType.receiving,
|
||||
);
|
||||
|
||||
await mainDB.updateOrPutAddresses([newReceivingAddress]);
|
||||
|
||||
if (info.cachedReceivingAddress != newReceivingAddress.value) {
|
||||
await info.updateReceivingAddress(
|
||||
newAddress: newReceivingAddress.value,
|
||||
isar: mainDB.isar,
|
||||
);
|
||||
}
|
||||
if (_initCompleter != null) {
|
||||
await _initCompleter!.future;
|
||||
return super.init();
|
||||
}
|
||||
|
||||
return await super.init();
|
||||
_initCompleter = Completer<void>();
|
||||
|
||||
try {
|
||||
final bool walletExists = await LibXelisWallet.checkWalletExists(walletId);
|
||||
|
||||
if (libXelisWallet == null) {
|
||||
if (isRestore == true) {
|
||||
await _restoreWallet();
|
||||
} else {
|
||||
if (!walletExists) {
|
||||
await _createNewWallet();
|
||||
} else {
|
||||
await _existingWallet();
|
||||
}
|
||||
}
|
||||
}
|
||||
_initCompleter!.complete();
|
||||
} catch (e) {
|
||||
_initCompleter!.completeError(e);
|
||||
rethrow;
|
||||
}
|
||||
|
||||
return super.init();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -191,7 +220,6 @@ class XelisWallet extends LibXelisWallet {
|
|||
|
||||
@override
|
||||
Future<bool> pingCheck() async {
|
||||
checkInitialized();
|
||||
try {
|
||||
await libXelisWallet!.getDaemonInfo();
|
||||
await handleOnline();
|
||||
|
@ -247,7 +275,7 @@ class XelisWallet extends LibXelisWallet {
|
|||
final Map<String, dynamic> nodeInfo =
|
||||
(json.decode(infoString) as Map).cast();
|
||||
|
||||
pruningHeight = int.parse(nodeInfo['pruned_topoheight'].toString());
|
||||
pruningHeight = int.tryParse(nodeInfo['pruned_topoheight']?.toString() ?? '0') ?? 0;
|
||||
return int.parse(nodeInfo['topoheight'].toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ enum XelisTableSize {
|
|||
}
|
||||
}
|
||||
|
||||
enum XelisWalletOpenType { create, restore }
|
||||
|
||||
class XelisTableState {
|
||||
final bool isGenerating;
|
||||
final XelisTableSize currentSize;
|
||||
|
@ -330,7 +328,7 @@ abstract class LibXelisWallet<T extends ElectrumCurrency>
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> open({XelisWalletOpenType? openType}) async {
|
||||
Future<void> open() async {
|
||||
try {
|
||||
await connect();
|
||||
} catch (e) {
|
||||
|
@ -439,4 +437,4 @@ extension XelisTableManagement on LibXelisWallet {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue