Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions lib/cardano/assets.ak
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ fn do_contains(
}
}

/// Check whether a `Value` carries any NFT from the given policy. Other assets are tolerated.
/// Check whether a `Value` carries a quantity of exactly 1 of at least one asset
/// of the given policy, as expected of an NFT. Other assets are tolerated.
///
/// > [!IMPORTANT]
/// > The check is local to the given `Value`. A quantity of 1 does not prove
/// > that the asset is a genuine NFT, unique across the whole chain. A fungible
/// > token present with a quantity of 1 also satisfies the check.
///
/// ```aiken
/// let value = assets.from_lovelace(42)
Expand All @@ -165,10 +171,15 @@ pub fn has_any_nft(self: Value, policy: PolicyId) -> Bool {
|> dict.foldr(False, fn(_, quantity, result) { result || 1 == quantity })
}

/// Check whether a `Value` carries any NFT from the given policy. Other assets (other than
/// Check whether a `Value` carries a quantity of exactly 1 of a single asset of
/// the given policy, as expected of an NFT. Other assets (other than
/// Ada) aren't tolerated. Said differently, the check succeeds if and only if
/// the value contains no assets other than the expected NFT or Ada.
///
/// > [!IMPORTANT]
/// > See [`has_any_nft`](#has_any_nft): the check is local to the given `Value`
/// > and does not prove chain-level uniqueness.
///
/// ```aiken
/// let value = assets.from_lovelace(42)
/// |> assets.add("foo", "asset#1", 1)
Expand Down Expand Up @@ -218,7 +229,12 @@ pub fn has_any_nft_strict(self: Value, policy: PolicyId) -> Bool {
}
}

/// Check whether a `Value` carries a specific NFT. Other assets are tolerated.
/// Check whether a `Value` carries a quantity of exactly 1 of the given asset,
/// as expected of an NFT. Other assets are tolerated.
///
/// > [!IMPORTANT]
/// > See [`has_any_nft`](#has_any_nft): the check is local to the given `Value`
/// > and does not prove chain-level uniqueness.
///
/// ```aiken
/// let value = assets.from_lovelace(42)
Expand All @@ -244,18 +260,23 @@ pub fn has_nft(self: Value, policy: PolicyId, asset_name: AssetName) -> Bool {
1 == quantity_of(self, policy, asset_name)
}

/// Check whether a `Value` carries a specific NFT. Other assets (other than
/// Check whether a `Value` carries a quantity of exactly 1 of the given asset,
/// as expected of an NFT. Other assets (other than
/// Ada) aren't tolerated. Said differently, the check succeeds if and only if
/// the value contains no assets other than the expected NFT or Ada.
///
/// > [!IMPORTANT]
/// > See [`has_any_nft`](#has_any_nft): the check is local to the given `Value`
/// > and does not prove chain-level uniqueness.
///
/// ```aiken
/// let value = assets.from_lovelace(42)
/// |> assets.add("foo", "asset#1", 1)
/// |> assets.add("bar", "asset#2", 14)
///
/// assets.has_nft_strict(value1, "foo", "asset#1") == False
/// assets.has_nft_strict(value1, "bar", "asset#2") == False
/// assets.has_nft_strict(value1, "baz", "asset#3") == False
/// assets.has_nft_strict(value, "foo", "asset#1") == False
/// assets.has_nft_strict(value, "bar", "asset#2") == False
/// assets.has_nft_strict(value, "baz", "asset#3") == False
/// ```
///
/// ```aiken
Expand All @@ -272,8 +293,8 @@ pub fn has_nft(self: Value, policy: PolicyId, asset_name: AssetName) -> Bool {
/// |> assets.add("foo", "asset#1", 1)
/// |> assets.add("foo", "asset#2", 1)
///
/// assets.has_nft_strict(value3, "foo", "asset#1") == False
/// assets.has_nft_strict(value3, "foo", "asset#2") == False
/// assets.has_nft_strict(value, "foo", "asset#1") == False
/// assets.has_nft_strict(value, "foo", "asset#2") == False
/// ```
pub fn has_nft_strict(
self: Value,
Expand Down