Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
iburzynski committed Feb 11, 2024
1 parent e1fc825 commit 80fc14b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
10 changes: 2 additions & 8 deletions lib/utils.ak
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aiken/hash.{Blake2b_224, Hash}
use aiken/list.{filter}
use aiken/transaction.{Input, Output, ScriptContext, Spend, find_input} as tx
use aiken/transaction.{Input, Output, ScriptContext, Spend, find_input}
use aiken/transaction/credential.{VerificationKey}

pub type POSIXTime =
Expand All @@ -25,14 +25,8 @@ pub fn find_own_input(ctx: ScriptContext) -> Option<Input> {
}
}

// getContinuingOutputs :: ScriptContext -> [TxOut]
// getContinuingOutputs ctx | Just TxInInfo{txInInfoResolved=TxOut{txOutAddress}} <- findOwnInput ctx = filter (f txOutAddress) (txInfoOutputs $ scriptContextTxInfo ctx)
// where
// f addr TxOut{txOutAddress=otherAddress} = addr == otherAddress
// getContinuingOutputs _ = traceError "Lf" -- "Can't get any continuing outputs"

pub fn get_continuing_outputs(ctx: ScriptContext) -> List<Output> {
expect Some(input) = find_own_input(ctx)
let script_address = input.output.address
filter(ctx.transaction.outputs, fn(o) { o.address == script_address })
filter(ctx.transaction.outputs, fn(o: Output) { o.address == script_address })
}
4 changes: 2 additions & 2 deletions validators/samples/minting.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use aiken/dict as dict
use aiken/list as list
use aiken/list.{any} as list
use aiken/transaction.{Input, OutputReference, ScriptContext, Transaction} as tx
use aiken/transaction/value.{AssetName, MintedValue, PolicyId}

Expand Down Expand Up @@ -29,7 +29,7 @@ validator(token_name: ByteArray, oref: OutputReference) {
}

fn has_utxo(oref: OutputReference, inputs: List<Input>) {
list.any(inputs, fn(input) { input.output_reference == oref })
any(inputs, fn(input) { input.output_reference == oref })
}

fn check_mint(cs: PolicyId, tn: AssetName, mint: MintedValue, mint_qty: Int) {
Expand Down
1 change: 0 additions & 1 deletion validators/samples/typed.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use aiken/transaction.{ScriptContext}
use utils.{trace_if_false}

validator {
fn simple_typed(_datum: Void, redeemer: Int, _ctx: ScriptContext) -> Bool {
Expand Down
8 changes: 4 additions & 4 deletions validators/samples/vesting.ak
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use aiken/interval.{Finite}
use aiken/list
use aiken/transaction.{ScriptContext, Transaction, ValidityRange}
use utils.{POSIXTime, PubKeyHash, trace_if_false}
use utils.{POSIXTime, PubKeyHash}

type VestingDatum {
beneficiary: PubKeyHash,
Expand Down Expand Up @@ -33,13 +33,13 @@ fn must_start_after(range: ValidityRange, maturity: POSIXTime) {

validator(beneficiary: PubKeyHash) {
fn param_vesting(
datum: POSIXTime,
maturity: POSIXTime,
_redeemer: Void,
ctx: ScriptContext,
) -> Bool {
must_be_signed_by(ctx.transaction, datum.beneficiary)? && must_start_after(
must_be_signed_by(ctx.transaction, beneficiary)? && must_start_after(
ctx.transaction.validity_range,
datum.maturity,
maturity,
)?
}
}

0 comments on commit 80fc14b

Please sign in to comment.