RosettaTransaction constructor

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

Implementation

RosettaTransaction(rosetta.Transaction rosettaTransaction, this.blockIndex)
    : super(rosettaTransaction.transaction_identifier,
          rosettaTransaction.operations, rosettaTransaction.metadata) {
  hash = rosettaTransaction.transaction_identifier.hash;
  var timestampMs =
      BigInt.from(rosettaTransaction.metadata?["timestamp"] as int) ~/
          BigInt.from(1000000);
  timestamp = DateTime.fromMillisecondsSinceEpoch(timestampMs.toInt());
  var operations = rosettaTransaction.operations;
  if (operations.isNotEmpty) {
    type = operations[0].type;
    status = operations[0].status;
    account1Address = operations[0].account?.address;

    amount = operations[0].amount != null
        ? BigInt.parse(operations[0].amount!.value)
        : null;
    // Negate amount for TRANSACTION and BURN, so that they appear in the UI as positive values.
    if ((operations[0].type == 'TRANSACTION' ||
            operations[0].type == 'BURN') &&
        amount! != BigInt.zero) {
      amount = -amount!;
    }
  } else {
    type = '';
    status = '';
    account1Address = '';
    amount = BigInt.zero;
  }
  if (operations.length >= 2 && operations[1].type == 'TRANSACTION') {
    account2Address = operations[1].account?.address;
  } else {
    account2Address = '';
  }

  if (operations.length >= 3 && operations[2].type == 'FEE') {
    fee = operations[2].amount?.value != null
        ? -BigInt.parse(operations[2].amount!.value)
        : null;
  } else {
    fee = BigInt.zero;
    memo = rosettaTransaction.metadata?["memo"] != null
        ? BigInt.parse(rosettaTransaction.metadata?["memo"] as String)
        : null;
  }
}