Transaction Input To Redeemer Map¶
-
typedef struct cardano_input_to_redeemer_map_t cardano_input_to_redeemer_map_t¶
Represents a map of input to redeemers.
-
cardano_error_t cardano_input_to_redeemer_map_new(cardano_input_to_redeemer_map_t **map)¶
Creates and initializes a new instance of a map.
This function allocates and initializes a new instance of cardano_input_to_redeemer_map_t, representing a map structure. It returns an error code to indicate the success or failure of the operation.
Usage Example:
cardano_input_to_redeemer_map_t* map = NULL; // Attempt to create a new map cardano_error_t result = cardano_input_to_redeemer_map_new(&input_to_redeemer_map); if (result == CARDANO_SUCCESS) { // Use the map // Once done, ensure to clean up and release the map cardano_input_to_redeemer_map_unref(&input_to_redeemer_map); }- Parameters:¶
- cardano_input_to_redeemer_map_t **map¶
[out] A pointer to a pointer to a cardano_input_to_redeemer_map_t input. Upon successful initialization, this will point to a newly created cardano_input_to_redeemer_map_t input. This input represents a “strong reference” to the map, fully initialized and ready for use. The caller is responsible for managing the lifecycle of this input. Specifically, once the map is no longer needed, the caller must release it by calling cardano_input_to_redeemer_map_unref.
- Returns:¶
CARDANO_SUCCESS if the map was successfully created, or an appropriate error code indicating the failure reason.
-
size_t cardano_input_to_redeemer_map_get_length(const cardano_input_to_redeemer_map_t *map)¶
Retrieves the length of the map.
This function returns the number of key-value pairs contained in the specified map.
Usage Example:
cardano_input_to_redeemer_map_t* map = cardano_input_to_redeemer_map_new(); // Populate the map with key-value pairs size_t length = cardano_input_to_redeemer_map_get_length(input_to_redeemer_map); printf("The length of the map is: %zu\n", length); cardano_input_to_redeemer_map_unref(&input_to_redeemer_map);- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
[in] A constant pointer to the cardano_input_to_redeemer_map_t input for which the length is to be retrieved.
- Returns:¶
The number of key-value pairs in the map. Returns 0 if the map is NULL.
-
cardano_error_t cardano_input_to_redeemer_map_get(cardano_input_to_redeemer_map_t *map, const cardano_transaction_input_t *key, cardano_redeemer_t **element)¶
Retrieves the value associated with a given key in the map.
This function retrieves the value associated with the specified key in the provided map. It returns the value through the output parameter
element. If the key is not found in the map, the output parameterelementwill be set to NULL.Usage Example:
cardano_input_to_redeemer_map_t* map = cardano_input_to_redeemer_map_new(); // Populate the map with key-value pairs cardano_transaction_input_t* key = ...; // Create a input representing the key cardano_redeemer_t* value = NULL; cardano_error_t result = cardano_input_to_redeemer_map_get(input_to_redeemer_map, key, &value); if (result == CARDANO_SUCCESS && value != NULL) { // Use the retrieved value // ... } else { // Handle error or key not found } cardano_transaction_input_unref(&key); // Clean up the key resource cardano_input_to_redeemer_map_unref(&input_to_redeemer_map); cardano_redeemer_unref(&value); // Clean up the value resource- Parameters:¶
- cardano_input_to_redeemer_map_t *map¶
[in] A constant pointer to the cardano_input_to_redeemer_map_t input from which the value is to be retrieved.
- const cardano_transaction_input_t *key¶
[in] The key whose associated value is to be retrieved from the map.
- cardano_redeemer_t **element¶
[out] A pointer to a variable where the retrieved value will be stored. If the key is found in the map, this variable will be set to the associated value. If the key is not found, this variable will be set to NULL.
- Returns:¶
CARDANO_SUCCESS if the value associated with the key was successfully retrieved, or an appropriate error code if the input parameters are invalid or any other error occurs.
-
cardano_error_t cardano_input_to_redeemer_map_insert(cardano_input_to_redeemer_map_t *map, cardano_transaction_input_t *key, cardano_redeemer_t *value)¶
Inserts a key-value pair into the map.
This function inserts the specified key-value pair into the provided map.
Usage Example:
cardano_input_to_redeemer_map_t* map = cardano_input_to_redeemer_map_new(); // Create key and value input cardano_transaction_input_t* key = ...; cardano_redeemer_t* value = ...; // Insert the key-value pair into the map cardano_error_t result = cardano_input_to_redeemer_map_insert(input_to_redeemer_map, key, value); if (result != CARDANO_SUCCESS) { // Handle insertion failure } // Clean up key and value input cardano_transaction_input_unref(&key); cardano_input_to_redeemer_map_unref(&input_to_redeemer_map);- Parameters:¶
- cardano_input_to_redeemer_map_t *map¶
[in] A constant pointer to the cardano_input_to_redeemer_map_t input where the key-value pair is to be inserted.
- cardano_transaction_input_t *key¶
[in] The key to be inserted into the map. The caller is responsible for managing the lifecycle of the key input.
- cardano_redeemer_t *value¶
[in] The value to be associated with the key and inserted into the map. The caller is responsible for managing the lifecycle of the value input.
- Returns:¶
CARDANO_SUCCESS if the key-value pair was successfully inserted, or an appropriate error code if the input parameters are invalid or any other error occurs.
-
cardano_error_t cardano_input_to_redeemer_map_get_key_at(const cardano_input_to_redeemer_map_t *map, size_t index, cardano_transaction_input_t **input)¶
Retrieves the input at a specific index from the map.
This function retrieves the input at the specified index from the map.
Usage Example:
cardano_input_to_redeemer_map_t* map = NULL; cardano_transaction_input_t* input = NULL; size_t index = 0; // Index of the key hash to retrieve // Assume map is initialized properly cardano_error_t result = cardano_input_to_redeemer_map_get_key_at(input_to_redeemer_map, index, &input); if (result == CARDANO_SUCCESS) { // Use the input // Once done, ensure to clean up and release the input cardano_transaction_input_unref(&input); } else { // Handle the error }- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
[in] Pointer to the map input.
- size_t index¶
[in] The index of the input to retrieve.
- cardano_transaction_input_t **input¶
[out] On successful retrieval, this will point to the input at the specified index. The caller is responsible for managing the lifecycle of this input. Specifically, once the input is no longer needed, the caller must release it by calling cardano_transaction_input_unref.
- Returns:¶
cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the input was successfully retrieved, or an appropriate error code indicating the failure reason.
-
cardano_error_t cardano_input_to_redeemer_map_get_value_at(const cardano_input_to_redeemer_map_t *map, size_t index, cardano_redeemer_t **redeemer)¶
Retrieves the redeemer at a specific index from the map.
This function retrieves the redeemer at the specified index from the map.
Usage Example:
cardano_input_to_redeemer_map_t* map = NULL; cardano_redeemer_t* redeemer = 0; size_t index = 0; // Index of the redeemer to retrieve // Assume map is initialized properly cardano_error_t result = cardano_input_to_redeemer_map_get_value_at(input_to_redeemer_map, index, &redeemer); if (result == CARDANO_SUCCESS) { // Use the redeemer } else { // Handle the error } cardano_redeemer_unref(&redeemer);- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
[in] Pointer to the map input.
- size_t index¶
[in] The index of the redeemer to retrieve.
- cardano_redeemer_t **redeemer¶
[out] On successful retrieval, this will point to the redeemer at the specified index.
- Returns:¶
cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the redeemer was successfully retrieved, or an appropriate error code indicating the failure reason.
-
cardano_error_t cardano_input_to_redeemer_map_get_key_value_at(const cardano_input_to_redeemer_map_t *map, size_t index, cardano_transaction_input_t **input, cardano_redeemer_t **redeemer)¶
Retrieves the input and redeemer at the specified index.
This function retrieves the input and redeemer from the proposed redeemers at the specified index.
Usage Example:
cardano_input_to_redeemer_map_t* map = NULL; // Assume map is initialized properly size_t index = 0; cardano_transaction_input_t* input = NULL; cardano_redeemer_t* redeemer = 0; cardano_error_t result = cardano_input_to_redeemer_map_get_key_value_at(input_to_redeemer_map, index, &input, &redeemer); if (result == CARDANO_SUCCESS) { if (input != NULL && redeemer != NULL) { // Use the input and redeemer } else { printf("Key-value pair not set at index %zu.\n", index); } } else { // Handle error printf("Failed to get key-value pair at index %zu.\n", index); } // Clean up cardano_input_to_redeemer_map_unref(&input_to_redeemer_map); cardano_transaction_input_unref(&input); cardano_redeemer_unref(&redeemer);- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
[in] Pointer to the proposed redeemers input.
- size_t index¶
[in] The index at which to retrieve the key-value pair.
- cardano_transaction_input_t **input¶
[out] On successful retrieval, this will point to the input at the specified index. The caller is responsible for managing the lifecycle of this input and should release it using cardano_transaction_input_unref when it is no longer needed.
- cardano_redeemer_t **redeemer¶
[out] On successful retrieval, this will point to the redeemer at the specified index.
- Returns:¶
cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS if the key-value pair was successfully retrieved, or an appropriate error code indicating the failure reason.
-
cardano_error_t cardano_input_to_redeemer_map_update_redeemer_index(cardano_input_to_redeemer_map_t *map, cardano_transaction_input_t *input, uint64_t index)¶
Finds a redeemer that matches the given input reference.
If it finds it, it updates its index. Otherwise it does nothing.
- Parameters:¶
- cardano_input_to_redeemer_map_t *map¶
The map to search for the input.
- cardano_transaction_input_t *input¶
The input key that will be used to search for the redeemer.
- uint64_t index¶
The new index to assign to the redeemer.
- Returns:¶
cardano_error_t indicating the outcome of the operation. Returns CARDANO_SUCCESS.
-
void cardano_input_to_redeemer_map_unref(cardano_input_to_redeemer_map_t **map)¶
Decrements the reference count of a map input.
This function is responsible for managing the lifecycle of a cardano_input_to_redeemer_map_t input by decreasing its reference count. When the reference count reaches zero, the map is finalized; its associated resources are released, and its memory is deallocated.
Usage Example:
cardano_input_to_redeemer_map_t* map = cardano_input_to_redeemer_map_new(); // Perform operations with the map... cardano_input_to_redeemer_map_unref(&input_to_redeemer_map); // At this point, map is NULL and cannot be used.Note
After calling cardano_input_to_redeemer_map_unref, the pointer to the cardano_input_to_redeemer_map_t input will be set to NULL to prevent its reuse.
- Parameters:¶
- cardano_input_to_redeemer_map_t **map¶
[inout] A pointer to the pointer of the map input. This double indirection allows the function to set the caller’s pointer to NULL, avoiding dangling pointer issues after the input has been freed.
-
void cardano_input_to_redeemer_map_ref(cardano_input_to_redeemer_map_t *map)¶
Increases the reference count of the cardano_input_to_redeemer_map_t input.
This function is used to manually increment the reference count of a map input, indicating that another part of the code has taken ownership of it. This ensures the input remains allocated and valid until all owners have released their reference by calling cardano_input_to_redeemer_map_unref.
Usage Example:
// Assuming map is a previously created map input cardano_input_to_redeemer_map_ref(input_to_redeemer_map); // Now map can be safely used elsewhere without worrying about premature deallocationNote
Always ensure that for every call to cardano_input_to_redeemer_map_ref there is a corresponding call to cardano_input_to_redeemer_map_unref to prevent memory leaks.
- Parameters:¶
- cardano_input_to_redeemer_map_t *map¶
A pointer to the map input whose reference count is to be incremented.
-
size_t cardano_input_to_redeemer_map_refcount(const cardano_input_to_redeemer_map_t *map)¶
Retrieves the current reference count of the cardano_input_to_redeemer_map_t input.
This function returns the number of active references to a map input. It’s useful for debugging purposes or managing the lifecycle of the input in complex scenarios.
Usage Example:
// Assuming map is a previously created map input size_t ref_count = cardano_input_to_redeemer_map_refcount(input_to_redeemer_map); printf("Reference count: %zu\n", ref_count);Warning
This function does not account for transitive references. A transitive reference occurs when an input holds a reference to another input, rather than directly to the cardano_input_to_redeemer_map_t. As such, the reported count may not fully represent the total number of conceptual references in cases where such transitive relationships exist.
- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
A pointer to the map input whose reference count is queried. The input must not be NULL.
- Returns:¶
The number of active references to the specified map input. If the input is properly managed (i.e., every cardano_input_to_redeemer_map_ref call is matched with a cardano_input_to_redeemer_map_unref call), this count should reach zero right before the input is deallocated.
-
void cardano_input_to_redeemer_map_set_last_error(cardano_input_to_redeemer_map_t *map, const char *message)¶
Sets the last error message for a given map input.
Records an error message in the map’s last_error buffer, overwriting any existing message. This is useful for storing descriptive error information that can be later retrieved. The message is truncated if it exceeds the buffer’s capacity.
Note
The error message is limited to 1023 characters, including the null terminator, due to the fixed size of the last_error buffer.
- Parameters:¶
- cardano_input_to_redeemer_map_t *map¶
[in] A pointer to the cardano_input_to_redeemer_map_t instance whose last error message is to be set. If
NULL, the function does nothing.- const char *message¶
[in] A null-terminated string containing the error message. If
NULL, the map’s last_error is set to an empty string, indicating no error.
-
const char *cardano_input_to_redeemer_map_get_last_error(const cardano_input_to_redeemer_map_t *map)¶
Retrieves the last error message recorded for a specific map.
This function returns a pointer to the null-terminated string containing the last error message set by cardano_input_to_redeemer_map_set_last_error for the given map. If no error message has been set, or if the last_error buffer was explicitly cleared, an empty string is returned, indicating no error.
Note
The returned string points to internal storage within the input and must not be modified by the caller. The string remains valid until the next call to cardano_input_to_redeemer_map_set_last_error for the same map, or until the map is deallocated.
- Parameters:¶
- const cardano_input_to_redeemer_map_t *map¶
[in] A pointer to the cardano_input_to_redeemer_map_t instance whose last error message is to be retrieved. If the map is NULL, the function returns a generic error message indicating the null map.
- Returns:¶
A pointer to a null-terminated string containing the last error message for the specified map. If the map is NULL, “Object is NULL.” is returned to indicate the error.