stack_wallet/lib/utilities/block_explorers.dart

72 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/block_explorer.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/enums/coin_enum.dart';
2023-05-04 18:10:37 +00:00
Uri getDefaultBlockExplorerUrlFor({
2022-08-26 08:11:35 +00:00
required Coin coin,
required String txid,
}) {
switch (coin) {
case Coin.bitcoin:
return Uri.parse("https://mempool.space/tx/$txid");
2022-10-28 18:03:52 +00:00
case Coin.litecoin:
return Uri.parse("https://chain.so/tx/LTC/$txid");
case Coin.litecoinTestNet:
return Uri.parse("https://chain.so/tx/LTCTEST/$txid");
2022-08-26 08:11:35 +00:00
case Coin.bitcoinTestNet:
return Uri.parse("https://mempool.space/testnet/tx/$txid");
2022-08-26 08:11:35 +00:00
case Coin.dogecoin:
return Uri.parse("https://chain.so/tx/DOGE/$txid");
case Coin.dogecoinTestNet:
return Uri.parse("https://chain.so/tx/DOGETEST/$txid");
case Coin.epicCash:
// TODO: Handle this case.
2022-08-26 08:11:35 +00:00
throw UnimplementedError("missing block explorer for epic cash");
2022-12-13 17:39:19 +00:00
case Coin.ethereum:
return Uri.parse("https://etherscan.io/tx/$txid");
2022-08-26 08:11:35 +00:00
case Coin.monero:
return Uri.parse("https://xmrchain.net/tx/$txid");
2022-09-27 08:09:31 +00:00
case Coin.wownero:
return Uri.parse("https://explore.wownero.com/search?value=$txid");
2022-08-26 08:11:35 +00:00
case Coin.firo:
return Uri.parse("https://explorer.firo.org/tx/$txid");
case Coin.firoTestNet:
return Uri.parse("https://testexplorer.firo.org/tx/$txid");
2022-09-26 20:32:53 +00:00
case Coin.bitcoincash:
return Uri.parse("https://blockchair.com/bitcoin-cash/transaction/$txid");
case Coin.bitcoincashTestnet:
return Uri.parse(
"https://blockexplorer.one/bitcoin-cash/testnet/tx/$txid");
2022-09-23 21:02:53 +00:00
case Coin.namecoin:
return Uri.parse("https://chainz.cryptoid.info/nmc/tx.dws?$txid.htm");
2022-10-25 15:06:37 +00:00
case Coin.particl:
return Uri.parse("https://chainz.cryptoid.info/part/tx.dws?$txid.htm");
2022-08-26 08:11:35 +00:00
}
}
2023-05-04 18:10:37 +00:00
/// returns internal Isar ID for the inserted object/record
Future<int> setBlockExplorerForCoin({
required Coin coin,
required Uri url,
}) async {
return await MainDB.instance.putTransactionBlockExplorer(
TransactionBlockExplorer(
ticker: coin.ticker,
url: url.toString(),
),
);
2023-05-04 18:10:37 +00:00
}
Uri getBlockExplorerTransactionUrlFor({
required Coin coin,
required String txid,
}) {
String? url = MainDB.instance.getTransactionBlockExplorer(coin: coin)?.url;
2023-05-04 18:10:37 +00:00
if (url == null) {
return getDefaultBlockExplorerUrlFor(coin: coin, txid: txid);
} else {
url = url.replaceAll("%5BTXID%5D", txid);
2023-05-05 17:30:22 +00:00
return Uri.parse(url);
2023-05-04 18:10:37 +00:00
}
}