mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-05 18:29:22 +00:00
fix: auto save formatting
This commit is contained in:
parent
84ab43ced1
commit
ab07b9c80e
1 changed files with 73 additions and 27 deletions
|
@ -81,7 +81,11 @@ class MainDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> isContactEntryExists({required String id}) async {
|
Future<bool> isContactEntryExists({required String id}) async {
|
||||||
return isar.contactEntrys.where().customIdEqualTo(id).count().then((value) => value > 0);
|
return isar.contactEntrys
|
||||||
|
.where()
|
||||||
|
.customIdEqualTo(id)
|
||||||
|
.count()
|
||||||
|
.then((value) => value > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactEntry? getContactEntry({required String id}) {
|
ContactEntry? getContactEntry({required String id}) {
|
||||||
|
@ -101,10 +105,14 @@ class MainDB {
|
||||||
|
|
||||||
// tx block explorers
|
// tx block explorers
|
||||||
TransactionBlockExplorer? getTransactionBlockExplorer({required Coin coin}) {
|
TransactionBlockExplorer? getTransactionBlockExplorer({required Coin coin}) {
|
||||||
return isar.transactionBlockExplorers.where().tickerEqualTo(coin.ticker).findFirstSync();
|
return isar.transactionBlockExplorers
|
||||||
|
.where()
|
||||||
|
.tickerEqualTo(coin.ticker)
|
||||||
|
.findFirstSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> putTransactionBlockExplorer(TransactionBlockExplorer explorer) async {
|
Future<int> putTransactionBlockExplorer(
|
||||||
|
TransactionBlockExplorer explorer) async {
|
||||||
try {
|
try {
|
||||||
return await isar.writeTxn(() async {
|
return await isar.writeTxn(() async {
|
||||||
return await isar.transactionBlockExplorers.put(explorer);
|
return await isar.transactionBlockExplorers.put(explorer);
|
||||||
|
@ -115,7 +123,8 @@ class MainDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
QueryBuilder<Address, Address, QAfterWhereClause> getAddresses(String walletId) =>
|
QueryBuilder<Address, Address, QAfterWhereClause> getAddresses(
|
||||||
|
String walletId) =>
|
||||||
isar.addresses.where().walletIdEqualTo(walletId);
|
isar.addresses.where().walletIdEqualTo(walletId);
|
||||||
|
|
||||||
Future<int> putAddress(Address address) async {
|
Future<int> putAddress(Address address) async {
|
||||||
|
@ -143,7 +152,8 @@ class MainDB {
|
||||||
List<int> ids = [];
|
List<int> ids = [];
|
||||||
await isar.writeTxn(() async {
|
await isar.writeTxn(() async {
|
||||||
for (final address in addresses) {
|
for (final address in addresses) {
|
||||||
final storedAddress = await isar.addresses.getByValueWalletId(address.value, address.walletId);
|
final storedAddress = await isar.addresses
|
||||||
|
.getByValueWalletId(address.value, address.walletId);
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
if (storedAddress == null) {
|
if (storedAddress == null) {
|
||||||
|
@ -183,12 +193,14 @@ class MainDB {
|
||||||
return id;
|
return id;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw MainDBException("failed updateAddress: from=$oldAddress to=$newAddress", e);
|
throw MainDBException(
|
||||||
|
"failed updateAddress: from=$oldAddress to=$newAddress", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// transactions
|
// transactions
|
||||||
QueryBuilder<Transaction, Transaction, QAfterWhereClause> getTransactions(String walletId) =>
|
QueryBuilder<Transaction, Transaction, QAfterWhereClause> getTransactions(
|
||||||
|
String walletId) =>
|
||||||
isar.transactions.where().walletIdEqualTo(walletId);
|
isar.transactions.where().walletIdEqualTo(walletId);
|
||||||
|
|
||||||
Future<int> putTransaction(Transaction transaction) async {
|
Future<int> putTransaction(Transaction transaction) async {
|
||||||
|
@ -223,7 +235,8 @@ class MainDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
// utxos
|
// utxos
|
||||||
QueryBuilder<UTXO, UTXO, QAfterWhereClause> getUTXOs(String walletId) => isar.utxos.where().walletIdEqualTo(walletId);
|
QueryBuilder<UTXO, UTXO, QAfterWhereClause> getUTXOs(String walletId) =>
|
||||||
|
isar.utxos.where().walletIdEqualTo(walletId);
|
||||||
|
|
||||||
Future<void> putUTXO(UTXO utxo) => isar.writeTxn(() async {
|
Future<void> putUTXO(UTXO utxo) => isar.writeTxn(() async {
|
||||||
await isar.utxos.put(utxo);
|
await isar.utxos.put(utxo);
|
||||||
|
@ -238,8 +251,10 @@ class MainDB {
|
||||||
final set = utxos.toSet();
|
final set = utxos.toSet();
|
||||||
for (final utxo in utxos) {
|
for (final utxo in utxos) {
|
||||||
// check if utxo exists in db and update accordingly
|
// check if utxo exists in db and update accordingly
|
||||||
final storedUtxo =
|
final storedUtxo = await isar.utxos
|
||||||
await isar.utxos.where().txidWalletIdVoutEqualTo(utxo.txid, utxo.walletId, utxo.vout).findFirst();
|
.where()
|
||||||
|
.txidWalletIdVoutEqualTo(utxo.txid, utxo.walletId, utxo.vout)
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
if (storedUtxo != null) {
|
if (storedUtxo != null) {
|
||||||
// update
|
// update
|
||||||
|
@ -269,18 +284,22 @@ class MainDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
// transaction notes
|
// transaction notes
|
||||||
QueryBuilder<TransactionNote, TransactionNote, QAfterWhereClause> getTransactionNotes(String walletId) =>
|
QueryBuilder<TransactionNote, TransactionNote, QAfterWhereClause>
|
||||||
isar.transactionNotes.where().walletIdEqualTo(walletId);
|
getTransactionNotes(String walletId) =>
|
||||||
|
isar.transactionNotes.where().walletIdEqualTo(walletId);
|
||||||
|
|
||||||
Future<void> putTransactionNote(TransactionNote transactionNote) => isar.writeTxn(() async {
|
Future<void> putTransactionNote(TransactionNote transactionNote) =>
|
||||||
|
isar.writeTxn(() async {
|
||||||
await isar.transactionNotes.put(transactionNote);
|
await isar.transactionNotes.put(transactionNote);
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> putTransactionNotes(List<TransactionNote> transactionNotes) => isar.writeTxn(() async {
|
Future<void> putTransactionNotes(List<TransactionNote> transactionNotes) =>
|
||||||
|
isar.writeTxn(() async {
|
||||||
await isar.transactionNotes.putAll(transactionNotes);
|
await isar.transactionNotes.putAll(transactionNotes);
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<TransactionNote?> getTransactionNote(String walletId, String txid) async {
|
Future<TransactionNote?> getTransactionNote(
|
||||||
|
String walletId, String txid) async {
|
||||||
return isar.transactionNotes.getByTxidWalletId(
|
return isar.transactionNotes.getByTxidWalletId(
|
||||||
txid,
|
txid,
|
||||||
walletId,
|
walletId,
|
||||||
|
@ -291,14 +310,17 @@ class MainDB {
|
||||||
required Id id,
|
required Id id,
|
||||||
bool fireImmediately = false,
|
bool fireImmediately = false,
|
||||||
}) {
|
}) {
|
||||||
return isar.transactionNotes.watchObject(id, fireImmediately: fireImmediately);
|
return isar.transactionNotes
|
||||||
|
.watchObject(id, fireImmediately: fireImmediately);
|
||||||
}
|
}
|
||||||
|
|
||||||
// address labels
|
// address labels
|
||||||
QueryBuilder<AddressLabel, AddressLabel, QAfterWhereClause> getAddressLabels(String walletId) =>
|
QueryBuilder<AddressLabel, AddressLabel, QAfterWhereClause> getAddressLabels(
|
||||||
|
String walletId) =>
|
||||||
isar.addressLabels.where().walletIdEqualTo(walletId);
|
isar.addressLabels.where().walletIdEqualTo(walletId);
|
||||||
|
|
||||||
Future<int> putAddressLabel(AddressLabel addressLabel) => isar.writeTxn(() async {
|
Future<int> putAddressLabel(AddressLabel addressLabel) =>
|
||||||
|
isar.writeTxn(() async {
|
||||||
return await isar.addressLabels.put(addressLabel);
|
return await isar.addressLabels.put(addressLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -306,11 +328,13 @@ class MainDB {
|
||||||
return isar.addressLabels.putSync(addressLabel);
|
return isar.addressLabels.putSync(addressLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> putAddressLabels(List<AddressLabel> addressLabels) => isar.writeTxn(() async {
|
Future<void> putAddressLabels(List<AddressLabel> addressLabels) =>
|
||||||
|
isar.writeTxn(() async {
|
||||||
await isar.addressLabels.putAll(addressLabels);
|
await isar.addressLabels.putAll(addressLabels);
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<AddressLabel?> getAddressLabel(String walletId, String addressString) async {
|
Future<AddressLabel?> getAddressLabel(
|
||||||
|
String walletId, String addressString) async {
|
||||||
return isar.addressLabels.getByAddressStringWalletId(
|
return isar.addressLabels.getByAddressStringWalletId(
|
||||||
addressString,
|
addressString,
|
||||||
walletId,
|
walletId,
|
||||||
|
@ -352,19 +376,31 @@ class MainDB {
|
||||||
|
|
||||||
// transactions
|
// transactions
|
||||||
for (int i = 0; i < transactionCount; i += paginateLimit) {
|
for (int i = 0; i < transactionCount; i += paginateLimit) {
|
||||||
final txnIds = await getTransactions(walletId).offset(i).limit(paginateLimit).idProperty().findAll();
|
final txnIds = await getTransactions(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
await isar.transactions.deleteAll(txnIds);
|
await isar.transactions.deleteAll(txnIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
for (int i = 0; i < addressCount; i += paginateLimit) {
|
for (int i = 0; i < addressCount; i += paginateLimit) {
|
||||||
final addressIds = await getAddresses(walletId).offset(i).limit(paginateLimit).idProperty().findAll();
|
final addressIds = await getAddresses(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
await isar.addresses.deleteAll(addressIds);
|
await isar.addresses.deleteAll(addressIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// utxos
|
// utxos
|
||||||
for (int i = 0; i < utxoCount; i += paginateLimit) {
|
for (int i = 0; i < utxoCount; i += paginateLimit) {
|
||||||
final utxoIds = await getUTXOs(walletId).offset(i).limit(paginateLimit).idProperty().findAll();
|
final utxoIds = await getUTXOs(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
await isar.utxos.deleteAll(utxoIds);
|
await isar.utxos.deleteAll(utxoIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -375,7 +411,11 @@ class MainDB {
|
||||||
await isar.writeTxn(() async {
|
await isar.writeTxn(() async {
|
||||||
const paginateLimit = 50;
|
const paginateLimit = 50;
|
||||||
for (int i = 0; i < addressLabelCount; i += paginateLimit) {
|
for (int i = 0; i < addressLabelCount; i += paginateLimit) {
|
||||||
final labelIds = await getAddressLabels(walletId).offset(i).limit(paginateLimit).idProperty().findAll();
|
final labelIds = await getAddressLabels(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
await isar.addressLabels.deleteAll(labelIds);
|
await isar.addressLabels.deleteAll(labelIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -386,7 +426,11 @@ class MainDB {
|
||||||
await isar.writeTxn(() async {
|
await isar.writeTxn(() async {
|
||||||
const paginateLimit = 50;
|
const paginateLimit = 50;
|
||||||
for (int i = 0; i < noteCount; i += paginateLimit) {
|
for (int i = 0; i < noteCount; i += paginateLimit) {
|
||||||
final labelIds = await getTransactionNotes(walletId).offset(i).limit(paginateLimit).idProperty().findAll();
|
final labelIds = await getTransactionNotes(walletId)
|
||||||
|
.offset(i)
|
||||||
|
.limit(paginateLimit)
|
||||||
|
.idProperty()
|
||||||
|
.findAll();
|
||||||
await isar.transactionNotes.deleteAll(labelIds);
|
await isar.transactionNotes.deleteAll(labelIds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -436,7 +480,8 @@ class MainDB {
|
||||||
|
|
||||||
// eth contracts
|
// eth contracts
|
||||||
|
|
||||||
QueryBuilder<EthContract, EthContract, QWhere> getEthContracts() => isar.ethContracts.where();
|
QueryBuilder<EthContract, EthContract, QWhere> getEthContracts() =>
|
||||||
|
isar.ethContracts.where();
|
||||||
|
|
||||||
Future<EthContract?> getEthContract(String contractAddress) =>
|
Future<EthContract?> getEthContract(String contractAddress) =>
|
||||||
isar.ethContracts.where().addressEqualTo(contractAddress).findFirst();
|
isar.ethContracts.where().addressEqualTo(contractAddress).findFirst();
|
||||||
|
@ -448,7 +493,8 @@ class MainDB {
|
||||||
return await isar.ethContracts.put(contract);
|
return await isar.ethContracts.put(contract);
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<void> putEthContracts(List<EthContract> contracts) => isar.writeTxn(() async {
|
Future<void> putEthContracts(List<EthContract> contracts) =>
|
||||||
|
isar.writeTxn(() async {
|
||||||
await isar.ethContracts.putAll(contracts);
|
await isar.ethContracts.putAll(contracts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue