Skip to content

Commit

Permalink
chore: adding inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Aug 8, 2024
1 parent 8618d33 commit 4f77221
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
File renamed without changes.
17 changes: 17 additions & 0 deletions lib/vodka_inputs.ak
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use aiken/transaction.{InlineDatum, Input}
use aiken/transaction/credential.{Address}
use aiken/transaction/value.{AssetName, PolicyId, flatten, quantity_of}

/// Extracts the inline datum from an input.
pub fn output_inline_datum(input: Input) {
expect InlineDatum(raw_datum) = input.output.datum
raw_datum
}

/// Extract the inline datum by locating the first input in a list of inputs by Address and PolicyId.
pub fn only_input_datum_with(
inputs: List<Input>,
policy: PolicyId,
Expand All @@ -21,10 +23,12 @@ pub fn only_input_datum_with(
output_inline_datum(input)
}

/// Filters inputs by Address.
pub fn inputs_at(inputs: List<Input>, address: Address) -> List<Input> {
list.filter(inputs, fn(input) { input.output.address == address })
}

/// Filters inputs by PolicyId and AssetName.
pub fn inputs_with(
inputs: List<Input>,
policy: PolicyId,
Expand All @@ -36,6 +40,17 @@ pub fn inputs_with(
)
}

/// Filters inputs by token policy.
pub fn inputs_with_policy(inputs: List<Input>, policy: PolicyId) -> List<Input> {
list.filter(
inputs,
fn(input) {
list.any(flatten(input.output.value), fn(token) { token.1st == policy })
},
)
}

/// Filters inputs by Address, PolicyId, and AssetName.
pub fn inputs_at_with(
inputs: List<Input>,
address: Address,
Expand All @@ -54,6 +69,7 @@ pub fn inputs_at_with(
)
}

/// Filters inputs by Address and PolicyId.
pub fn inputs_at_with_policy(
inputs: List<Input>,
address: Address,
Expand All @@ -70,6 +86,7 @@ pub fn inputs_at_with_policy(
)
}

/// Calculate the total quantity of a token in a list of inputs.
pub fn inputs_token_quantity(
inputs: List<Input>,
token: (PolicyId, AssetName),
Expand Down

0 comments on commit 4f77221

Please sign in to comment.