RosettaTransaction constructor

RosettaTransaction(
  1. Transaction rosettaTransaction,
  2. int blockIndex
)

Create a Transaction. @param {Any} rosettaTransaction The Rosetta Transaction object of the transaction. @param {Number} blockIndex The index of the block containing the transaction. milliseconds since the Unix Epoch.

Implementation

RosettaTransaction(
  rosetta.Transaction rosettaTransaction,
  this.blockIndex,
) : super(
        rosettaTransaction.transactionIdentifier,
        rosettaTransaction.operations,
        rosettaTransaction.metadata,
      ) {
  hash = rosettaTransaction.transactionIdentifier.hash;
  final timestampMs =
      BigInt.from(rosettaTransaction.metadata?['timestamp'] as int) ~/
          BigInt.from(1000000);
  timestamp = DateTime.fromMillisecondsSinceEpoch(timestampMs.toInt());
  final operations = rosettaTransaction.operations;
  if (operations.isNotEmpty) {
    final firstOperation = operations[0];
    type = firstOperation.type;
    status = firstOperation.status;
    account1Address = firstOperation.account?.address;
    BigInt amountValue = firstOperation.amount?.valueInBigInt ?? BigInt.zero;
    // Negate amount for TRANSACTION and BURN,
    // so that they appear in the UI as positive values.
    if ((type == 'TRANSACTION' || type == 'BURN') &&
        amountValue != BigInt.zero) {
      amountValue = -amountValue;
    }
    amount = amountValue;
  } else {
    type = null;
    status = null;
    account1Address = null;
    amount = BigInt.zero;
  }
  if (operations.length >= 2 && operations[1].type == 'TRANSACTION') {
    account2Address = operations[1].account?.address;
  } else {
    account2Address = null;
  }
  if (operations.length >= 3 && operations[2].type == 'FEE') {
    fee = (operations[2].amount?.valueInBigInt ?? BigInt.zero) * -BigInt.one;
    memo = null;
  } else {
    fee = BigInt.zero;
    memo = rosettaTransaction.metadata?['memo'] != null
        ? BigInt.parse(rosettaTransaction.metadata?['memo'] as String)
        : null;
  }
}