mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
custom block explorer isar model/schema
This commit is contained in:
parent
e75c74b3c4
commit
e3c0f58abc
2 changed files with 56 additions and 0 deletions
|
@ -2,6 +2,7 @@ import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter_native_splash/cli_commands.dart';
|
import 'package:flutter_native_splash/cli_commands.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stackwallet/exceptions/main_db/main_db_exception.dart';
|
import 'package:stackwallet/exceptions/main_db/main_db_exception.dart';
|
||||||
|
import 'package:stackwallet/models/isar/models/block_explorer.dart';
|
||||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -33,6 +34,7 @@ class MainDB {
|
||||||
AddressSchema,
|
AddressSchema,
|
||||||
AddressLabelSchema,
|
AddressLabelSchema,
|
||||||
EthContractSchema,
|
EthContractSchema,
|
||||||
|
TransactionBlockExplorerSchema,
|
||||||
],
|
],
|
||||||
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
directory: (await StackFileSystem.applicationIsarDirectory()).path,
|
||||||
// inspector: kDebugMode,
|
// inspector: kDebugMode,
|
||||||
|
@ -43,6 +45,25 @@ class MainDB {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tx block explorers
|
||||||
|
TransactionBlockExplorer? getTransactionBlockExplorer({required Coin coin}) {
|
||||||
|
return isar.transactionBlockExplorers
|
||||||
|
.where()
|
||||||
|
.tickerEqualTo(coin.ticker)
|
||||||
|
.findFirstSync();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<int> putTransactionBlockExplorer(
|
||||||
|
TransactionBlockExplorer explorer) async {
|
||||||
|
try {
|
||||||
|
return await isar.writeTxn(() async {
|
||||||
|
return await isar.transactionBlockExplorers.put(explorer);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
throw MainDBException("failed putTransactionBlockExplorer: $explorer", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
QueryBuilder<Address, Address, QAfterWhereClause> getAddresses(
|
QueryBuilder<Address, Address, QAfterWhereClause> getAddresses(
|
||||||
String walletId) =>
|
String walletId) =>
|
||||||
|
|
35
lib/models/isar/models/block_explorer.dart
Normal file
35
lib/models/isar/models/block_explorer.dart
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import 'package:isar/isar.dart';
|
||||||
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
|
||||||
|
part 'block_explorer.g.dart';
|
||||||
|
|
||||||
|
@collection
|
||||||
|
class TransactionBlockExplorer {
|
||||||
|
TransactionBlockExplorer({
|
||||||
|
required this.ticker,
|
||||||
|
required this.url,
|
||||||
|
});
|
||||||
|
|
||||||
|
Id id = Isar.autoIncrement;
|
||||||
|
|
||||||
|
@Index(unique: true, replace: true)
|
||||||
|
late final String ticker;
|
||||||
|
|
||||||
|
late final String url;
|
||||||
|
|
||||||
|
@ignore
|
||||||
|
Coin? get coin {
|
||||||
|
try {
|
||||||
|
return coinFromTickerCaseInsensitive(ticker);
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri? getUrlFor({required String txid}) => Uri.tryParse(
|
||||||
|
url.replaceFirst(
|
||||||
|
"%5BTXID%5D",
|
||||||
|
txid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue