Make basic script a template, and add more assertions.
This commit is contained in:
@@ -1,6 +1,43 @@
|
||||
use aiken/list
|
||||
use aiken/transaction.{ScriptContext}
|
||||
use aiken/option
|
||||
use aiken/transaction.{ScriptContext, Spend, TransactionId}
|
||||
use aiken/transaction/credential.{VerificationKeyCredential}
|
||||
use aiken/transaction/value
|
||||
|
||||
fn spend(_datum: Void, _redeemer: Void, ctx: ScriptContext) {
|
||||
list.length(ctx.transaction.outputs) == 1
|
||||
[
|
||||
assert_purpose(ctx.purpose),
|
||||
assert_outputs(ctx.transaction),
|
||||
assert_fee(ctx.transaction),
|
||||
]
|
||||
|> list.and
|
||||
}
|
||||
|
||||
fn assert_purpose(purpose) {
|
||||
when purpose is {
|
||||
Spend(ref) ->
|
||||
ref.transaction_id == TransactionId(
|
||||
#"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
) && ref.output_index == 0
|
||||
_ -> error("script purpose isn't 'Spend'")
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_fee(transaction) {
|
||||
transaction.fee == value.from_lovelace(42)
|
||||
}
|
||||
|
||||
fn assert_outputs(transaction) {
|
||||
when transaction.outputs is {
|
||||
[output] ->
|
||||
[
|
||||
output.value == value.from_lovelace(1000000000),
|
||||
output.address.payment_credential == VerificationKeyCredential(
|
||||
#"11111111111111111111111111111111111111111111111111111111",
|
||||
),
|
||||
option.is_none(output.address.stake_credential),
|
||||
]
|
||||
|> list.and
|
||||
_ -> error("unexpected number of outputs")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user