stack_wallet/lib/wallets/models/tx_data.dart

303 lines
8.8 KiB
Dart
Raw Normal View History

import 'package:cw_monero/pending_monero_transaction.dart';
2023-11-06 21:37:18 +00:00
import 'package:cw_wownero/pending_wownero_transaction.dart';
2024-06-16 19:25:07 +00:00
import 'package:tezart/tezart.dart' as tezart;
import 'package:web3dart/web3dart.dart' as web3dart;
import '../../models/isar/models/blockchain_data/v2/transaction_v2.dart';
import '../../models/isar/models/isar_models.dart';
import '../../models/paynym/paynym_account_lite.dart';
import '../../utilities/amount/amount.dart';
import '../../utilities/enums/fee_rate_type_enum.dart';
import '../isar/models/spark_coin.dart';
2024-06-18 23:38:47 +00:00
typedef TxRecipient = ({String address, Amount amount, bool isChange});
class TxData {
final FeeRateType? feeRateType;
final int? feeRateAmount;
final int? satsPerVByte;
final Amount? fee;
final int? vSize;
final String? raw;
final String? txid;
final String? txHash;
final String? note;
final String? noteOnChain;
final String? memo;
2024-06-18 23:38:47 +00:00
final List<TxRecipient>? recipients;
final Set<UTXO>? utxos;
final List<UTXO>? usedUTXOs;
final String? changeAddress;
2024-05-02 22:43:02 +00:00
// frost specific
final String? frostMSConfig;
2024-05-02 22:43:02 +00:00
final List<String>? frostSigners;
// paynym specific
final PaynymAccountLite? paynymAccountLite;
// eth token specific
final web3dart.Transaction? web3dartTransaction;
final int? nonce;
final BigInt? chainId;
final BigInt? feeInWei;
2023-11-06 21:37:18 +00:00
// wownero specific
final PendingWowneroTransaction? pendingWowneroTransaction;
// monero specific
final PendingMoneroTransaction? pendingMoneroTransaction;
2023-11-20 15:15:36 +00:00
// firo lelantus specific
final int? jMintValue;
final List<int>? spendCoinIndexes;
final int? height;
final TransactionType? txType;
final TransactionSubType? txSubType;
final List<Map<String, dynamic>>? mintsMapLelantus;
2023-11-20 19:55:22 +00:00
// tezos specific
final tezart.OperationsList? tezosOperationsList;
2023-12-13 17:26:30 +00:00
// firo spark specific
final List<
({
String address,
Amount amount,
String memo,
2024-01-05 19:45:42 +00:00
bool isChange,
2023-12-13 17:26:30 +00:00
})>? sparkRecipients;
final List<TxData>? sparkMints;
final List<SparkCoin>? usedSparkCoins;
2023-12-13 17:26:30 +00:00
final TransactionV2? tempTx;
2024-06-16 19:25:07 +00:00
final bool ignoreCachedBalanceChecks;
TxData({
this.feeRateType,
this.feeRateAmount,
this.satsPerVByte,
this.fee,
this.vSize,
this.raw,
this.txid,
this.txHash,
this.note,
this.noteOnChain,
this.memo,
this.recipients,
this.utxos,
this.usedUTXOs,
this.changeAddress,
this.frostMSConfig,
2024-05-02 22:43:02 +00:00
this.frostSigners,
this.paynymAccountLite,
this.web3dartTransaction,
this.nonce,
this.chainId,
this.feeInWei,
2023-11-06 21:37:18 +00:00
this.pendingWowneroTransaction,
this.pendingMoneroTransaction,
2023-11-20 15:15:36 +00:00
this.jMintValue,
this.spendCoinIndexes,
this.height,
this.txType,
this.txSubType,
this.mintsMapLelantus,
2023-11-20 19:55:22 +00:00
this.tezosOperationsList,
2023-12-13 17:26:30 +00:00
this.sparkRecipients,
this.sparkMints,
this.usedSparkCoins,
this.tempTx,
2024-06-16 19:25:07 +00:00
this.ignoreCachedBalanceChecks = false,
});
Amount? get amount => recipients != null && recipients!.isNotEmpty
? recipients!
.map((e) => e.amount)
.reduce((total, amount) => total += amount)
: null;
2023-12-21 00:00:02 +00:00
Amount? get amountSpark =>
sparkRecipients != null && sparkRecipients!.isNotEmpty
? sparkRecipients!
.map((e) => e.amount)
.reduce((total, amount) => total += amount)
: null;
Amount? get amountWithoutChange {
if (recipients != null && recipients!.isNotEmpty) {
if (recipients!.where((e) => !e.isChange).isEmpty) {
return Amount(
rawValue: BigInt.zero,
fractionDigits: recipients!.first.amount.fractionDigits,
);
} else {
return recipients!
.where((e) => !e.isChange)
.map((e) => e.amount)
.reduce((total, amount) => total += amount);
}
} else {
return null;
}
}
Amount? get amountSparkWithoutChange {
if (sparkRecipients != null && sparkRecipients!.isNotEmpty) {
if (sparkRecipients!.where((e) => !e.isChange).isEmpty) {
return Amount(
rawValue: BigInt.zero,
fractionDigits: sparkRecipients!.first.amount.fractionDigits,
);
} else {
return sparkRecipients!
.where((e) => !e.isChange)
.map((e) => e.amount)
.reduce((total, amount) => total += amount);
}
} else {
return null;
}
}
2024-01-05 19:45:42 +00:00
int? get estimatedSatsPerVByte => fee != null && vSize != null
? (fee!.raw ~/ BigInt.from(vSize!)).toInt()
: null;
TxData copyWith({
FeeRateType? feeRateType,
int? feeRateAmount,
int? satsPerVByte,
Amount? fee,
int? vSize,
String? raw,
String? txid,
String? txHash,
String? note,
String? noteOnChain,
String? memo,
Set<UTXO>? utxos,
List<UTXO>? usedUTXOs,
2024-06-18 23:38:47 +00:00
List<TxRecipient>? recipients,
String? frostMSConfig,
2024-05-02 22:43:02 +00:00
List<String>? frostSigners,
String? changeAddress,
PaynymAccountLite? paynymAccountLite,
web3dart.Transaction? web3dartTransaction,
int? nonce,
BigInt? chainId,
BigInt? feeInWei,
2023-11-06 21:37:18 +00:00
PendingWowneroTransaction? pendingWowneroTransaction,
PendingMoneroTransaction? pendingMoneroTransaction,
2023-11-20 15:15:36 +00:00
int? jMintValue,
List<int>? spendCoinIndexes,
int? height,
TransactionType? txType,
TransactionSubType? txSubType,
List<Map<String, dynamic>>? mintsMapLelantus,
2023-11-20 19:55:22 +00:00
tezart.OperationsList? tezosOperationsList,
2023-12-13 17:26:30 +00:00
List<
({
String address,
Amount amount,
String memo,
2024-01-05 19:45:42 +00:00
bool isChange,
2023-12-13 17:26:30 +00:00
})>?
sparkRecipients,
List<TxData>? sparkMints,
List<SparkCoin>? usedSparkCoins,
TransactionV2? tempTx,
2024-06-16 19:25:07 +00:00
bool? ignoreCachedBalanceChecks,
}) {
return TxData(
feeRateType: feeRateType ?? this.feeRateType,
feeRateAmount: feeRateAmount ?? this.feeRateAmount,
satsPerVByte: satsPerVByte ?? this.satsPerVByte,
fee: fee ?? this.fee,
vSize: vSize ?? this.vSize,
raw: raw ?? this.raw,
txid: txid ?? this.txid,
txHash: txHash ?? this.txHash,
note: note ?? this.note,
noteOnChain: noteOnChain ?? this.noteOnChain,
memo: memo ?? this.memo,
utxos: utxos ?? this.utxos,
usedUTXOs: usedUTXOs ?? this.usedUTXOs,
recipients: recipients ?? this.recipients,
frostMSConfig: frostMSConfig ?? this.frostMSConfig,
2024-05-02 22:43:02 +00:00
frostSigners: frostSigners ?? this.frostSigners,
changeAddress: changeAddress ?? this.changeAddress,
paynymAccountLite: paynymAccountLite ?? this.paynymAccountLite,
web3dartTransaction: web3dartTransaction ?? this.web3dartTransaction,
nonce: nonce ?? this.nonce,
chainId: chainId ?? this.chainId,
feeInWei: feeInWei ?? this.feeInWei,
2023-11-06 21:37:18 +00:00
pendingWowneroTransaction:
pendingWowneroTransaction ?? this.pendingWowneroTransaction,
pendingMoneroTransaction:
pendingMoneroTransaction ?? this.pendingMoneroTransaction,
2023-11-20 15:15:36 +00:00
jMintValue: jMintValue ?? this.jMintValue,
spendCoinIndexes: spendCoinIndexes ?? this.spendCoinIndexes,
height: height ?? this.height,
txType: txType ?? this.txType,
txSubType: txSubType ?? this.txSubType,
mintsMapLelantus: mintsMapLelantus ?? this.mintsMapLelantus,
2023-11-20 19:55:22 +00:00
tezosOperationsList: tezosOperationsList ?? this.tezosOperationsList,
2023-12-13 17:26:30 +00:00
sparkRecipients: sparkRecipients ?? this.sparkRecipients,
sparkMints: sparkMints ?? this.sparkMints,
usedSparkCoins: usedSparkCoins ?? this.usedSparkCoins,
tempTx: tempTx ?? this.tempTx,
2024-06-16 19:25:07 +00:00
ignoreCachedBalanceChecks:
ignoreCachedBalanceChecks ?? this.ignoreCachedBalanceChecks,
);
}
@override
String toString() => 'TxData{'
'feeRateType: $feeRateType, '
'feeRateAmount: $feeRateAmount, '
'satsPerVByte: $satsPerVByte, '
'fee: $fee, '
'vSize: $vSize, '
'raw: $raw, '
'txid: $txid, '
'txHash: $txHash, '
'note: $note, '
'noteOnChain: $noteOnChain, '
'memo: $memo, '
'recipients: $recipients, '
'utxos: $utxos, '
'usedUTXOs: $usedUTXOs, '
2024-05-02 22:43:02 +00:00
'frostSigners: $frostSigners, '
'changeAddress: $changeAddress, '
'paynymAccountLite: $paynymAccountLite, '
'web3dartTransaction: $web3dartTransaction, '
'nonce: $nonce, '
'chainId: $chainId, '
'feeInWei: $feeInWei, '
2023-11-06 21:37:18 +00:00
'pendingWowneroTransaction: $pendingWowneroTransaction, '
'pendingMoneroTransaction: $pendingMoneroTransaction, '
2023-11-20 15:15:36 +00:00
'jMintValue: $jMintValue, '
'spendCoinIndexes: $spendCoinIndexes, '
'height: $height, '
'txType: $txType, '
'txSubType: $txSubType, '
'mintsMapLelantus: $mintsMapLelantus, '
2023-11-20 19:55:22 +00:00
'tezosOperationsList: $tezosOperationsList, '
2023-12-13 17:26:30 +00:00
'sparkRecipients: $sparkRecipients, '
'sparkMints: $sparkMints, '
'usedSparkCoins: $usedSparkCoins, '
'tempTx: $tempTx, '
2024-06-16 19:25:07 +00:00
'ignoreCachedBalanceChecks: $ignoreCachedBalanceChecks, '
'}';
}