stack_wallet/lib/wallets/wallet/impl/namecoin_wallet.dart

99 lines
3.1 KiB
Dart
Raw Normal View History

import 'package:isar/isar.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/namecoin.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/wallets/wallet/intermediate/bip39_hd_wallet.dart';
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/coin_control_interface.dart';
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart';
2024-01-09 22:57:32 +00:00
import 'package:tuple/tuple.dart';
class NamecoinWallet extends Bip39HDWallet
with ElectrumXInterface, CoinControlInterface {
@override
int get isarTransactionVersion => 2;
NamecoinWallet(CryptoCurrencyNetwork network) : super(Namecoin(network));
@override
FilterOperation? get changeAddressFilterOperation =>
FilterGroup.and(standardChangeAddressFilters);
@override
FilterOperation? get receivingAddressFilterOperation =>
FilterGroup.and(standardReceivingAddressFilters);
// ===========================================================================
@override
Future<List<Address>> fetchAddressesForElectrumXScan() async {
final allAddresses = await mainDB
.getAddresses(walletId)
.filter()
.not()
.group(
(q) => q
.typeEqualTo(AddressType.nonWallet)
.or()
.subTypeEqualTo(AddressSubType.nonWallet),
)
.findAll();
return allAddresses;
}
// ===========================================================================
@override
2024-01-10 16:15:26 +00:00
Future<
({
bool blocked,
String? blockedReason,
String? utxoLabel,
})> checkBlockUTXO(
Map<String, dynamic> jsonUTXO,
String? scriptPubKeyHex,
Map<String, dynamic> jsonTX,
String? utxoOwnerAddress,
) async {
2024-01-09 22:57:32 +00:00
// Namecoin doesn't have special outputs like tokens, ordinals, etc.
return (blocked: false, blockedReason: null, utxoLabel: null);
}
@override
int estimateTxFee({required int vSize, required int feeRatePerKB}) {
2024-01-09 02:30:17 +00:00
return vSize * (feeRatePerKB / 1000).ceil();
}
2024-01-09 22:57:32 +00:00
// TODO: Check if this is the correct formula for namecoin.
@override
Amount roughFeeEstimate(int inputCount, int outputCount, int feeRatePerKB) {
2024-01-09 02:30:17 +00:00
return Amount(
rawValue: BigInt.from(
((42 + (272 * inputCount) + (128 * outputCount)) / 4).ceil() *
(feeRatePerKB / 1000).ceil()),
fractionDigits: cryptoCurrency.fractionDigits,
);
}
@override
2024-01-09 22:57:32 +00:00
Future<void> updateTransactions() async {
final currentChainHeight = await fetchChainHeight();
2024-01-10 16:15:26 +00:00
// TODO: [prio=high] switch to V2 transactions.
2024-01-09 22:57:32 +00:00
final data = await fetchTransactionsV1(
addresses: await fetchAddressesForElectrumXScan(),
currentChainHeight: currentChainHeight,
);
await mainDB.addNewTransactionData(
data
.map((e) => Tuple2(
e.transaction,
e.address,
))
.toList(),
walletId,
);
}
}