frost db tx fix and some lint clean up

This commit is contained in:
julian 2024-05-13 08:10:53 -06:00
parent c9ea423495
commit 032a507e72

View file

@ -180,10 +180,12 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
final config = Frost.createSignConfig( final config = Frost.createSignConfig(
network: network, network: network,
inputs: utxosToUse inputs: utxosToUse
.map((e) => ( .map(
utxo: e, (e) => (
scriptPubKey: publicKey, utxo: e,
)) scriptPubKey: publicKey,
),
)
.toList(), .toList(),
outputs: txData.recipients!, outputs: txData.recipients!,
changeAddress: (await getCurrentReceivingAddress())!.value, changeAddress: (await getCurrentReceivingAddress())!.value,
@ -278,8 +280,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
Amount _roughFeeEstimate(int inputCount, int outputCount, int feeRatePerKB) { Amount _roughFeeEstimate(int inputCount, int outputCount, int feeRatePerKB) {
return Amount( return Amount(
rawValue: BigInt.from( rawValue: BigInt.from(
((42 + (272 * inputCount) + (128 * outputCount)) / 4).ceil() * ((42 + (272 * inputCount) + (128 * outputCount)) / 4).ceil() *
(feeRatePerKB / 1000).ceil()), (feeRatePerKB / 1000).ceil(),
),
fractionDigits: cryptoCurrency.fractionDigits, fractionDigits: cryptoCurrency.fractionDigits,
); );
} }
@ -333,7 +336,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
final currentHeight = await chainHeight; final currentHeight = await chainHeight;
final coin = info.coin; final coin = info.coin;
List<Map<String, dynamic>> allTransactions = []; final List<Map<String, dynamic>> allTransactions = [];
for (final txHash in allTxHashes) { for (final txHash in allTxHashes) {
final storedTx = await mainDB.isar.transactionV2s final storedTx = await mainDB.isar.transactionV2s
@ -390,8 +393,8 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
); );
final prevOutJson = Map<String, dynamic>.from( final prevOutJson = Map<String, dynamic>.from(
(inputTx["vout"] as List).firstWhere((e) => e["n"] == vout) (inputTx["vout"] as List).firstWhere((e) => e["n"] == vout) as Map,
as Map); );
final prevOut = OutputV2.fromElectrumXJson( final prevOut = OutputV2.fromElectrumXJson(
prevOutJson, prevOutJson,
@ -456,7 +459,8 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
TransactionSubType subType = TransactionSubType.none; TransactionSubType subType = TransactionSubType.none;
if (outputs.length > 1 && inputs.isNotEmpty) { if (outputs.length > 1 && inputs.isNotEmpty) {
for (int i = 0; i < outputs.length; i++) { for (int i = 0; i < outputs.length; i++) {
List<String>? scriptChunks = outputs[i].scriptPubKeyAsm?.split(" "); final List<String>? scriptChunks =
outputs[i].scriptPubKeyAsm?.split(" ");
if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") { if (scriptChunks?.length == 2 && scriptChunks?[0] == "OP_RETURN") {
final blindedPaymentCode = scriptChunks![1]; final blindedPaymentCode = scriptChunks![1];
final bytes = blindedPaymentCode.toUint8ListFromHex; final bytes = blindedPaymentCode.toUint8ListFromHex;
@ -575,8 +579,10 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
return txData; return txData;
} catch (e, s) { } catch (e, s) {
Logging.instance.log("Exception rethrown from confirmSend(): $e\n$s", Logging.instance.log(
level: LogLevel.Error); "Exception rethrown from confirmSend(): $e\n$s",
level: LogLevel.Error,
);
rethrow; rethrow;
} }
} }
@ -685,7 +691,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
multisigConfig = await getMultisigConfig(); multisigConfig = await getMultisigConfig();
} }
if (serializedKeys == null || multisigConfig == null) { if (serializedKeys == null || multisigConfig == null) {
String err = "${info.coinName} wallet ${info.walletId} had null keys/cfg"; final err = "${info.coinName} wallet ${info.walletId} had null keys/cfg";
Logging.instance.log(err, level: LogLevel.Fatal); Logging.instance.log(err, level: LogLevel.Fatal);
throw Exception(err); throw Exception(err);
// TODO [prio=low]: handle null keys or config. This should not happen. // TODO [prio=low]: handle null keys or config. This should not happen.
@ -713,7 +719,7 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
if (knownSalts.contains(salt)) { if (knownSalts.contains(salt)) {
throw Exception("Known frost multisig salt found!"); throw Exception("Known frost multisig salt found!");
} }
List<String> updatedKnownSalts = List<String>.from(knownSalts); final List<String> updatedKnownSalts = List<String>.from(knownSalts);
updatedKnownSalts.add(salt); updatedKnownSalts.add(salt);
await _updateKnownSalts(updatedKnownSalts); await _updateKnownSalts(updatedKnownSalts);
} else { } else {
@ -1015,8 +1021,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
.findFirstSync()!; .findFirstSync()!;
Future<void> _updateParticipants(List<String> participants) async { Future<void> _updateParticipants(List<String> participants) async {
final info = frostInfo;
await mainDB.isar.writeTxn(() async { await mainDB.isar.writeTxn(() async {
final info = frostInfo;
await mainDB.isar.frostWalletInfo.delete(info.id); await mainDB.isar.frostWalletInfo.delete(info.id);
await mainDB.isar.frostWalletInfo.put( await mainDB.isar.frostWalletInfo.put(
info.copyWith(participants: participants), info.copyWith(participants: participants),
@ -1031,8 +1038,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
.findFirstSync()!; .findFirstSync()!;
Future<void> _updateThreshold(int threshold) async { Future<void> _updateThreshold(int threshold) async {
final info = frostInfo;
await mainDB.isar.writeTxn(() async { await mainDB.isar.writeTxn(() async {
final info = frostInfo;
await mainDB.isar.frostWalletInfo.delete(info.id); await mainDB.isar.frostWalletInfo.delete(info.id);
await mainDB.isar.frostWalletInfo.put( await mainDB.isar.frostWalletInfo.put(
info.copyWith(threshold: threshold), info.copyWith(threshold: threshold),
@ -1047,8 +1055,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
.findFirstSync()!; .findFirstSync()!;
Future<void> _updateMyName(String myName) async { Future<void> _updateMyName(String myName) async {
final info = frostInfo;
await mainDB.isar.writeTxn(() async { await mainDB.isar.writeTxn(() async {
final info = frostInfo;
await mainDB.isar.frostWalletInfo.delete(info.id); await mainDB.isar.frostWalletInfo.delete(info.id);
await mainDB.isar.frostWalletInfo.put( await mainDB.isar.frostWalletInfo.put(
info.copyWith(myName: myName), info.copyWith(myName: myName),
@ -1074,13 +1083,15 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
Future<void> _updateElectrumX() async { Future<void> _updateElectrumX() async {
final failovers = nodeService final failovers = nodeService
.failoverNodesFor(coin: cryptoCurrency.coin) .failoverNodesFor(coin: cryptoCurrency.coin)
.map((e) => ElectrumXNode( .map(
address: e.host, (e) => ElectrumXNode(
port: e.port, address: e.host,
name: e.name, port: e.port,
id: e.id, name: e.name,
useSSL: e.useSSL, id: e.id,
)) useSSL: e.useSSL,
),
)
.toList(); .toList();
final newNode = await _getCurrentElectrumXNode(); final newNode = await _getCurrentElectrumXNode();
@ -1109,7 +1120,9 @@ class BitcoinFrostWallet<T extends FrostCurrency> extends Wallet<T> {
} }
bool _duplicateTxCheck( bool _duplicateTxCheck(
List<Map<String, dynamic>> allTransactions, String txid) { List<Map<String, dynamic>> allTransactions,
String txid,
) {
for (int i = 0; i < allTransactions.length; i++) { for (int i = 0; i < allTransactions.length; i++) {
if (allTransactions[i]["txid"] == txid) { if (allTransactions[i]["txid"] == txid) {
return true; return true;