Apply Parameters¶
Applies a list of parameters to a parameterized Plutus script, producing the fully applied script ready for use on chain.
-
cardano_error_t cardano_uplc_apply_params_to_script(const cardano_plutus_list_t *params, const byte_t *script_bytes, size_t script_size, cardano_buffer_t **out_script)¶
Applies a list of Plutus-data parameters to a compiled Plutus script.
Decodes the CBOR-wrapped, flat-encoded script in
script_bytesinto a program, applies each parameter inparamsin order (params[0] first, so it becomes the innermost argument), and re-encodes the result to the ledger witness-set form: the new flat program wrapped in a single CBOR bytestring.The decode peels exactly one CBOR layer, and the output is single-CBOR-wrapped, so a canonical input round-trips byte-for-byte. A non-canonical input re-encodes to the canonical form, but the resulting program is structurally equal to applying the parameters to the decoded input.
The decoding and re-encoding run inside an internal arena that is freed before this returns on every path. The result
out_scriptis allocated outside that arena and outlives it.- Parameters:¶
- const cardano_plutus_list_t *params¶
[in] The parameters to apply, a list of plutus-data values, or NULL to apply no parameters. An empty or NULL list re-encodes the script unchanged (up to canonicalization).
- const byte_t *script_bytes¶
[in] The compiled script bytes, CBOR-wrapped flat. May be NULL only when
script_sizeis 0, which is rejected as a malformed script.- size_t script_size¶
[in] The number of bytes in
script_bytes.- cardano_buffer_t **out_script¶
[out] On success, set to a newly allocated buffer holding the CBOR-wrapped flat bytes of the parameterized script. The caller owns it and releases it with cardano_buffer_unref. Left untouched on failure.
- Returns:¶
CARDANO_SUCCESS on success, CARDANO_ERROR_POINTER_IS_NULL if
out_scriptis NULL orscript_bytesis NULL whilescript_sizeis non-zero, CARDANO_ERROR_DECODING if the script bytes are not a valid CBOR-wrapped flat program, CARDANO_ERROR_NOT_IMPLEMENTED if the decoded program carries a constant form with no flat serialization, or CARDANO_ERROR_MEMORY_ALLOCATION_FAILED if the arena or an output buffer cannot be allocated.