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);

  var envelope = envelopes[0][0];
  assert(envelope["content"]["request_type"] == "call");
  assert(envelope["content"]["method_name"] == "send_pb");
  var content = envelope["content"] as Map;
  var senderPubkey = envelope["sender_pubkey"];
  var sendArgs = SendRequest.fromBuffer(content["arg"]);
  var senderAddress = Principal.fromBlob(Uint8List.fromList(content["sender"]));
  final hash = SHA224()
    ..update(('\x0Aaccount-id').plainToU8a())
    ..update(senderAddress.toBlob())
    ..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),
  };
}