TronAddress constructor

TronAddress(
  1. String address, {
  2. bool? visible,
})

Factory method to create a TronAddress from a Tron address string

Implementation

factory TronAddress(String address, {bool? visible}) {
  try {
    if (visible == null) {
      if (StringUtils.isHexBytes(address)) {
        return TronAddress.fromBytes(BytesUtils.fromHexString(address));
      }
      final decode = TrxAddrDecoder().decodeAddr(address);
      return TronAddress._(address,
          BytesUtils.toHexString([...TrxAddressUtils.prefix, ...decode]));
    } else {
      if (visible) {
        final decode = TrxAddrDecoder().decodeAddr(address);
        return TronAddress._(address,
            BytesUtils.toHexString([...TrxAddressUtils.prefix, ...decode]));
      } else {
        return TronAddress.fromBytes(BytesUtils.fromHexString(address));
      }
    }
  } catch (e) {
    throw MessageException("invalid tron address",
        details: {"input": address, "visible": visible});
  }
}