UTXOTransaction.create constructor
Implementation
factory UTXOTransaction.create({
required Map<String, dynamic> json,
required UTXONetworkType type,
required Iterable<AddressType> addressTypes,
required Iterable<NodeWithAddress> nodes,
required Iterable<ElectrumOutput> spentOutputs,
}) {
final coin = type.coin;
final id = json['txid'] as String;
//final hash = json['hash'] as String;
final inputs = (json['vin'] as List<dynamic>)
.map((e) => ElectrumInput.fromJson(e as Map<String, dynamic>))
.toList();
final rawOutputs = (json['vout'] as List<dynamic>)
.map((e) => ElectrumOutput.fromJson(e as Map<String, dynamic>))
.toList();
final outputs = findOurOwnCoins(rawOutputs, nodes, addressTypes, type);
final sender = inputs.first.getAddress(
type,
addressType: addressTypes.first,
);
final transferMethod = determineSendDirection(
inputs: inputs,
outputs: outputs,
nodes: nodes,
type: type,
addressTypes: addressTypes,
);
final (value, totalOutputValue) = determineTransactionValue(
outputs,
transferMethod,
nodes,
type,
);
final totalInputValue = spentOutputs.fold(
BigInt.zero,
(prev, spentOutput) => prev + spentOutput.value,
);
final fee_int = json['fee_int'] as int?;
var fee = fee_int != null ? BigInt.from(fee_int) : null;
fee ??= spentOutputs.isEmpty ? null : totalInputValue - totalOutputValue;
final recipient = determineTransactionTarget(
outputs,
transferMethod,
type,
addressTypes.first,
) ??
ADDRESS_NOT_SUPPORTED;
//final blockHash = json['blockhash'] as String;
final timestamp = (json['time'] ?? -1) * 1000;
final height = int.tryParse(json['height'].toString()) ?? -1;
final confirmations = int.tryParse(json['confirmations'].toString()) ?? -1;
final version = json['version'] as int;
return UTXOTransaction(
block: height,
fee: fee != null ? Amount(value: fee, decimals: coin.decimals) : null,
hash: id,
timeMilli: timestamp,
amount: Amount(value: value, decimals: coin.decimals),
sender: sender,
recipient: recipient,
token: coin,
transferMethod: transferMethod,
confirmations: confirmations,
inputs: inputs,
outputs: outputs,
id: id,
version: version,
status: ConfirmationStatus.fromConfirmations(confirmations),
);
}