toRequest method

TronRequestDetails toRequest(
  1. int _
)

Converts the request parameters to TronRequestDetails with a unique identifier.

Implementation

TronRequestDetails toRequest(int _) {
  final inJson = toJson();
  inJson.removeWhere((key, value) => value == null);
  final Map<String, BigInt> replace = {};
  int id = 0;
  final encoder = JsonEncoder(
    (object) {
      if (object is TronAddress) {
        return object.toAddress(visible ?? true);
      }
      object as BigInt;
      if (object.isValidInt) {
        return object.toInt();
      }
      id++;
      final n = "$id#${object.toString()}";
      replace[n] = object;

      return n;
    },
  );

  String encode = encoder.convert(inJson);
  for (final i in replace.entries) {
    encode = encode.replaceFirst('"${i.key}"', "${i.value}");
  }
  return TronRequestDetails(id: id, method: method, params: encode);
}