From daffb45411ec1ecb2d2429c85c969660649d28c2 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Thu, 12 Sep 2024 11:10:18 -0700 Subject: [PATCH 1/2] minting.quantity_of added; similar to is_occurring but returns the quantity of the mint --- CHANGELOG.md | 2 ++ aiken.toml | 2 +- lib/cardano/minting.ak | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77e8d2b..0fe9dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/aiken.toml b/aiken.toml index 3455c91..099582d 100644 --- a/aiken.toml +++ b/aiken.toml @@ -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" diff --git a/lib/cardano/minting.ak b/lib/cardano/minting.ak index cf5c483..612e9c2 100644 --- a/lib/cardano/minting.ak +++ b/lib/cardano/minting.ak @@ -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 +} From 30d9ffbef13d90efd23ab51f140d653b7080f301 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Thu, 12 Sep 2024 11:15:16 -0700 Subject: [PATCH 2/2] upgrade to aiken v1.1.1 --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 52b7548..8f2af3a 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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