cashscript_py.helpers.argument_encoding module

CashScript ABI argument encoding.

Key behavior: - ‘int’ encodes to Script Number (little-endian, minimal-length). - ‘bool’ encodes to 0x00/0x01. - ‘string’ encodes to UTF-8 bytes. - ‘pubkey’ accepts raw bytes or hex string (33/65 bytes). - ‘bytes’/’bytesN’ accept raw bytes or hex string; bytesN enforces exact length. - ‘sig’ accepts SignatureTemplate, or raw bytes with valid lengths {0,65,71,72,73}. - ‘datasig’ accepts raw bytes with valid lengths {0,64,70,71,72}.

exception ArgumentTypeError(actual_type: str, expected_type: str)[source]

Bases: Exception

Raised when an ABI argument’s Python type does not match the expected CashScript type.

encode_constructor_arguments(contract_params: list[bool | int | str | bytes], constructor_inputs: list[dict[str, str]]) list[bytes][source]

Encode constructor arguments according to the artifact’s constructor types.

Parameters:
  • contract_params – Values provided to the contract constructor.

  • constructor_inputs – Type descriptors (in declaration order) from the artifact.

Returns:

Encoded arguments as raw bytes (ABI format).

Raises:

ValueError – If a signature type is used in the constructor (disallowed) or types mismatch.

encode_function_argument(argument: bool | int | str | bytes | SignatureTemplate, type_str: str) bytes | SignatureTemplate[source]

Encode a single function argument for the CashScript ABI.

Parameters:
  • argument – The argument value (bytes/hex/string/int/bool/SigTemplate).

  • type_str – The ABI type string (e.g., “int”, “bool”, “string”, “bytesN”, “pubkey”, “sig”, “datasig”).

Returns:

Encoded bytes or a SignatureTemplate (for “sig”).

Raises:
  • ArgumentTypeError – If the value type does not match the expected ABI type.

  • ValueError – If bounded bytesN lengths, signature lengths, or unknown types are invalid.