encode method
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) {
final BigInt v;
if (value is BigInt) {
v = value;
} else if (value is int) {
v = BigInt.from(value);
} else {
throw ArgumentError('Expected int or BigInt, got ${value.runtimeType}');
}
final minVal = -(BigInt.one << (bits - 1));
final maxVal = (BigInt.one << (bits - 1)) - BigInt.one;
if (v < minVal || v > maxVal) {
throw ArgumentError('Value $v out of int$bits range [$minVal..$maxVal]');
}
// Two's complement into 256-bit slot.
final encoded = v < BigInt.zero ? (BigInt.one << 256) + v : v;
return _bigIntToBytes32(encoded);
}