decodeAddr method

  1. @override
List<int> decodeAddr(
  1. String addr, [
  2. Map<String, dynamic> kwargs = const {}
])
override

Overrides the base class method to decode an OKExChain address.

This method decodes an OKExChain address from the provided input string using Bech32 encoding. It expects an optional map of keyword arguments for custom behavior, but specifically, it skips the checksum encoding validation. The address Human-Readable Part (HRP) is retrieved from the OKExChain configuration. The method first decodes the Bech32 address and then decodes it again as an Ethereum address with a custom prefix. The result is returned as a List<int> containing the decoded Ethereum address bytes.

Parameters:

  • addr: The OKExChain address to be decoded.
  • kwargs: Optional keyword arguments (with 'skip_chksum_enc' for skipping checksum encoding).

Returns: A List<int> containing the decoded Ethereum address bytes derived from the OKExChain address.

Implementation

@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
  try {
    /// Decode the OKExChain address using the OKExChain configuration's HRP.
    final List<int> addrDecBytes =
        Bech32Decoder.decode(CoinsConf.okexChain.params.addrHrp!, addr);

    /// Decode the address again as an Ethereum address with a custom prefix.
    return EthAddrDecoder().decodeAddr(
        CoinsConf.ethereum.params.addrPrefix! +
            BytesUtils.toHexString(addrDecBytes),
        {"skip_chksum_enc": true});
  } catch (e) {
    if (e is Bech32ChecksumError) {
      throw const AddressConverterException('Invalid bech32 checksum');
    }
    rethrow;
  }
}