encode method

  1. @override
Uint8List encode(
  1. dynamic value
)
override

ABI-encode value as a 32-byte-aligned Uint8List. For dynamic types, returns the tail; the caller places the offset in the head.

Implementation

@override
Uint8List encode(dynamic value) {
  Uint8List bytes;
  if (value is Uint8List) {
    bytes = value;
  } else if (value is String) {
    bytes = hexDecode(value);
  } else {
    throw ArgumentError('Expected Uint8List or hex String, got ${value.runtimeType}');
  }
  if (bytes.length != 20) {
    throw ArgumentError('Address must be 20 bytes, got ${bytes.length}');
  }
  final out = Uint8List(32);
  out.setRange(12, 32, bytes);
  return out;
}