transactionDecoder function

Map<String, dynamic> transactionDecoder(
  1. String txnHash
)

Implementation

Map<String, dynamic> transactionDecoder(String txnHash) {
  final envelopes = cborDecode(blobFromHex(txnHash));
  assert(envelopes.length == 1);

  final envelope = envelopes[0][0];
  assert(envelope['content']['request_type'] == 'call');
  assert(envelope['content']['method_name'] == 'send_pb');
  final content = envelope['content'] as Map;
  final senderPubkey = envelope['sender_pubkey'];
  final sendArgs = SendRequest.fromBuffer(content['arg']);
  final senderAddress = Principal(Uint8List.fromList(content['sender']));
  final hash = SHA224()
    ..update(('\x0Aaccount-id').plainToU8a())
    ..update(senderAddress.toUint8List())
    ..update(Uint8List(32));
  return {
    'from': hash.digest(),
    'to': Uint8List.fromList(sendArgs.to.hash.sublist(4)),
    'amount': BigInt.parse(sendArgs.payment.receiverGets.e8s.toRadixString(10)),
    'fee': BigInt.parse(sendArgs.maxFee.e8s.toRadixString(10)),
    'sender_pubkey': Uint8List.fromList(senderPubkey).sublist(
      Uint8List.fromList(senderPubkey).byteLength - _tweetNaclSignedPubLength,
    ),
  };
}