(
value: Hex,
{ param }: { param: param },
)
| 292 | | ErrorType |
| 293 | |
| 294 | function encodeBytes<const param extends AbiParameter>( |
| 295 | value: Hex, |
| 296 | { param }: { param: param }, |
| 297 | ): PreparedParam { |
| 298 | const [, paramSize] = param.type.split('bytes') |
| 299 | const bytesSize = size(value) |
| 300 | if (!paramSize) { |
| 301 | let value_ = value |
| 302 | // If the size is not divisible by 32 bytes, pad the end |
| 303 | // with empty bytes to the ceiling 32 bytes. |
| 304 | if (bytesSize % 32 !== 0) |
| 305 | value_ = padHex(value_, { |
| 306 | dir: 'right', |
| 307 | size: Math.ceil((value.length - 2) / 2 / 32) * 32, |
| 308 | }) |
| 309 | return { |
| 310 | dynamic: true, |
| 311 | encoded: concatHex([ |
| 312 | padHex(numberToHex(bytesSize, { size: 32 })), |
| 313 | value_, |
| 314 | ]), |
| 315 | } |
| 316 | } |
| 317 | if (bytesSize !== Number.parseInt(paramSize, 10)) |
| 318 | throw new AbiEncodingBytesSizeMismatchError({ |
| 319 | expectedSize: Number.parseInt(paramSize, 10), |
| 320 | value, |
| 321 | }) |
| 322 | return { dynamic: false, encoded: padHex(value, { dir: 'right' }) } |
| 323 | } |
| 324 | |
| 325 | type EncodeBoolErrorType = PadHexErrorType | BoolToHexErrorType | ErrorType |
| 326 |
no test coverage detected