From 595e79d111517f7bf490043569290e940de3c7d0 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Mon, 31 Jul 2023 14:32:21 -0700 Subject: [PATCH] prep for 0.2.3 and added new features --- .gitignore | 2 +- CHANGELOG.md | 20 ++++++++---- aiken.toml | 2 +- docs/assist/addresses.html | 18 +++++------ docs/assist/certificates.html | 18 +++++------ docs/assist/count.html | 18 +++++------ docs/assist/credentials.html | 18 +++++------ docs/assist/data.html | 18 +++++------ docs/assist/find.html | 18 +++++------ docs/assist/maths.html | 18 +++++------ docs/assist/minting.html | 49 ++++++++++++++++++++++++------ docs/assist/payout.html | 18 +++++------ docs/assist/prefixes.html | 57 +++++++++++++++++++++++++++++------ docs/assist/signing.html | 18 +++++------ docs/assist/std.html | 18 +++++------ docs/assist/values.html | 45 +++++++++++++++++++++------ docs/index.html | 18 +++++------ docs/search-data.js | 2 +- docs/tests/fake_tx.html | 35 +++++++++++++++------ lib/assist/minting.ak | 51 +++++++++++++++++++++++++++++++ lib/assist/prefixes.ak | 11 ++++++- lib/assist/values.ak | 55 +++++++++++++++++++++++++++++++++ lib/tests/fake_tx.ak | 31 ++++++++++++++----- 23 files changed, 404 insertions(+), 154 deletions(-) diff --git a/.gitignore b/.gitignore index 751a1ff..c0f4ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ artifacts/ # Aiken's project working directory build/ - +plutus.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 9299fe8..7c6479d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,28 @@ +# v0.2.3 + +- Added in a function to calculate the total amount of some specific token inside all the transaction inputs. +- Two new prefixes are now added, callable and database. +- The 555 prefix is being depreciated and will be removed in v0.2.4. +- Added in a function to check if a mint is occurring inside a transaction. + # v0.2.2 -Minting functions for exact mints and by_prefix mints. A experimental cip68 prefix has been added to prefixes. +- Added minting functions for exact mints and by_prefix mints. +- A experimental cip68 prefix has been added to prefixes. # v0.2.1 -CIP68 prefixes have been fixed. The unique token name function still produces correct names but any length checks needs to be adjusted. New prefix length is now 4. +- CIP68 prefixes have been fixed. The unique token name function still produces correct names but any length checks needs to be adjusted. New prefix length is now 4. # v0.1.6 -Does not work with Aiken versions below v1.0.7-alpha Aiken and v1.1.0 Stdlib. +- Does not work with Aiken versions below v1.0.7-alpha Aiken and v1.1.0 Stdlib. ## Changes -Fake Tx is updated with new `MintedValue` type. -Value add is now value merge. All Values functions have been updated. +- Fake Tx is updated with new `MintedValue` type. +- Value add is now value merge. All Values functions have been updated. # v0.1.5 and below -Works with v1.0.6-alpha Aiken and v1.0.0 Stdlib \ No newline at end of file +- Works with v1.0.6-alpha Aiken and v1.0.0 Stdlib \ No newline at end of file diff --git a/aiken.toml b/aiken.toml index 9300c70..f89580d 100644 --- a/aiken.toml +++ b/aiken.toml @@ -1,5 +1,5 @@ name = "aiken-lang/assist" -version = "0.2.2" +version = "0.2.3" license = "Apache-2.0" description = "Aiken Assist Library" diff --git a/docs/assist/addresses.html b/docs/assist/addresses.html index ad086de..19392c8 100644 --- a/docs/assist/addresses.html +++ b/docs/assist/addresses.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/certificates.html b/docs/assist/certificates.html index 39659a0..dce7220 100644 --- a/docs/assist/certificates.html +++ b/docs/assist/certificates.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/count.html b/docs/assist/count.html index c3631b4..7ac65f9 100644 --- a/docs/assist/count.html +++ b/docs/assist/count.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/credentials.html b/docs/assist/credentials.html index 637567d..26554fb 100644 --- a/docs/assist/credentials.html +++ b/docs/assist/credentials.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/data.html b/docs/assist/data.html index 97ab55a..08b2c38 100644 --- a/docs/assist/data.html +++ b/docs/assist/data.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/find.html b/docs/assist/find.html index 76fcd0b..e4f8205 100644 --- a/docs/assist/find.html +++ b/docs/assist/find.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/maths.html b/docs/assist/maths.html index 96f00fb..33ffd26 100644 --- a/docs/assist/maths.html +++ b/docs/assist/maths.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/minting.html b/docs/assist/minting.html index c81341d..c1b9dbd 100644 --- a/docs/assist/minting.html +++ b/docs/assist/minting.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/payout.html b/docs/assist/payout.html index 9cafc4e..3462933 100644 --- a/docs/assist/payout.html +++ b/docs/assist/payout.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/prefixes.html b/docs/assist/prefixes.html index ad88efd..80f0708 100644 --- a/docs/assist/prefixes.html +++ b/docs/assist/prefixes.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/signing.html b/docs/assist/signing.html index 52e7b9a..aa5a0dd 100644 --- a/docs/assist/signing.html +++ b/docs/assist/signing.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/std.html b/docs/assist/std.html index 7e1ede8..72a2529 100644 --- a/docs/assist/std.html +++ b/docs/assist/std.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/assist/values.html b/docs/assist/values.html index d5ea8e1..21a7105 100644 --- a/docs/assist/values.html +++ b/docs/assist/values.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 789b949..8fa9be9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/docs/search-data.js b/docs/search-data.js index 277b7c0..f59ac00 100644 --- a/docs/search-data.js +++ b/docs/search-data.js @@ -1 +1 @@ -window.Aiken.initSearch([{"doc":"assist/certificates","title":"create_credential_delegation","content":"create_credential_delegation(\n sc: Hash<Blake2b_224, Script>,\n pool_id: PoolId,\n) -> Certificate\n Creates a credential delegation for changing the location of the stake.\n This certificate can be used to check if stake is being delegated to\n a specific pool.\n\n ```aiken\n certificates.create_credential_delegation(datum.contract_hash, datum.pool_id)\n ```","url":"assist/certificates.html#create_credential_delegation"},{"doc":"assist/certificates","title":"assist/certificates","content":"","url":"assist/certificates.html"},{"doc":"tests/fake_tx","title":"test_input","content":"test_input() -> Input\n A fake input used for testing.","url":"tests/fake_tx.html#test_input"},{"doc":"tests/fake_tx","title":"test_out_ref","content":"test_out_ref() -> OutputReference\n Creates an `OutputReference`","url":"tests/fake_tx.html#test_out_ref"},{"doc":"tests/fake_tx","title":"test_output","content":"test_output() -> Output\n A fake output used for testing.","url":"tests/fake_tx.html#test_output"},{"doc":"tests/fake_tx","title":"test_signatories","content":"test_signatories() -> List<ByteArray>\n A fake list of tx signers","url":"tests/fake_tx.html#test_signatories"},{"doc":"tests/fake_tx","title":"test_tx","content":"test_tx() -> Transaction\n A fake transaction used for testing.","url":"tests/fake_tx.html#test_tx"},{"doc":"tests/fake_tx","title":"DataType","content":"DataType = Data\n A `Data`data type\n","url":"tests/fake_tx.html#DataType"},{"doc":"tests/fake_tx","title":"test_datum","content":"test_datum: ByteArray = #"acabbeeffacecafe"\n A test datum.","url":"tests/fake_tx.html#test_datum"},{"doc":"tests/fake_tx","title":"tests/fake_tx","content":" This is for testing only.\n","url":"tests/fake_tx.html"},{"doc":"assist/prefixes","title":"prefix_100","content":"prefix_100: ByteArray = #"000643b0"\n (100) Reference Token Prefix","url":"assist/prefixes.html#prefix_100"},{"doc":"assist/prefixes","title":"prefix_222","content":"prefix_222: ByteArray = #"000de140"\n (222) Non-Fungible Token Prefix","url":"assist/prefixes.html#prefix_222"},{"doc":"assist/prefixes","title":"prefix_333","content":"prefix_333: ByteArray = #"0014df10"\n (333) Fungible Token Prefix","url":"assist/prefixes.html#prefix_333"},{"doc":"assist/prefixes","title":"prefix_444","content":"prefix_444: ByteArray = #"001bc280"\n (444) Rich-Fungible Token Prefix","url":"assist/prefixes.html#prefix_444"},{"doc":"assist/prefixes","title":"prefix_555","content":"prefix_555: ByteArray = #"0022bfb0"\n (555) Pointer Token Prefix, NOT IMPLEMENTED IN CIP68","url":"assist/prefixes.html#prefix_555"},{"doc":"assist/prefixes","title":"assist/prefixes","content":" This module provides the currently accepted token prefixes.\n","url":"assist/prefixes.html"},{"doc":"assist/payout","title":"at_least","content":"at_least(\n payout_address: Address,\n payout_value: Value,\n outputs: List<Output>,\n) -> Bool\n Find the first occurrence of an output that contains at least some specific\n value at some address. If nothing is found then return False. This function\n does not search for an exact UTxO match.\n\n ```aiken\n payout.at_least(wallet_addr, just_token_value, tx.outputs)\n ```","url":"assist/payout.html#at_least"},{"doc":"assist/payout","title":"cont","content":"cont(payout_address: Address, outputs: List<Output>) -> Bool\n Find the first occurrence of an output at some address. If nothing is \n found then return False. This function does not search by value.\n\n ```aiken\n payout.cont(that_script_addr, tx.outputs)\n ```","url":"assist/payout.html#cont"},{"doc":"assist/payout","title":"exact","content":"exact(\n payout_address: Address,\n payout_value: Value,\n outputs: List<Output>,\n) -> Bool\n Find the first occurrence of an exact output that matches a specific\n address and value. If nothing is found then return False.\n\n ```aiken\n payout.exact(wallet_addr, validating_value, tx.outputs)\n ```","url":"assist/payout.html#exact"},{"doc":"assist/payout","title":"assist/payout","content":" This module contains code that assists with payout logic. Payout\n functions are designed to return a boolean value instead of an error.\n","url":"assist/payout.html"},{"doc":"assist/credentials","title":"create_stake_credential","content":"create_stake_credential(sc: Hash<Blake2b_224, Script>) -> Referenced<Credential>\n Creates a stake credential from the hex encoding of a stake key.\n This can be used to find the reward amount from the withdrawals \n information inside the transaction of the form Dict<StakeCredential, Int>\n\n ```aiken\n credentials.create_stake_credential(datum.contract_hash)\n ```","url":"assist/credentials.html#create_stake_credential"},{"doc":"assist/credentials","title":"assist/credentials","content":" This module incorporates code for generating valid credentials,\n ensuring their correctness. \n","url":"assist/credentials.html"},{"doc":"assist/minting","title":"by_prefix","content":"by_prefix(\n flat: List<(ByteArray, ByteArray, Int)>,\n pid: ByteArray,\n prefix: ByteArray,\n amt: Int,\n) -> Bool\n This checks if a specific policy id, prefix, and amount exist inside\n the flattened exact value. Instead of searching for exact match, it\n checks if the token name has the correct prefix. This works if\n every token name on the policy id is unique. If found then it returns\n True else False.\n","url":"assist/minting.html#by_prefix"},{"doc":"assist/minting","title":"exact","content":"exact(\n flat: List<(ByteArray, ByteArray, Int)>,\n pid: ByteArray,\n tkn: ByteArray,\n amt: Int,\n) -> Bool\n This checks if a specific policy id, token name, and amount exist inside\n the flattened exact value. It is searching for an exact match. If found\n then it returns True else False.\n","url":"assist/minting.html#exact"},{"doc":"assist/minting","title":"assist/minting","content":"","url":"assist/minting.html"},{"doc":"assist/count","title":"inputs_by_addr","content":"inputs_by_addr(inputs: List<Input>, addr: Address, amount: Int) -> Bool\n Verify that the number of inputs from a specific script is equal to the\n amount intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.inputs_by_addr(tx.inputs, this_addr, 1)\n ```","url":"assist/count.html#inputs_by_addr"},{"doc":"assist/count","title":"inputs_by_datum","content":"inputs_by_datum(inputs: List<Input>, amount: Int) -> Bool\n Verify that the number of inputs with an inline datum is equal to the\n number intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.inputs_by_datum(tx.inputs, 1)\n ```","url":"assist/count.html#inputs_by_datum"},{"doc":"assist/count","title":"outputs_by_addr","content":"outputs_by_addr(outputs: List<Output>, addr: Address, amount: Int) -> Bool\n Verify that the number of outputs from a specific script is equal the amount\n intended in the contract. The amount must be exact with the counter.\n\n ```aiken\n count.outputs_by_addr(tx.outputs, this_addr, 1)\n ```","url":"assist/count.html#outputs_by_addr"},{"doc":"assist/count","title":"outputs_by_datum","content":"outputs_by_datum(outputs: List<Output>, amount: Int) -> Bool\n Verify that the number of outputs with an inline datum is equal to the\n number intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.outputs_by_datum(tx.outputs, 1)\n ```","url":"assist/count.html#outputs_by_datum"},{"doc":"assist/count","title":"assist/count","content":" This module contains code to accurately count the number of inputs and\n outputs in a transaction for a specific address, assuming precise amounts.\n","url":"assist/count.html"},{"doc":"assist/maths","title":"base_q","content":"base_q(n: Int, q: Int) -> List<Int>\n Convert a integer `n` into some base `q`. This method\n should scale with any integer and any logical base.\n\n ```aiken\n maths.base_q(123, 7)\n ```","url":"assist/maths.html#base_q"},{"doc":"assist/maths","title":"decay","content":"decay(start_amt: Int, scale: Int, num: Int) -> Int\n Decay some starting amount logarithmically until zero. The function evaluates\n `y = a - log(n)` and when `n >= 2^a` the function equals zero but will return\n zero whenever the result is less than the scale. This is a great\n way to reduce some integer amount of something over time by incrementing `n`.\n\n ```aiken\n maths.decay(start_amount, lovelace_scaling, datum.current_int)\n ```","url":"assist/maths.html#decay"},{"doc":"assist/maths","title":"effective_ratio","content":"effective_ratio(amt: Int, pct: Int, scale: Int) -> Int\n Calculates the ratio of the amount `amt` multiplied by the scale by the\n percentage `pct`. The scale allows for finer calculations.\n\n ```aiken\n maths.effective_ratio(123456789, 40, 1000) == 3086419725\n ```","url":"assist/maths.html#effective_ratio"},{"doc":"assist/maths","title":"from_int","content":"from_int(self: Int) -> ByteArray\n Convert a integer into a hexadecimal bytearray. This works for all integers\n but odd length bytearrays will be prefixed with a zero. This function \n combined with the `to_int` function allows a string to represent a number\n and still be used for calculations, pushing the `2^64 - 1` integer boundary\n to `2^256 - 1`.\n\n ```aiken\n maths.from_int(44203)\n ```","url":"assist/maths.html#from_int"},{"doc":"assist/maths","title":"gcd","content":"gcd(a: Int, b: Int) -> Int\n Computes greatest common divisor of two numbers.\n\n ```aiken\n maths.gcd(20, 15)\n ```","url":"assist/maths.html#gcd"},{"doc":"assist/maths","title":"is_in_range","content":"is_in_range(n: Int, lb: Int, ub: Int) -> Bool\n Verify that some integer `n` is greater than the lower bound, `lb`, and\n less than or equal to the upper bound, `ub`. The function is exclusive\n for `lb` but inclusive for `lb + 1`.\n\n ```aiken\n maths.is_in_range(5, 0, 10)\n ```","url":"assist/maths.html#is_in_range"},{"doc":"assist/maths","title":"legendre_symbol","content":"legendre_symbol(a: Int, p: Int) -> Int\n Calculate the Legendre symbol `(a/p)` using the Euler's criterion.\n This implementation assumes that 'a' and 'p' are positive integers.\n\n ```aiken\n maths.legendre_symbol(10, 19)\n ```","url":"assist/maths.html#legendre_symbol"},{"doc":"assist/maths","title":"list_powmod","content":"list_powmod(lst: List<Int>, g: Int, q: Int) -> Int\n Computes the power mod product of a list of integers.\n\n ```aiken\n maths.list_pow_mod([1,2,3], 2, 19)\n ```","url":"assist/maths.html#list_powmod"},{"doc":"assist/maths","title":"list_product","content":"list_product(lst: List<Int>) -> Int\n Computes the product of a list of integers.\n\n ```aiken\n maths.list_product([1,2,3])\n ```","url":"assist/maths.html#list_product"},{"doc":"assist/maths","title":"list_sum","content":"list_sum(lst: List<Int>) -> Int\n Computes the sum of a list of integers.\n\n ```aiken\n maths.list_sum(list_of_integers)\n ```","url":"assist/maths.html#list_sum"},{"doc":"assist/maths","title":"powmod","content":"powmod(n: Int, e: Int, q: Int) -> Int\n Calculate `n` to the power of `e` modulo `q` using the exponentiation by \n squaring method. At each multiplication a modulo is calculated, allowing\n very large `n` and `e` values.\n\n ```aiken\n maths.powmod(3, 2, 5)\n ```","url":"assist/maths.html#powmod"},{"doc":"assist/maths","title":"ratio","content":"ratio(amt: Int, pct: Int) -> Int\n Calculates the ratio of the amount `amt` by a percentage `pct`. This can\n be used to calculate rough percentages. The function `ratio` is just a \n special case of the effective ratio function. \n\n ```aiken\n maths.ratio(123, 40)\n ```","url":"assist/maths.html#ratio"},{"doc":"assist/maths","title":"scaling","content":"scaling(amt: Int, pct: Int) -> Int\n Find the optimal scaling for a number such that it\n has three trailing zeros. This should be used in combination\n with the effective ratio for optimal calculations.\n\n ```aiken\n maths.scaling(123, 40)\n ```","url":"assist/maths.html#scaling"},{"doc":"assist/maths","title":"to_int","content":"to_int(self: ByteArray) -> Int\n Convert a hexadecimal bytearray into its base 10 representation. This\n only works with even length bytearrays so arbitrary numbers in hexadecimal\n form will not in general work.\n\n ```aiken\n maths.to_int(#"acab")\n ```","url":"assist/maths.html#to_int"},{"doc":"assist/maths","title":"assist/maths","content":" This module incorporates code for various mathematical operations.\n","url":"assist/maths.html"},{"doc":"assist/std","title":"out_ref","content":"out_ref(tx_id_hash: ByteArray, idx: Int) -> OutputReference\n Create an `OutputReference` from the `TxId#Idx` information. This is useful\n for building correct output references of specific UTxOs. It can be combined\n with the `find` module for some very convenient requests.\n\n ```aiken\n std.out_ref(that_tx_id, that_tx_idx)\n ```","url":"assist/std.html#out_ref"},{"doc":"assist/std","title":"assist/std","content":" This module incorporates additional code that expands the\n functionality of the standard library.\n","url":"assist/std.html"},{"doc":"assist/signing","title":"verify_multisig","content":"verify_multisig(\n sigs: List<Hash<Blake2b_224, VerificationKey>>,\n vks: List<Hash<Blake2b_224, VerificationKey>>,\n minimum: Int,\n) -> Bool\n This counts the number of signatures inside a transaction that are from \n the list of signers then checks if its at least the minimum amount.\n\n ```aiken\n signing.verify_multisig(context.transaction, lst_of_sigs, sig_threshold)\n ```","url":"assist/signing.html#verify_multisig"},{"doc":"assist/signing","title":"verify_sig","content":"verify_sig(\n vks: List<Hash<Blake2b_224, VerificationKey>>,\n vk: Hash<Blake2b_224, VerificationKey>,\n) -> Bool\n Check if the list of signatures inside a transaction contains the\n verification key.\n\n ```aiken\n signing.verify_sig(context.transaction, wallet_pkh)\n ```","url":"assist/signing.html#verify_sig"},{"doc":"assist/signing","title":"assist/signing","content":" This module contains code for verifying transaction signatures. \n It assumes that all signatures provided are verification keys.\n","url":"assist/signing.html"},{"doc":"assist/values","title":"compute_hash","content":"compute_hash(target: Value) -> ByteArray\n Compute the sha3_256 hash of a value by merklizing the policy id, asset\n name, and quantity. Empty values return the empty by string.\n\n ```aiken\n values.compute_hash(validating_value)\n ```","url":"assist/values.html#compute_hash"},{"doc":"assist/values","title":"contains","content":"contains(target: Value, total: Value) -> Bool\n Prove that the target value is contained inside another value. Each token\n inside the target must exist inside the total value. The quantity of each\n token must be at least the target amount or greater.\n\n ```aiken\n values.contain(payment_value, output_value)\n ```","url":"assist/values.html#contains"},{"doc":"assist/values","title":"multiply","content":"multiply(val: Value, n: Int) -> Value\n Multiply some value by `n`. This is just a linear scaling to the quantity\n of each token.\n\n ```aiken\n values.multiply(bundle_value, bundle_size)\n ```","url":"assist/values.html#multiply"},{"doc":"assist/values","title":"prove_exact_nft","content":"prove_exact_nft(\n nft_pid: PolicyId,\n nft_tkn: AssetName,\n total_value: Value,\n) -> Bool\n Proves that inside some value there is a policy id with token\n name that has a quantity of 1. This will show that a value contains an\n NFT or something that is nft-like. Should be useful to prove that\n something is holding a token inside a transaction when the policy id and\n token name is known.\n\n ```aiken\n values.prove_exact_nft(pid, tkn, that_value)\n ```","url":"assist/values.html#prove_exact_nft"},{"doc":"assist/values","title":"prove_nft","content":"prove_nft(pid: PolicyId, total: Value) -> Bool\n Proves that inside some value there is a policy id with a single token\n name that has a quantity of 1. This will show that a value contains an\n NFT or something that is nft-like. Should be useful to prove that\n something is holding a token inside a transaction when the token name\n is assumed to be unique.\n\n ```aiken\n values.prove_nft(pid, this_value)\n ```","url":"assist/values.html#prove_nft"},{"doc":"assist/values","title":"unique_token_name","content":"unique_token_name(txid: ByteArray, idx: Int, prefix: ByteArray) -> ByteArray\n Calculate a unique token name from a `TxId#Idx` and prefix. Can be combined\n with the `find` module to create unique token names from the first input\n utxo inside the transaction.\n\n ```aiken\n values.unique_token_name(tx_id, tx_idx, prefixes.prefix_333)\n ```","url":"assist/values.html#unique_token_name"},{"doc":"assist/values","title":"assist/values","content":" This module contains code that aids in various value \n manipulations and comparisons.\n","url":"assist/values.html"},{"doc":"assist/addresses","title":"create_address","content":"create_address(\n pkh: Hash<Blake2b_224, VerificationKey>,\n sc: Hash<Blake2b_224, VerificationKey>,\n) -> Address\n Creates a enterprise or base address from the public key hash and stake\n credential. An empty sc means enterpise address by default.\n\n ```aiken\n addresses.create_address(datum.wallet.pkh, datum.wallet.sc)\n ```","url":"assist/addresses.html#create_address"},{"doc":"assist/addresses","title":"create_script_address","content":"create_script_address(\n pkh: Hash<Blake2b_224, Script>,\n sc: Hash<Blake2b_224, Script>,\n) -> Address\n Creates a script address for a smart contract. The type does not mix address\n types. Staked smart contracts are contracts as well. An empty sc is\n assumed to be not staked.\n\n ```aiken\n addresses.create_script_address(datum.script.pkh, datum.script.sc)\n ```","url":"assist/addresses.html#create_script_address"},{"doc":"assist/addresses","title":"assist/addresses","content":" This module incorporates code for generating valid wallet and script \n addresses, ensuring their correctness. Empty keys are treated as \n intentional, and address subtypes are not combined or mixed.\n","url":"assist/addresses.html"},{"doc":"assist/find","title":"first_input_index","content":"first_input_index(inputs: List<Input>) -> Int\n Find the first input's output reference index.\n Output references have the form `TxId#Idx`, this function\n extracts the `Idx` part. If nothing is found then error.\n\n ```aiken\n find.first_input_index(tx.inputs)\n ```","url":"assist/find.html#first_input_index"},{"doc":"assist/find","title":"first_input_txid","content":"first_input_txid(inputs: List<Input>) -> ByteArray\n Find the first input's output reference transaction id hash.\n Output references have the form `TxId#Idx`, this function\n extracts the `TxId` part. If nothing is found then error.\n\n ```aiken\n find.first_input_txid(tx.inputs)\n ```","url":"assist/find.html#first_input_txid"},{"doc":"assist/find","title":"first_output_datum","content":"first_output_datum(outputs: List<Output>) -> Data\n Find the first output with an inline datum and return the data.\n If nothing is found then error. This works great for tx with a\n single output and datum or where ordering is irrelevant.\n\n ```aiken\n find.first_output_datum(tx.outputs)\n ```","url":"assist/find.html#first_output_datum"},{"doc":"assist/find","title":"input_by_addr","content":"input_by_addr(inputs: List<Input>, addr: Address) -> Input\n Find the first occurrence of an input by a specific address. If nothing\n is found then error. The address here is an exact match, so both the\n pkh and sc need to be correct.\n\n ```aiken\n find.input_by_addr(tx.reference_inputs, ref_addr)\n ```","url":"assist/find.html#input_by_addr"},{"doc":"assist/find","title":"input_by_ref","content":"input_by_ref(inputs: List<Input>, out_ref: OutputReference) -> Input\n Find an input by an output reference. If nothing is found then error. \n Similar to the builtin function in stdlib but auto errors instead of\n returning an `Option`.\n\n ```aiken\n find.input_by_ref(tx.inputs, out_ref)\n ```","url":"assist/find.html#input_by_ref"},{"doc":"assist/find","title":"output_by_addr","content":"output_by_addr(outputs: List<Output>, addr: Address) -> Output\n Find the first occurrence of an output by a specific address. If nothing\n is found then error. The address here is an exact match.\n\n ```aiken\n find.output_by_addr(tx.outputs, your_address)\n ```","url":"assist/find.html#output_by_addr"},{"doc":"assist/find","title":"output_datum_by_addr","content":"output_datum_by_addr(outputs: List<Output>, addr: Address) -> Data\n Find the first occurence of output datum by some address. If nothing is\n found then error.\n\n ```aiken\n expect datum: Datum = find.output_datum_by_addr(tx.outputs, this_addr)\n ```","url":"assist/find.html#output_datum_by_addr"},{"doc":"assist/find","title":"redeemer_by_ref","content":"redeemer_by_ref(\n redeemers: Dict<ScriptPurpose, Redeemer>,\n out_ref: OutputReference,\n) -> Data\n Find a redeemer data by an output reference. This is good for checking\n if a specific redeemer is being used on some specific UTxO inside \n the transaction.\n\n ```aiken\n find.redeemer_by_ref(tx.redeemers, that_out_ref)\n ```","url":"assist/find.html#redeemer_by_ref"},{"doc":"assist/find","title":"stake_reward_by_sc","content":"stake_reward_by_sc(\n withdraws: Dict<StakeCredential, Int>,\n stake_credential: StakeCredential,\n) -> Int\n Find the staking reward amount in loveace for some stake credential.\n If no rewards are available then error. This is a great method for\n checking on-chain staking rewards and withdrawal validation.\n\n ```aiken\n find.stake_reward_by_sc(tx.withdrawals, datum.wallet.sc)\n ```","url":"assist/find.html#stake_reward_by_sc"},{"doc":"assist/find","title":"assist/find","content":" This module contains code for identifying various aspects of \n a validating transaction.\n","url":"assist/find.html"},{"doc":"assist/data","title":"input_datum","content":"input_datum(possible_input: Input) -> Data\n Find the datum data on an input or error. The data is assumed\n to be an inline datum.\n\n ```aiken\n expect datum: Datum = data.input_datum(this_input)\n ```","url":"assist/data.html#input_datum"},{"doc":"assist/data","title":"output_datum","content":"output_datum(possible_output: Output) -> Data\n Find the datum data on an output or error. The data is assumed\n to be an inline datum.\n\n ```aiken\n expect datum: Datum = data.output_datum(that_output)\n ```","url":"assist/data.html#output_datum"},{"doc":"assist/data","title":"assist/data","content":" This module contains code for extracting data from a potential inline \n datum found in either an input or output.\n","url":"assist/data.html"}]); \ No newline at end of file +window.Aiken.initSearch([{"doc":"assist/find","title":"first_input_index","content":"first_input_index(inputs: List<Input>) -> Int\n Find the first input's output reference index.\n Output references have the form `TxId#Idx`, this function\n extracts the `Idx` part. If nothing is found then error.\n\n ```aiken\n find.first_input_index(tx.inputs)\n ```","url":"assist/find.html#first_input_index"},{"doc":"assist/find","title":"first_input_txid","content":"first_input_txid(inputs: List<Input>) -> ByteArray\n Find the first input's output reference transaction id hash.\n Output references have the form `TxId#Idx`, this function\n extracts the `TxId` part. If nothing is found then error.\n\n ```aiken\n find.first_input_txid(tx.inputs)\n ```","url":"assist/find.html#first_input_txid"},{"doc":"assist/find","title":"first_output_datum","content":"first_output_datum(outputs: List<Output>) -> Data\n Find the first output with an inline datum and return the data.\n If nothing is found then error. This works great for tx with a\n single output and datum or where ordering is irrelevant.\n\n ```aiken\n find.first_output_datum(tx.outputs)\n ```","url":"assist/find.html#first_output_datum"},{"doc":"assist/find","title":"input_by_addr","content":"input_by_addr(inputs: List<Input>, addr: Address) -> Input\n Find the first occurrence of an input by a specific address. If nothing\n is found then error. The address here is an exact match, so both the\n pkh and sc need to be correct.\n\n ```aiken\n find.input_by_addr(tx.reference_inputs, ref_addr)\n ```","url":"assist/find.html#input_by_addr"},{"doc":"assist/find","title":"input_by_ref","content":"input_by_ref(inputs: List<Input>, out_ref: OutputReference) -> Input\n Find an input by an output reference. If nothing is found then error. \n Similar to the builtin function in stdlib but auto errors instead of\n returning an `Option`.\n\n ```aiken\n find.input_by_ref(tx.inputs, out_ref)\n ```","url":"assist/find.html#input_by_ref"},{"doc":"assist/find","title":"output_by_addr","content":"output_by_addr(outputs: List<Output>, addr: Address) -> Output\n Find the first occurrence of an output by a specific address. If nothing\n is found then error. The address here is an exact match.\n\n ```aiken\n find.output_by_addr(tx.outputs, your_address)\n ```","url":"assist/find.html#output_by_addr"},{"doc":"assist/find","title":"output_datum_by_addr","content":"output_datum_by_addr(outputs: List<Output>, addr: Address) -> Data\n Find the first occurence of output datum by some address. If nothing is\n found then error.\n\n ```aiken\n expect datum: Datum = find.output_datum_by_addr(tx.outputs, this_addr)\n ```","url":"assist/find.html#output_datum_by_addr"},{"doc":"assist/find","title":"redeemer_by_ref","content":"redeemer_by_ref(\n redeemers: Dict<ScriptPurpose, Redeemer>,\n out_ref: OutputReference,\n) -> Data\n Find a redeemer data by an output reference. This is good for checking\n if a specific redeemer is being used on some specific UTxO inside \n the transaction.\n\n ```aiken\n find.redeemer_by_ref(tx.redeemers, that_out_ref)\n ```","url":"assist/find.html#redeemer_by_ref"},{"doc":"assist/find","title":"stake_reward_by_sc","content":"stake_reward_by_sc(\n withdraws: Dict<StakeCredential, Int>,\n stake_credential: StakeCredential,\n) -> Int\n Find the staking reward amount in loveace for some stake credential.\n If no rewards are available then error. This is a great method for\n checking on-chain staking rewards and withdrawal validation.\n\n ```aiken\n find.stake_reward_by_sc(tx.withdrawals, datum.wallet.sc)\n ```","url":"assist/find.html#stake_reward_by_sc"},{"doc":"assist/find","title":"assist/find","content":" This module contains code for identifying various aspects of \n a validating transaction.\n","url":"assist/find.html"},{"doc":"assist/credentials","title":"create_stake_credential","content":"create_stake_credential(sc: Hash<Blake2b_224, Script>) -> Referenced<Credential>\n Creates a stake credential from the hex encoding of a stake key.\n This can be used to find the reward amount from the withdrawals \n information inside the transaction of the form Dict<StakeCredential, Int>\n\n ```aiken\n credentials.create_stake_credential(datum.contract_hash)\n ```","url":"assist/credentials.html#create_stake_credential"},{"doc":"assist/credentials","title":"assist/credentials","content":" This module incorporates code for generating valid credentials,\n ensuring their correctness. \n","url":"assist/credentials.html"},{"doc":"assist/values","title":"compute_hash","content":"compute_hash(target: Value) -> ByteArray\n Compute the sha3_256 hash of a value by merklizing the policy id, asset\n name, and quantity. Empty values return the empty by string.\n\n ```aiken\n values.compute_hash(validating_value)\n ```","url":"assist/values.html#compute_hash"},{"doc":"assist/values","title":"contains","content":"contains(target: Value, total: Value) -> Bool\n Prove that the target value is contained inside another value. Each token\n inside the target must exist inside the total value. The quantity of each\n token must be at least the target amount or greater.\n\n ```aiken\n values.contain(payment_value, output_value)\n ```","url":"assist/values.html#contains"},{"doc":"assist/values","title":"multiply","content":"multiply(val: Value, n: Int) -> Value\n Multiply some value by `n`. This is just a linear scaling to the quantity\n of each token.\n\n ```aiken\n values.multiply(bundle_value, bundle_size)\n ```","url":"assist/values.html#multiply"},{"doc":"assist/values","title":"prove_exact_nft","content":"prove_exact_nft(\n nft_pid: PolicyId,\n nft_tkn: AssetName,\n total_value: Value,\n) -> Bool\n Proves that inside some value there is a policy id with token\n name that has a quantity of 1. This will show that a value contains an\n NFT or something that is nft-like. Should be useful to prove that\n something is holding a token inside a transaction when the policy id and\n token name is known.\n\n ```aiken\n values.prove_exact_nft(pid, tkn, that_value)\n ```","url":"assist/values.html#prove_exact_nft"},{"doc":"assist/values","title":"prove_nft","content":"prove_nft(pid: PolicyId, total: Value) -> Bool\n Proves that inside some value there is a policy id with a single token\n name that has a quantity of 1. This will show that a value contains an\n NFT or something that is nft-like. Should be useful to prove that\n something is holding a token inside a transaction when the token name\n is assumed to be unique.\n\n ```aiken\n values.prove_nft(pid, this_value)\n ```","url":"assist/values.html#prove_nft"},{"doc":"assist/values","title":"total_token_amount","content":"total_token_amount(\n inputs: List<Input>,\n pid: PolicyId,\n tkn: AssetName,\n counter: Int,\n) -> Int\n Calculate the total amount of a token within the set of inputs for the \n transaction. This function is useful when needing to get a total amount\n of one token inside a given transaction, like estimating if a threshold\n has been met.\n\n ```aiken\n values.total_token_amount(tx.inputs, datum.pid, datum.tkn, 0)\n ```","url":"assist/values.html#total_token_amount"},{"doc":"assist/values","title":"unique_token_name","content":"unique_token_name(txid: ByteArray, idx: Int, prefix: ByteArray) -> ByteArray\n Calculate a unique token name from a `TxId#Idx` and prefix. Can be combined\n with the `find` module to create unique token names from the first input\n utxo inside the transaction.\n\n ```aiken\n values.unique_token_name(tx_id, tx_idx, prefixes.prefix_333)\n ```","url":"assist/values.html#unique_token_name"},{"doc":"assist/values","title":"assist/values","content":" This module contains code that aids in various value \n manipulations and comparisons.\n","url":"assist/values.html"},{"doc":"assist/prefixes","title":"prefix_100","content":"prefix_100: ByteArray = #"000643b0"\n (100) Reference Token Prefix","url":"assist/prefixes.html#prefix_100"},{"doc":"assist/prefixes","title":"prefix_222","content":"prefix_222: ByteArray = #"000de140"\n (222) Non-Fungible Token Prefix","url":"assist/prefixes.html#prefix_222"},{"doc":"assist/prefixes","title":"prefix_333","content":"prefix_333: ByteArray = #"0014df10"\n (333) Fungible Token Prefix","url":"assist/prefixes.html#prefix_333"},{"doc":"assist/prefixes","title":"prefix_444","content":"prefix_444: ByteArray = #"001bc280"\n (444) Rich-Fungible Token Prefix","url":"assist/prefixes.html#prefix_444"},{"doc":"assist/prefixes","title":"prefix_555","content":"prefix_555: ByteArray = #"0022bfb0"\n (555) Pointer Token Prefix, NOT IMPLEMENTED IN CIP68\n This will be depreciated.","url":"assist/prefixes.html#prefix_555"},{"doc":"assist/prefixes","title":"prefix_callable","content":"prefix_callable: ByteArray = #"ca11ab1e"\n Callable Token Prefix\n This is the new pointer prefix","url":"assist/prefixes.html#prefix_callable"},{"doc":"assist/prefixes","title":"prefix_database","content":"prefix_database: ByteArray = #"da7aba5e"\n Database Token Prefix\n This is the new data reference prefix","url":"assist/prefixes.html#prefix_database"},{"doc":"assist/prefixes","title":"assist/prefixes","content":" This module provides the currently accepted token prefixes.\n","url":"assist/prefixes.html"},{"doc":"assist/signing","title":"verify_multisig","content":"verify_multisig(\n sigs: List<Hash<Blake2b_224, VerificationKey>>,\n vks: List<Hash<Blake2b_224, VerificationKey>>,\n minimum: Int,\n) -> Bool\n This counts the number of signatures inside a transaction that are from \n the list of signers then checks if its at least the minimum amount.\n\n ```aiken\n signing.verify_multisig(context.transaction, lst_of_sigs, sig_threshold)\n ```","url":"assist/signing.html#verify_multisig"},{"doc":"assist/signing","title":"verify_sig","content":"verify_sig(\n vks: List<Hash<Blake2b_224, VerificationKey>>,\n vk: Hash<Blake2b_224, VerificationKey>,\n) -> Bool\n Check if the list of signatures inside a transaction contains the\n verification key.\n\n ```aiken\n signing.verify_sig(context.transaction, wallet_pkh)\n ```","url":"assist/signing.html#verify_sig"},{"doc":"assist/signing","title":"assist/signing","content":" This module contains code for verifying transaction signatures. \n It assumes that all signatures provided are verification keys.\n","url":"assist/signing.html"},{"doc":"assist/data","title":"input_datum","content":"input_datum(possible_input: Input) -> Data\n Find the datum data on an input or error. The data is assumed\n to be an inline datum.\n\n ```aiken\n expect datum: Datum = data.input_datum(this_input)\n ```","url":"assist/data.html#input_datum"},{"doc":"assist/data","title":"output_datum","content":"output_datum(possible_output: Output) -> Data\n Find the datum data on an output or error. The data is assumed\n to be an inline datum.\n\n ```aiken\n expect datum: Datum = data.output_datum(that_output)\n ```","url":"assist/data.html#output_datum"},{"doc":"assist/data","title":"assist/data","content":" This module contains code for extracting data from a potential inline \n datum found in either an input or output.\n","url":"assist/data.html"},{"doc":"assist/maths","title":"base_q","content":"base_q(n: Int, q: Int) -> List<Int>\n Convert a integer `n` into some base `q`. This method\n should scale with any integer and any logical base.\n\n ```aiken\n maths.base_q(123, 7)\n ```","url":"assist/maths.html#base_q"},{"doc":"assist/maths","title":"decay","content":"decay(start_amt: Int, scale: Int, num: Int) -> Int\n Decay some starting amount logarithmically until zero. The function evaluates\n `y = a - log(n)` and when `n >= 2^a` the function equals zero but will return\n zero whenever the result is less than the scale. This is a great\n way to reduce some integer amount of something over time by incrementing `n`.\n\n ```aiken\n maths.decay(start_amount, lovelace_scaling, datum.current_int)\n ```","url":"assist/maths.html#decay"},{"doc":"assist/maths","title":"effective_ratio","content":"effective_ratio(amt: Int, pct: Int, scale: Int) -> Int\n Calculates the ratio of the amount `amt` multiplied by the scale by the\n percentage `pct`. The scale allows for finer calculations.\n\n ```aiken\n maths.effective_ratio(123456789, 40, 1000) == 3086419725\n ```","url":"assist/maths.html#effective_ratio"},{"doc":"assist/maths","title":"from_int","content":"from_int(self: Int) -> ByteArray\n Convert a integer into a hexadecimal bytearray. This works for all integers\n but odd length bytearrays will be prefixed with a zero. This function \n combined with the `to_int` function allows a string to represent a number\n and still be used for calculations, pushing the `2^64 - 1` integer boundary\n to `2^256 - 1`.\n\n ```aiken\n maths.from_int(44203)\n ```","url":"assist/maths.html#from_int"},{"doc":"assist/maths","title":"gcd","content":"gcd(a: Int, b: Int) -> Int\n Computes greatest common divisor of two numbers.\n\n ```aiken\n maths.gcd(20, 15)\n ```","url":"assist/maths.html#gcd"},{"doc":"assist/maths","title":"is_in_range","content":"is_in_range(n: Int, lb: Int, ub: Int) -> Bool\n Verify that some integer `n` is greater than the lower bound, `lb`, and\n less than or equal to the upper bound, `ub`. The function is exclusive\n for `lb` but inclusive for `lb + 1`.\n\n ```aiken\n maths.is_in_range(5, 0, 10)\n ```","url":"assist/maths.html#is_in_range"},{"doc":"assist/maths","title":"legendre_symbol","content":"legendre_symbol(a: Int, p: Int) -> Int\n Calculate the Legendre symbol `(a/p)` using the Euler's criterion.\n This implementation assumes that 'a' and 'p' are positive integers.\n\n ```aiken\n maths.legendre_symbol(10, 19)\n ```","url":"assist/maths.html#legendre_symbol"},{"doc":"assist/maths","title":"list_powmod","content":"list_powmod(lst: List<Int>, g: Int, q: Int) -> Int\n Computes the power mod product of a list of integers.\n\n ```aiken\n maths.list_pow_mod([1,2,3], 2, 19)\n ```","url":"assist/maths.html#list_powmod"},{"doc":"assist/maths","title":"list_product","content":"list_product(lst: List<Int>) -> Int\n Computes the product of a list of integers.\n\n ```aiken\n maths.list_product([1,2,3])\n ```","url":"assist/maths.html#list_product"},{"doc":"assist/maths","title":"list_sum","content":"list_sum(lst: List<Int>) -> Int\n Computes the sum of a list of integers.\n\n ```aiken\n maths.list_sum(list_of_integers)\n ```","url":"assist/maths.html#list_sum"},{"doc":"assist/maths","title":"powmod","content":"powmod(n: Int, e: Int, q: Int) -> Int\n Calculate `n` to the power of `e` modulo `q` using the exponentiation by \n squaring method. At each multiplication a modulo is calculated, allowing\n very large `n` and `e` values.\n\n ```aiken\n maths.powmod(3, 2, 5)\n ```","url":"assist/maths.html#powmod"},{"doc":"assist/maths","title":"ratio","content":"ratio(amt: Int, pct: Int) -> Int\n Calculates the ratio of the amount `amt` by a percentage `pct`. This can\n be used to calculate rough percentages. The function `ratio` is just a \n special case of the effective ratio function. \n\n ```aiken\n maths.ratio(123, 40)\n ```","url":"assist/maths.html#ratio"},{"doc":"assist/maths","title":"scaling","content":"scaling(amt: Int, pct: Int) -> Int\n Find the optimal scaling for a number such that it\n has three trailing zeros. This should be used in combination\n with the effective ratio for optimal calculations.\n\n ```aiken\n maths.scaling(123, 40)\n ```","url":"assist/maths.html#scaling"},{"doc":"assist/maths","title":"to_int","content":"to_int(self: ByteArray) -> Int\n Convert a hexadecimal bytearray into its base 10 representation. This\n only works with even length bytearrays so arbitrary numbers in hexadecimal\n form will not in general work.\n\n ```aiken\n maths.to_int(#"acab")\n ```","url":"assist/maths.html#to_int"},{"doc":"assist/maths","title":"assist/maths","content":" This module incorporates code for various mathematical operations.\n","url":"assist/maths.html"},{"doc":"assist/certificates","title":"create_credential_delegation","content":"create_credential_delegation(\n sc: Hash<Blake2b_224, Script>,\n pool_id: PoolId,\n) -> Certificate\n Creates a credential delegation for changing the location of the stake.\n This certificate can be used to check if stake is being delegated to\n a specific pool.\n\n ```aiken\n certificates.create_credential_delegation(datum.contract_hash, datum.pool_id)\n ```","url":"assist/certificates.html#create_credential_delegation"},{"doc":"assist/certificates","title":"assist/certificates","content":"","url":"assist/certificates.html"},{"doc":"assist/count","title":"inputs_by_addr","content":"inputs_by_addr(inputs: List<Input>, addr: Address, amount: Int) -> Bool\n Verify that the number of inputs from a specific script is equal to the\n amount intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.inputs_by_addr(tx.inputs, this_addr, 1)\n ```","url":"assist/count.html#inputs_by_addr"},{"doc":"assist/count","title":"inputs_by_datum","content":"inputs_by_datum(inputs: List<Input>, amount: Int) -> Bool\n Verify that the number of inputs with an inline datum is equal to the\n number intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.inputs_by_datum(tx.inputs, 1)\n ```","url":"assist/count.html#inputs_by_datum"},{"doc":"assist/count","title":"outputs_by_addr","content":"outputs_by_addr(outputs: List<Output>, addr: Address, amount: Int) -> Bool\n Verify that the number of outputs from a specific script is equal the amount\n intended in the contract. The amount must be exact with the counter.\n\n ```aiken\n count.outputs_by_addr(tx.outputs, this_addr, 1)\n ```","url":"assist/count.html#outputs_by_addr"},{"doc":"assist/count","title":"outputs_by_datum","content":"outputs_by_datum(outputs: List<Output>, amount: Int) -> Bool\n Verify that the number of outputs with an inline datum is equal to the\n number intended in the contract. The amount must be exactly the counter.\n\n ```aiken\n count.outputs_by_datum(tx.outputs, 1)\n ```","url":"assist/count.html#outputs_by_datum"},{"doc":"assist/count","title":"assist/count","content":" This module contains code to accurately count the number of inputs and\n outputs in a transaction for a specific address, assuming precise amounts.\n","url":"assist/count.html"},{"doc":"assist/addresses","title":"create_address","content":"create_address(\n pkh: Hash<Blake2b_224, VerificationKey>,\n sc: Hash<Blake2b_224, VerificationKey>,\n) -> Address\n Creates a enterprise or base address from the public key hash and stake\n credential. An empty sc means enterpise address by default.\n\n ```aiken\n addresses.create_address(datum.wallet.pkh, datum.wallet.sc)\n ```","url":"assist/addresses.html#create_address"},{"doc":"assist/addresses","title":"create_script_address","content":"create_script_address(\n pkh: Hash<Blake2b_224, Script>,\n sc: Hash<Blake2b_224, Script>,\n) -> Address\n Creates a script address for a smart contract. The type does not mix address\n types. Staked smart contracts are contracts as well. An empty sc is\n assumed to be not staked.\n\n ```aiken\n addresses.create_script_address(datum.script.pkh, datum.script.sc)\n ```","url":"assist/addresses.html#create_script_address"},{"doc":"assist/addresses","title":"assist/addresses","content":" This module incorporates code for generating valid wallet and script \n addresses, ensuring their correctness. Empty keys are treated as \n intentional, and address subtypes are not combined or mixed.\n","url":"assist/addresses.html"},{"doc":"assist/std","title":"out_ref","content":"out_ref(tx_id_hash: ByteArray, idx: Int) -> OutputReference\n Create an `OutputReference` from the `TxId#Idx` information. This is useful\n for building correct output references of specific UTxOs. It can be combined\n with the `find` module for some very convenient requests.\n\n ```aiken\n std.out_ref(that_tx_id, that_tx_idx)\n ```","url":"assist/std.html#out_ref"},{"doc":"assist/std","title":"assist/std","content":" This module incorporates additional code that expands the\n functionality of the standard library.\n","url":"assist/std.html"},{"doc":"assist/minting","title":"by_prefix","content":"by_prefix(\n flat: List<(ByteArray, ByteArray, Int)>,\n pid: ByteArray,\n prefix: ByteArray,\n amt: Int,\n) -> Bool\n This checks if a specific policy id, prefix, and amount exist inside\n the flattened exact value. Instead of searching for exact match, it\n checks if the token name has the correct prefix. This works if\n every token name on the policy id is unique. If found then it returns\n True else False.\n\n ```aiken\n minting.by_prefix(flatten_mint_value, pid, tkn, 1)\n ```","url":"assist/minting.html#by_prefix"},{"doc":"assist/minting","title":"exact","content":"exact(\n flat: List<(ByteArray, ByteArray, Int)>,\n pid: ByteArray,\n tkn: ByteArray,\n amt: Int,\n) -> Bool\n This checks if a specific policy id, token name, and amount exist inside\n the flattened exact value. It is searching for an exact match. If found\n then it returns True else False.\n\n ```aiken\n minting.exact(flatten_mint_value, pid, tkn, 1)\n ```","url":"assist/minting.html#exact"},{"doc":"assist/minting","title":"is_occurring","content":"is_occurring(\n flat: List<(ByteArray, ByteArray, Int)>,\n pid: ByteArray,\n tkn: ByteArray,\n) -> Bool\n Prove that a transaction is minting something from a specific policy id \n and token name but the amount does not matter. This is great for lock-n-mint\n style contracts where some logic just needs to check if a mint is occuring\n but not the specifics of the amount being minted or burned. If a mint is\n occurring then it will return True else False.\n\n ```aiken\n minting.is_occurring(flatten_mint_value, pid, tkn)\n ```","url":"assist/minting.html#is_occurring"},{"doc":"assist/minting","title":"assist/minting","content":"","url":"assist/minting.html"},{"doc":"assist/payout","title":"at_least","content":"at_least(\n payout_address: Address,\n payout_value: Value,\n outputs: List<Output>,\n) -> Bool\n Find the first occurrence of an output that contains at least some specific\n value at some address. If nothing is found then return False. This function\n does not search for an exact UTxO match.\n\n ```aiken\n payout.at_least(wallet_addr, just_token_value, tx.outputs)\n ```","url":"assist/payout.html#at_least"},{"doc":"assist/payout","title":"cont","content":"cont(payout_address: Address, outputs: List<Output>) -> Bool\n Find the first occurrence of an output at some address. If nothing is \n found then return False. This function does not search by value.\n\n ```aiken\n payout.cont(that_script_addr, tx.outputs)\n ```","url":"assist/payout.html#cont"},{"doc":"assist/payout","title":"exact","content":"exact(\n payout_address: Address,\n payout_value: Value,\n outputs: List<Output>,\n) -> Bool\n Find the first occurrence of an exact output that matches a specific\n address and value. If nothing is found then return False.\n\n ```aiken\n payout.exact(wallet_addr, validating_value, tx.outputs)\n ```","url":"assist/payout.html#exact"},{"doc":"assist/payout","title":"assist/payout","content":" This module contains code that assists with payout logic. Payout\n functions are designed to return a boolean value instead of an error.\n","url":"assist/payout.html"},{"doc":"tests/fake_tx","title":"test_input","content":"test_input() -> Input\n A fake input used for testing.","url":"tests/fake_tx.html#test_input"},{"doc":"tests/fake_tx","title":"test_inputs","content":"test_inputs(amt: Int) -> List<Input>\n A fake input used for testing.","url":"tests/fake_tx.html#test_inputs"},{"doc":"tests/fake_tx","title":"test_out_ref","content":"test_out_ref() -> OutputReference\n Creates an `OutputReference`","url":"tests/fake_tx.html#test_out_ref"},{"doc":"tests/fake_tx","title":"test_output","content":"test_output() -> Output\n A fake output used for testing.","url":"tests/fake_tx.html#test_output"},{"doc":"tests/fake_tx","title":"test_signatories","content":"test_signatories() -> List<ByteArray>\n A fake list of tx signers","url":"tests/fake_tx.html#test_signatories"},{"doc":"tests/fake_tx","title":"test_tx","content":"test_tx() -> Transaction\n A fake transaction used for testing.","url":"tests/fake_tx.html#test_tx"},{"doc":"tests/fake_tx","title":"DataType","content":"DataType = Data\n A `Data`data type\n","url":"tests/fake_tx.html#DataType"},{"doc":"tests/fake_tx","title":"test_datum","content":"test_datum: ByteArray = #"acabbeeffacecafe"\n A test datum.","url":"tests/fake_tx.html#test_datum"},{"doc":"tests/fake_tx","title":"tests/fake_tx","content":" This is for testing only.\n","url":"tests/fake_tx.html"}]); \ No newline at end of file diff --git a/docs/tests/fake_tx.html b/docs/tests/fake_tx.html index 9710d38..68bc405 100644 --- a/docs/tests/fake_tx.html +++ b/docs/tests/fake_tx.html @@ -7,8 +7,8 @@ - - + + - + + - - + + - + \ No newline at end of file diff --git a/lib/assist/minting.ak b/lib/assist/minting.ak index 4ba6ee5..afe6442 100644 --- a/lib/assist/minting.ak +++ b/lib/assist/minting.ak @@ -7,6 +7,9 @@ use assist/prefixes /// the flattened exact value. It is searching for an exact match. If found /// then it returns True else False. /// +/// ```aiken +/// minting.exact(flatten_mint_value, pid, tkn, 1) +/// ``` pub fn exact( flat: List<(ByteArray, ByteArray, Int)>, pid: ByteArray, @@ -66,6 +69,9 @@ test empty_exact_mint() { /// every token name on the policy id is unique. If found then it returns /// True else False. /// +/// ```aiken +/// minting.by_prefix(flatten_mint_value, pid, tkn, 1) +/// ``` pub fn by_prefix( flat: List<(ByteArray, ByteArray, Int)>, pid: ByteArray, @@ -116,3 +122,48 @@ test empty_by_prefix_mint() { let flat = value.zero() |> value.flatten() by_prefix(flat, #"", #"", 0) == False } + +/// Prove that a transaction is minting something from a specific policy id +/// and token name but the amount does not matter. This is great for lock-n-mint +/// style contracts where some logic just needs to check if a mint is occuring +/// but not the specifics of the amount being minted or burned. If a mint is +/// occurring then it will return True else False. +/// +/// ```aiken +/// minting.is_occurring(flatten_mint_value, pid, tkn) +/// ``` +pub fn is_occurring( + flat: List<(ByteArray, ByteArray, Int)>, + pid: ByteArray, + tkn: ByteArray, +) -> Bool { + when flat is { + // loop the minted value + [(policy, token_name, _), ..rest] -> + if list.and([policy == pid, token_name == tkn]) == True { + True + } else { + is_occurring(rest, pid, tkn) + } + // something wasn't found + [] -> False + } +} + +test tx_is_empty_minting() { + let flat = + [] + is_occurring(flat, #"acab", prefixes.prefix_222) == False +} + +test tx_is_minting() { + let flat = + value.from_asset(#"acab", prefixes.prefix_222, 1) |> value.flatten() + is_occurring(flat, #"acab", prefixes.prefix_222) == True +} + +test tx_is_not_minting() { + let flat = + value.from_asset(#"acab", prefixes.prefix_222, 1) |> value.flatten() + is_occurring(flat, #"acab", prefixes.prefix_333) == False +} diff --git a/lib/assist/prefixes.ak b/lib/assist/prefixes.ak index 4aea5e6..6404bba 100644 --- a/lib/assist/prefixes.ak +++ b/lib/assist/prefixes.ak @@ -14,4 +14,13 @@ pub const prefix_333 = #"0014df10" pub const prefix_444 = #"001bc280" /// (555) Pointer Token Prefix, NOT IMPLEMENTED IN CIP68 -pub const prefix_555 = #"0022bfb0" \ No newline at end of file +/// This will be depreciated. +pub const prefix_555 = #"0022bfb0" + +/// Callable Token Prefix +/// This is the new pointer prefix +pub const prefix_callable = #"ca11ab1e" + +/// Database Token Prefix +/// This is the new data reference prefix +pub const prefix_database = #"da7aba5e" diff --git a/lib/assist/values.ak b/lib/assist/values.ak index 2daaafc..91fd12c 100644 --- a/lib/assist/values.ak +++ b/lib/assist/values.ak @@ -7,8 +7,10 @@ use aiken/dict use aiken/hash use aiken/list use aiken/string +use aiken/transaction.{Input} use aiken/transaction/value.{AssetName, PolicyId, Value} use assist/prefixes +use tests/fake_tx /// Multiply some value by `n`. This is just a linear scaling to the quantity /// of each token. @@ -282,3 +284,56 @@ test missing_exact_nft() { |> value.merge(value.from_asset(#"face", #"beef", 40)) prove_exact_nft(#"acab", #"beef", val) == False } + +/// Calculate the total amount of a token within the set of inputs for the +/// transaction. This function is useful when needing to get a total amount +/// of one token inside a given transaction, like estimating if a threshold +/// has been met. +/// +/// ```aiken +/// values.total_token_amount(tx.inputs, datum.pid, datum.tkn, 0) +/// ``` +pub fn total_token_amount( + inputs: List, + pid: PolicyId, + tkn: AssetName, + counter: Int, +) -> Int { + when inputs is { + [input, ..rest] -> { + let amt = value.quantity_of(input.output.value, pid, tkn) + total_token_amount(rest, pid, tkn, counter + amt) + } + [] -> counter + } +} + +test count_pid1() { + let amt = 1 + let inputs = fake_tx.test_inputs(amt) + total_token_amount(inputs, #"acab", #"beef", 0) == amt * 100 +} + +test count_pid2() { + let amt = 2 + let inputs = fake_tx.test_inputs(amt) + total_token_amount(inputs, #"acab", #"beef", 0) == amt * 100 +} + +test count_pid3() { + let amt = 4 + let inputs = fake_tx.test_inputs(amt) + total_token_amount(inputs, #"acab", #"beef", 0) == amt * 100 +} + +test count_pid4() { + let amt = 8 + let inputs = fake_tx.test_inputs(amt) + total_token_amount(inputs, #"acab", #"beef", 0) == amt * 100 +} + +test count_pid5() { + let amt = 16 + let inputs = fake_tx.test_inputs(amt) + total_token_amount(inputs, #"acab", #"beef", 0) == amt * 100 +} diff --git a/lib/tests/fake_tx.ak b/lib/tests/fake_tx.ak index a2cf99d..d009e65 100644 --- a/lib/tests/fake_tx.ak +++ b/lib/tests/fake_tx.ak @@ -3,6 +3,7 @@ use aiken/dict use aiken/interval.{Interval, IntervalBound, NegativeInfinity, PositiveInfinity} +use aiken/list use aiken/transaction.{ InlineDatum, Input, NoDatum, Output, OutputReference, Spend, Transaction, TransactionId, @@ -13,8 +14,7 @@ use assist/addresses use assist/credentials /// A test datum. -pub const test_datum: ByteArray = - #"acabbeeffacecafe" +pub const test_datum: ByteArray = #"acabbeeffacecafe" /// A `Data`data type pub type DataType = @@ -30,6 +30,24 @@ pub fn test_out_ref() -> OutputReference { out_ref } +/// A fake input used for testing. +pub fn test_inputs(amt: Int) -> List { + let input = + Input { + output_reference: OutputReference { + transaction_id: TransactionId { hash: #"acab" }, + output_index: 0, + }, + output: Output { + address: addresses.create_address(#"acab", #""), + value: value.from_asset(#"acab", #"beef", 100), + datum: InlineDatum(#""), + reference_script: None, + }, + } + list.repeat(input, amt) +} + /// A fake input used for testing. pub fn test_input() -> Input { let input = @@ -77,15 +95,12 @@ pub fn test_signatories() -> List { /// A fake transaction used for testing. pub fn test_tx() -> Transaction { - let sc: StakeCredential = - credentials.create_stake_credential(#"face") - let out_ref = - test_out_ref() + let sc: StakeCredential = credentials.create_stake_credential(#"face") + let out_ref = test_out_ref() let withdrawal = dict.new() |> dict.insert(key: sc, value: 100, compare: fn(_, _) { Equal }) - let d: DataType = - 1 + let d: DataType = 1 let redeem = dict.new() |> dict.insert(key: Spend(out_ref), value: d, compare: fn(_, _) { Equal })