From ab07b9c80e250495cd03156506ac38dd25a3bba8 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 5 Jun 2023 16:25:54 -0600 Subject: [PATCH] fix: auto save formatting --- lib/db/isar/main_db.dart | 100 ++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 27 deletions(-) diff --git a/lib/db/isar/main_db.dart b/lib/db/isar/main_db.dart index fe9d29539..ed73c398d 100644 --- a/lib/db/isar/main_db.dart +++ b/lib/db/isar/main_db.dart @@ -81,7 +81,11 @@ class MainDB { } Future 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}) { @@ -101,10 +105,14 @@ class MainDB { // tx block explorers TransactionBlockExplorer? getTransactionBlockExplorer({required Coin coin}) { - return isar.transactionBlockExplorers.where().tickerEqualTo(coin.ticker).findFirstSync(); + return isar.transactionBlockExplorers + .where() + .tickerEqualTo(coin.ticker) + .findFirstSync(); } - Future putTransactionBlockExplorer(TransactionBlockExplorer explorer) async { + Future putTransactionBlockExplorer( + TransactionBlockExplorer explorer) async { try { return await isar.writeTxn(() async { return await isar.transactionBlockExplorers.put(explorer); @@ -115,7 +123,8 @@ class MainDB { } // addresses - QueryBuilder getAddresses(String walletId) => + QueryBuilder getAddresses( + String walletId) => isar.addresses.where().walletIdEqualTo(walletId); Future putAddress(Address address) async { @@ -143,7 +152,8 @@ class MainDB { List ids = []; await isar.writeTxn(() async { 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; if (storedAddress == null) { @@ -183,12 +193,14 @@ class MainDB { return id; }); } catch (e) { - throw MainDBException("failed updateAddress: from=$oldAddress to=$newAddress", e); + throw MainDBException( + "failed updateAddress: from=$oldAddress to=$newAddress", e); } } // transactions - QueryBuilder getTransactions(String walletId) => + QueryBuilder getTransactions( + String walletId) => isar.transactions.where().walletIdEqualTo(walletId); Future putTransaction(Transaction transaction) async { @@ -223,7 +235,8 @@ class MainDB { } // utxos - QueryBuilder getUTXOs(String walletId) => isar.utxos.where().walletIdEqualTo(walletId); + QueryBuilder getUTXOs(String walletId) => + isar.utxos.where().walletIdEqualTo(walletId); Future putUTXO(UTXO utxo) => isar.writeTxn(() async { await isar.utxos.put(utxo); @@ -238,8 +251,10 @@ class MainDB { final set = utxos.toSet(); for (final utxo in utxos) { // check if utxo exists in db and update accordingly - final storedUtxo = - await isar.utxos.where().txidWalletIdVoutEqualTo(utxo.txid, utxo.walletId, utxo.vout).findFirst(); + final storedUtxo = await isar.utxos + .where() + .txidWalletIdVoutEqualTo(utxo.txid, utxo.walletId, utxo.vout) + .findFirst(); if (storedUtxo != null) { // update @@ -269,18 +284,22 @@ class MainDB { } // transaction notes - QueryBuilder getTransactionNotes(String walletId) => - isar.transactionNotes.where().walletIdEqualTo(walletId); + QueryBuilder + getTransactionNotes(String walletId) => + isar.transactionNotes.where().walletIdEqualTo(walletId); - Future putTransactionNote(TransactionNote transactionNote) => isar.writeTxn(() async { + Future putTransactionNote(TransactionNote transactionNote) => + isar.writeTxn(() async { await isar.transactionNotes.put(transactionNote); }); - Future putTransactionNotes(List transactionNotes) => isar.writeTxn(() async { + Future putTransactionNotes(List transactionNotes) => + isar.writeTxn(() async { await isar.transactionNotes.putAll(transactionNotes); }); - Future getTransactionNote(String walletId, String txid) async { + Future getTransactionNote( + String walletId, String txid) async { return isar.transactionNotes.getByTxidWalletId( txid, walletId, @@ -291,14 +310,17 @@ class MainDB { required Id id, bool fireImmediately = false, }) { - return isar.transactionNotes.watchObject(id, fireImmediately: fireImmediately); + return isar.transactionNotes + .watchObject(id, fireImmediately: fireImmediately); } // address labels - QueryBuilder getAddressLabels(String walletId) => + QueryBuilder getAddressLabels( + String walletId) => isar.addressLabels.where().walletIdEqualTo(walletId); - Future putAddressLabel(AddressLabel addressLabel) => isar.writeTxn(() async { + Future putAddressLabel(AddressLabel addressLabel) => + isar.writeTxn(() async { return await isar.addressLabels.put(addressLabel); }); @@ -306,11 +328,13 @@ class MainDB { return isar.addressLabels.putSync(addressLabel); }); - Future putAddressLabels(List addressLabels) => isar.writeTxn(() async { + Future putAddressLabels(List addressLabels) => + isar.writeTxn(() async { await isar.addressLabels.putAll(addressLabels); }); - Future getAddressLabel(String walletId, String addressString) async { + Future getAddressLabel( + String walletId, String addressString) async { return isar.addressLabels.getByAddressStringWalletId( addressString, walletId, @@ -352,19 +376,31 @@ class MainDB { // transactions 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); } // addresses 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); } // utxos 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); } }); @@ -375,7 +411,11 @@ class MainDB { await isar.writeTxn(() async { const paginateLimit = 50; 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); } }); @@ -386,7 +426,11 @@ class MainDB { await isar.writeTxn(() async { const paginateLimit = 50; 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); } }); @@ -436,7 +480,8 @@ class MainDB { // eth contracts - QueryBuilder getEthContracts() => isar.ethContracts.where(); + QueryBuilder getEthContracts() => + isar.ethContracts.where(); Future getEthContract(String contractAddress) => isar.ethContracts.where().addressEqualTo(contractAddress).findFirst(); @@ -448,7 +493,8 @@ class MainDB { return await isar.ethContracts.put(contract); }); - Future putEthContracts(List contracts) => isar.writeTxn(() async { + Future putEthContracts(List contracts) => + isar.writeTxn(() async { await isar.ethContracts.putAll(contracts); }); }