decodeError method

List? decodeError(
  1. dynamic error
)

Decodes the error data based on the error fragment in the contract ABI.

Implementation

List<dynamic>? decodeError(dynamic error) {
  try {
    if (error is String) {
      final inBytes = BytesUtils.fromHexString(error);
      final errorSelector = inBytes.sublist(0, ABIConst.selectorLength);
      if (BytesUtils.bytesEqual(errorSelector, revert.selector)) {
        return revert.decodeError(inBytes);
      }
      final errorFragment = errors.singleWhere((element) =>
          BytesUtils.bytesEqual(element.selector, errorSelector));

      return errorFragment.decodeError(inBytes);
    }
  } catch (e) {
    return null;
  }
  return null;
}