Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
keyan-m committed Nov 28, 2024
1 parent de740fb commit 1bc7149
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
5 changes: 1 addition & 4 deletions on-chain/lib/cardano-account/tests.ak
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ use aiken/fuzz.{and_then}
use aiken/primitive/bytearray
use cardano/address.{Address, Inline, Script, VerificationKey}
use cardano/assets.{Value}
use cardano/transaction.{
Datum, Input, NoDatum, Output, OutputReference,
}
use cardano/transaction.{Datum, Input, NoDatum, Output, OutputReference}
use cardano/transaction/output_reference as output_reference
use cardano_account/utils as utils


const sample_outputs =
#"9fd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e01d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa140a1401a00030d40d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e02d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa140a1401a00030d40d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e07d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e01d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa140a1401a00030d40d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e02d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa140a1401a00030d40d87b9f01ffd87a80ffd8799fd8799fd87a9f581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616ffd87a80ffa240a1401a00030d40581c9ee6dfb61a2fb903df487c401663825643bb825d41695e63df8af616a1419e03d87b9f01ffd87a80ffff"

Expand Down
14 changes: 14 additions & 0 deletions on-chain/lib/cardano-account/utils.ak
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ pub fn foldl6(
}
}

pub fn foldr6(
self: List<x>,
zero_a: a,
zero_b: b,
zero_c: c,
zero_d: d,
zero_e: e,
zero_f: f,
with: fn(x, a, b, c, d, e, f, Scott6<a, b, c, d, e, f, result>) -> result,
return: Scott6<a, b, c, d, e, f, result>,
) -> result {
do_foldr6(self, with, return)(zero_a, zero_b, zero_c, zero_d, zero_e, zero_f)
}

pub fn sort_inputs(inputs: List<Input>) -> List<Input> {
inputs
|> list.sort(
Expand Down
12 changes: 8 additions & 4 deletions on-chain/validators/record.ak
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ validator record(utxo_ref: OutputReference) {
// 3. Two UTxOs are produced at the script: list head at index 0, record
// validator's deployed script at index 1
// 4. List head's output datum is
// `Entry { next_username: None, contributor }`
// `Entry { next_username: None }`
// where the contributor can be set arbitrarily
// 5. Reference UTxO has no datum attached
// 6. Each of the two produced UTxOs carry one of the nameless tokens
Expand Down Expand Up @@ -599,7 +599,8 @@ validator record(utxo_ref: OutputReference) {
AuthorizedSpend { signature, accounts_input_index, intent } -> {
expect Some(input_datum) = datum

expect Account { pubkey, contribution_return, .. }: RecordDatum = input_datum
expect Account { pubkey, contribution_return, .. }: RecordDatum =
input_datum

expect Output {
address: Address { payment_credential: Script(own_script_hash), .. } as own_address,
Expand All @@ -621,8 +622,11 @@ validator record(utxo_ref: OutputReference) {
..
] = outputs

expect Account { pubkey: cont_pubkey, salt: cont_salt, contribution_return: cont_contribution_return }: RecordDatum =
cont_datum_data
expect Account {
pubkey: cont_pubkey,
salt: cont_salt,
contribution_return: cont_contribution_return,
}: RecordDatum = cont_datum_data

// 1. Input account UTxO must be authentic
// 2. Outputs must be signed by input account's stored `pubkey`
Expand Down
18 changes: 9 additions & 9 deletions on-chain/validators/treasury.ak
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
////
//// This contract allows a single UTxO to be spent for each new account. One
//// other requirement is that all newly created UTxOs must have staking parts
//// that match that of the UTxO's contributor (store in datum).
//// that match that of the UTxO's contributor (stored in datum).

// === IMPORTS =================================================================
use aiken/collection/list
Expand Down Expand Up @@ -34,8 +34,8 @@ validator treasury(record_script_hash: ScriptHash) {
let mint_qty = utils.get_single_mint_quantity_of(mint, record_script_hash)
expect (mint_qty == 4)?

// Apart from UTxOs spent from `record` script, only one script UTxO is
// expected to be spent, which will be from this `treasury` contract.
// Apart from UTxOs spent from `record` script, only one UTxO is expected
// to be spent, which will be from this `treasury` contract.
let records_script = Script(record_script_hash)
expect [Input { output: Output { address: treasury_address, .. }, .. }] =
list.filter(
Expand Down Expand Up @@ -93,14 +93,14 @@ validator treasury(record_script_hash: ScriptHash) {
and {
// Staking parts of the 4 newly produced UTxOs must match that of
// contributor's
new_entrys_stake_credential == contributors_stake_credential,
users_account_stake_credential == contributors_stake_credential,
spending_ref_script_stake_credential == contributors_stake_credential,
staking_ref_script_stake_credential == contributors_stake_credential,
contributors_stake_credential == new_entrys_stake_credential,
contributors_stake_credential == users_account_stake_credential,
contributors_stake_credential == spending_ref_script_stake_credential,
contributors_stake_credential == staking_ref_script_stake_credential,
// Contributor must be stored in record entry's datum
users_account_contributor == contributor,
contributor == users_account_contributor,
// This treausry's address must also be correctly stored.
users_account_treasury_address == treasury_address,
treasury_address == users_account_treasury_address,
}?
}

Expand Down

0 comments on commit 1bc7149

Please sign in to comment.