Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prove an exact nft is now added #23

Merged
merged 1 commit into from
May 30, 2023
Merged
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
40 changes: 39 additions & 1 deletion lib/assist/values.ak
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ test real_token_name() {
/// is assumed to be unique.
///
/// ```aiken
/// values.prove_nft(pointer_pid, validating_value)
/// values.prove_nft(pid, this_value)
/// ```
pub fn prove_nft(pid: PolicyId, total: Value) {
let tkns =
Expand Down Expand Up @@ -267,3 +267,41 @@ test missing_nft() {
|> value.add(value.from_asset(#"face", #"beef", 40))
prove_nft(#"acab", val) == False
}

/// Proves that inside some value there is a policy id with token
/// name that has a quantity of 1. This will show that a value contains an
/// NFT or something that is nft-like. Should be useful to prove that
/// something is holding a token inside a transaction when the policy id and
/// token name is known.
///
/// ```aiken
/// values.prove_exact_nft(pid, tkn, that_value)
/// ```
pub fn prove_exact_nft(
nft_pid: PolicyId,
nft_tkn: AssetName,
total_value: Value,
) -> Bool {
// exactly 1 token inside a value
value.quantity_of(total_value, nft_pid, nft_tkn) == 1
}

test prove_exact_nft_from_policy_id() {
let val =
value.from_lovelace(100)
|> value.add(value.from_asset(#"acab", #"beef", 1))
|> value.add(value.from_asset(#"cafe", #"face", 40))
|> value.add(value.from_asset(#"beef", #"face", 40))
|> value.add(value.from_asset(#"face", #"beef", 40))
prove_exact_nft(#"acab", #"beef", val) == True
}

test missing_exact_nft() {
let val =
value.from_lovelace(100)
|> value.add(value.from_asset(#"acab", #"beef", 10))
|> value.add(value.from_asset(#"cafe", #"face", 10))
|> value.add(value.from_asset(#"beef", #"face", 40))
|> value.add(value.from_asset(#"face", #"beef", 40))
prove_exact_nft(#"acab", #"beef", val) == False
}