Skip to content

Commit

Permalink
Merge pull request #95 from logical-mechanism/adding-minting-quantity-of
Browse files Browse the repository at this point in the history
minting.quantity_of added;
  • Loading branch information
logicalmechanism authored Sep 12, 2024
2 parents 13736f1 + 30d9ffb commit 1ed6bc9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: aiken-lang/setup-aiken@v1
with:
version: v1.1.0
version: v1.1.1
- run: aiken fmt --check
- run: aiken check -D
- run: aiken build
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# v0.x.y

- Added minting.quantity_of to get prove that some form of minting is occurring then the quantity is returned

# v0.5.0

- Updated toml to Aiken 1.1.0, stdlib main (v2.0.0 should be the tagged release)
Expand Down
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "logical-mechanism/Assist"
version = "v0.5.0"
compiler = "v1.1.0"
compiler = "v1.1.1"
plutus = "v3"
license = "Apache-2.0"
description = "Aiken Assist Library"
Expand Down
44 changes: 44 additions & 0 deletions lib/cardano/minting.ak
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,47 @@ test tx_is_not_minting() {
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
is_occurring(flat, #"acab", cip68.prefix_333) == False
}

/// Prove that a transaction is minting something from a specific policy id
/// and token name. If it is minting then return the amount else return zero.
///
/// ```aiken
/// minting.quantity_of(flatten_mint_value, pid, tkn)
/// ```
pub fn quantity_of(
flat: List<(PolicyId, AssetName, Int)>,
pid: PolicyId,
tkn: AssetName,
) -> Int {
when flat is {
// loop the minted value
[(policy, token_name, quantity), ..rest] ->
if and {
policy == pid,
token_name == tkn,
} {
// we found what we are looking for so return the quantity
quantity
} else {
quantity_of(rest, pid, tkn)
}
// something wasn't found
[] -> 0
}
}

test tx_is_empty_minting_quantity() {
let flat =
[]
quantity_of(flat, #"acab", cip68.prefix_222) == 0
}

test tx_is_minting_quantity() {
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
quantity_of(flat, #"acab", cip68.prefix_222) == 1
}

test tx_is_not_minting_quantity() {
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
quantity_of(flat, #"acab", cip68.prefix_333) == 0
}

0 comments on commit 1ed6bc9

Please sign in to comment.