encodeTo method

  1. @override
void encodeTo(
  1. List<String> value,
  2. Output output
)
override

Encode topics to output

Implementation

@override
void encodeTo(List<String> value, Output output) {
  // Convert hex strings to byte arrays
  final byteArrays = value.map((hash) {
    // Remove '0x' prefix if present
    final cleanHash = hash.startsWith('0x') ? hash.substring(2) : hash;

    // Validate hash length
    if (cleanHash.length != HASH_SIZE * 2) {
      throw MetadataException(
        'Invalid hash length: expected ${HASH_SIZE * 2} hex characters, got ${cleanHash.length}',
      );
    }

    // Validate hex characters
    if (!RegExp(r'^[0-9a-fA-F]+$').hasMatch(cleanHash)) {
      throw MetadataException('Invalid hash: contains non-hex characters');
    }

    // Convert to bytes
    return Uint8List.fromList(decodeHex(cleanHash));
  }).toList();

  // Use SequenceCodec to encode
  _codec.encodeTo(byteArrays, output);
}