-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use aiken/hash.{Blake2b_224, Hash} | ||
use aiken/list | ||
use aiken/transaction.{ | ||
OutputReference, ScriptContext, Spend, Transaction, TransactionId, | ||
} | ||
use aiken/transaction/credential.{VerificationKey} | ||
|
||
type MyRedeemer { | ||
message: ByteArray, | ||
} | ||
|
||
type PubKeyHash = | ||
Hash<Blake2b_224, VerificationKey> | ||
|
||
type MyDatum { | ||
owner: PubKeyHash, | ||
} | ||
|
||
const unlock_message = "aiken rocks" | ||
|
||
validator { | ||
fn unlock(datum: MyDatum, redeemer: MyRedeemer, context: ScriptContext) { | ||
let must_be_signed = | ||
list.has(context.transaction.extra_signatories, datum.owner) | ||
|
||
must_be_signed && redeemer.message == unlock_message | ||
|
||
// let MyDatum { owner } = datum | ||
// let MyRedeemer { message } = redeemer | ||
// let ScriptContext { purpose, .. } = context | ||
|
||
// when purpose is { | ||
// Spend(_oref) -> { | ||
// let must_be_signed = | ||
// list.has(context.transaction.extra_signatories, owner) | ||
|
||
// must_be_signed && message == "hello world" | ||
// } | ||
// _ -> False | ||
// } | ||
} | ||
} | ||
|
||
// Validator Tests | ||
test unlock_test_fail_message() fail { | ||
let redeemer = MyRedeemer { message: "wrong message" } | ||
let datum = | ||
MyDatum { | ||
owner: #"00000000000000000000000000000000000000000000000000000000", | ||
} | ||
|
||
let placeholder_oref = | ||
OutputReference { transaction_id: TransactionId(""), output_index: 0 } | ||
let context = | ||
ScriptContext { | ||
purpose: Spend(placeholder_oref), | ||
transaction: transaction.placeholder(), | ||
} | ||
|
||
unlock(datum, redeemer, context) | ||
} | ||
|
||
test unlock_test_fail_owner() fail { | ||
let redeemer = MyRedeemer { message: unlock_message } | ||
let datum = | ||
MyDatum { | ||
owner: #"00000000000000000000000000000000000000000000000000000000", | ||
} | ||
|
||
let placeholder_oref = | ||
OutputReference { transaction_id: TransactionId(""), output_index: 0 } | ||
let context = | ||
ScriptContext { | ||
purpose: Spend(placeholder_oref), | ||
transaction: transaction.placeholder(), | ||
} | ||
|
||
unlock(datum, redeemer, context) | ||
} | ||
|
||
test unlock_test() { | ||
let redeemer = MyRedeemer { message: unlock_message } | ||
let datum = | ||
MyDatum { | ||
owner: #"00000000000000000000000000000000000000000000000000000000", | ||
} | ||
|
||
let placeholder_oref = | ||
OutputReference { transaction_id: TransactionId(""), output_index: 0 } | ||
let context = | ||
ScriptContext { | ||
purpose: Spend(placeholder_oref), | ||
transaction: transaction.placeholder() | ||
|> fn(transaction) { | ||
Transaction { ..transaction, extra_signatories: [datum.owner] } | ||
}, | ||
} | ||
|
||
unlock(datum, redeemer, context) | ||
} |