aiken_design_patterns/linked_list/unordered

Types

Every list node utxo:

  • has a unique key (unless it’s the root node)
  • has a unique link to another node’s key (unless it’s the last node of the list)
  • holds some app-specific data

Constructors

  • NodeDatum { key: NodeKey, link: NodeKey, data: Data }

Same as Option, but with more informative constructor names.

Constructors

  • Key { key: ByteArray }
  • Empty

Constants

node_prefix: ByteArray = "Node"

Every list node’s token name starts with this prefix.

Functions

Data types, constants, and accessors

get_key(raw_key_and_link: (Data, Data)) -> NodeKey

serialize_key(key: NodeKey) -> ByteArray

get_node_outputs(outputs: List<Output>, policy_id: PolicyId) -> List<Output>

get_node_inputs(inputs: List<Input>, policy_id: PolicyId) -> List<Output>

Predicates (used outside of list validators)

prove_is_root_node(policy_id: PolicyId, node: Output) -> Bool

Prove that a node belongs to the given list and is its root.

prove_is_last_node(policy_id: PolicyId, node: Output) -> Bool

Prove that a node belongs to the given list and is its last node.

prove_is_empty_list(policy_id: PolicyId, node: Output) -> Bool

Prove that the given list is empty, as witnessed by a node that is both the root and last node of the list.

prove_is_member(policy_id: PolicyId, key: NodeKey, node: Output) -> Bool

Prove that a key is a member of the given list, as witnessed by a node that satisfies the membership predicate with the key.

State integrity handlers (used in list spending validator)

list_state_transition(node_mint: Dict<AssetName, Int>) -> Bool

Detect whether the list’s minting policy is invoked in the transaction, so that the spending validator can forward to it.

modify_data(
  node_mint: Dict<AssetName, Int>,
  own_input: Output,
  own_output: Output,
  node_nft_policy_id: ByteArray,
  node_nft_asset_name: ByteArray,
) -> Bool

Modify the data field of a list node without changing the key and link fields.

State transition handlers (used in list minting policy)

init(
  node_outputs: List<Output>,
  node_mint: Dict<AssetName, Int>,
  node_cs: ByteArray,
) -> Bool

Initialize an empty unordered list.

Application code must ensure that this action can happen only once.

deinit(
  node_inputs: List<Output>,
  node_mint: Dict<AssetName, Int>,
  node_cs: ByteArray,
) -> Bool

Deinitialize an empty unordered list.

prepend_unsafe(
  key_to_prepend: NodeKey,
  prepended_node_index: Int,
  anchor_node_output_index: Int,
  node_inputs: List<Output>,
  node_outputs: List<Output>,
  node_mint: Dict<AssetName, Int>,
) -> Bool

Prepend a new node to the beginning of the list.

WARNING: An application using a key-unordered list MUST only add nodes with unique keys to the list. Duplicate keys break the linked list data structure.

The index arguments in this function are relative to the node_inputs and node_outputs. They are NOT absolute.

append_unsafe(
  key_to_append: NodeKey,
  appended_node_index: Int,
  anchor_node_output_index: Int,
  node_inputs: List<Output>,
  node_outputs: List<Output>,
  node_mint: Dict<AssetName, Int>,
) -> Bool

Append a new node to the end of the list.

WARNING: An application using a key-unordered list MUST only add nodes with unique keys to the list. Duplicate keys break the linked list data structure.

The index arguments in this function are relative to the node_inputs and node_outputs. They are NOT absolute.

remove(
  key_to_remove: NodeKey,
  removed_node_input_index: Int,
  anchor_node_input_index: Int,
  node_inputs: List<Output>,
  node_outputs: List<Output>,
  node_mint: Dict<AssetName, Int>,
) -> Bool

Remove a non-root node from the list.

The index arguments in this function are relative to the node_inputs and node_outputs. They are NOT absolute.

Search Document