Skip to content

Commit 1ed6bc9

Browse files
Merge pull request #95 from logical-mechanism/adding-minting-quantity-of
minting.quantity_of added;
2 parents 13736f1 + 30d9ffb commit 1ed6bc9

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v3
1313
- uses: aiken-lang/setup-aiken@v1
1414
with:
15-
version: v1.1.0
15+
version: v1.1.1
1616
- run: aiken fmt --check
1717
- run: aiken check -D
1818
- run: aiken build

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# v0.x.y
22

3+
- Added minting.quantity_of to get prove that some form of minting is occurring then the quantity is returned
4+
35
# v0.5.0
46

57
- Updated toml to Aiken 1.1.0, stdlib main (v2.0.0 should be the tagged release)

aiken.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "logical-mechanism/Assist"
22
version = "v0.5.0"
3-
compiler = "v1.1.0"
3+
compiler = "v1.1.1"
44
plutus = "v3"
55
license = "Apache-2.0"
66
description = "Aiken Assist Library"

lib/cardano/minting.ak

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,47 @@ test tx_is_not_minting() {
176176
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
177177
is_occurring(flat, #"acab", cip68.prefix_333) == False
178178
}
179+
180+
/// Prove that a transaction is minting something from a specific policy id
181+
/// and token name. If it is minting then return the amount else return zero.
182+
///
183+
/// ```aiken
184+
/// minting.quantity_of(flatten_mint_value, pid, tkn)
185+
/// ```
186+
pub fn quantity_of(
187+
flat: List<(PolicyId, AssetName, Int)>,
188+
pid: PolicyId,
189+
tkn: AssetName,
190+
) -> Int {
191+
when flat is {
192+
// loop the minted value
193+
[(policy, token_name, quantity), ..rest] ->
194+
if and {
195+
policy == pid,
196+
token_name == tkn,
197+
} {
198+
// we found what we are looking for so return the quantity
199+
quantity
200+
} else {
201+
quantity_of(rest, pid, tkn)
202+
}
203+
// something wasn't found
204+
[] -> 0
205+
}
206+
}
207+
208+
test tx_is_empty_minting_quantity() {
209+
let flat =
210+
[]
211+
quantity_of(flat, #"acab", cip68.prefix_222) == 0
212+
}
213+
214+
test tx_is_minting_quantity() {
215+
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
216+
quantity_of(flat, #"acab", cip68.prefix_222) == 1
217+
}
218+
219+
test tx_is_not_minting_quantity() {
220+
let flat = assets.from_asset(#"acab", cip68.prefix_222, 1) |> assets.flatten()
221+
quantity_of(flat, #"acab", cip68.prefix_333) == 0
222+
}

0 commit comments

Comments
 (0)