Refresh gift_card and hello_world examples.

This commit is contained in:
KtorZ 2024-09-01 18:16:39 +02:00
parent 7bfc01413b
commit 9f6daa8cd5
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
13 changed files with 30 additions and 33 deletions

View File

@ -1,6 +1,6 @@
use aiken/transaction/value use cardano/assets
test test_quantity_of_1() { test test_quantity_of_1() {
let x = value.from_asset(#"000000", #"000020e05363726970744f776e6572", -1) let x = assets.from_asset(#"000000", #"000020e05363726970744f776e6572", -1)
value.quantity_of(x, #"000000", #"000020e05363726970744f776e6572") < 0 assets.quantity_of(x, #"000000", #"000020e05363726970744f776e6572") < 0
} }

View File

@ -1,7 +1,7 @@
use aiken/bytearray.{from_string} use aiken/collection/list
use aiken/hash.{Hash, Sha2_256, sha2_256} use aiken/crypto.{Hash, Sha2_256, sha2_256}
use aiken/list
use aiken/option.{choice, is_none} use aiken/option.{choice, is_none}
use aiken/primitive/bytearray.{from_string}
// Construction of the merkle tree shouldn't be done by hand, but via // Construction of the merkle tree shouldn't be done by hand, but via
// 'from_list'. // 'from_list'.

View File

@ -1,7 +1,6 @@
use aiken/bytearray use aiken/collection/dict.{Dict}
use aiken/dict.{Dict} use aiken/crypto.{Blake2b_224, Hash, Script}
use aiken/hash.{Blake2b_224, Hash} use aiken/primitive/bytearray
use aiken/transaction/credential.{Script}
pub type PolicyId = pub type PolicyId =
Hash<Blake2b_224, Script> Hash<Blake2b_224, Script>
@ -13,9 +12,7 @@ pub opaque type Value {
inner: Dict<PolicyId, Dict<AssetName, Int>>, inner: Dict<PolicyId, Dict<AssetName, Int>>,
} }
pub fn zero() -> Value { pub const zero: Value = Value { inner: dict.empty }
Value { inner: dict.new() }
}
pub fn from_asset( pub fn from_asset(
policy_id: PolicyId, policy_id: PolicyId,
@ -23,9 +20,9 @@ pub fn from_asset(
quantity: Int, quantity: Int,
) -> Value { ) -> Value {
let asset = let asset =
dict.new() dict.empty
|> dict.insert(asset_name, quantity) |> dict.insert(asset_name, quantity)
dict.new() dict.empty
|> dict.insert(policy_id, asset) |> dict.insert(policy_id, asset)
|> Value |> Value
} }
@ -86,12 +83,12 @@ pub fn flatten_with(
} }
test flatten_with_1() { test flatten_with_1() {
flatten_with(zero(), fn(p, a, q) { Some((p, a, q)) }) == [] flatten_with(zero, fn(p, a, q) { Some((p, a, q)) }) == []
} }
test flatten_with_2() { test flatten_with_2() {
let v = let v =
zero() zero
|> add(from_asset("a", "1", 14)) |> add(from_asset("a", "1", 14))
|> add(from_asset("b", "", 42)) |> add(from_asset("b", "", 42))
|> add(from_asset("a", "2", 42)) |> add(from_asset("a", "2", 42))

View File

@ -1,7 +1,7 @@
use aiken/bytearray.{from_string} use aiken/collection/list
use aiken/hash.{Hash, Sha2_256, sha2_256} use aiken/crypto.{Hash, Sha2_256, sha2_256}
use aiken/list
use aiken/option.{choice, is_none} use aiken/option.{choice, is_none}
use aiken/primitive/bytearray.{from_string}
/// Variant of MerkleTree with only hash but without actual value /// Variant of MerkleTree with only hash but without actual value
pub type MerkleTree<a> { pub type MerkleTree<a> {

View File

@ -1,6 +1,6 @@
use aiken/builtin.{snd_pair} use aiken/builtin.{snd_pair}
use aiken/cbor use aiken/cbor
use aiken/list use aiken/collection/list
test tuple_when() { test tuple_when() {
let items = let items =

View File

@ -1,6 +1,6 @@
use aiken/collection/list use aiken/collection/list
use cardano/assets
use cardano/address.{Address, VerificationKey} use cardano/address.{Address, VerificationKey}
use cardano/assets
use cardano/transaction.{Input, NoDatum, Output, OutputReference, Transaction} use cardano/transaction.{Input, NoDatum, Output, OutputReference, Transaction}
pub const own_hash = #"01020304050607080910111213140102030405060708091011121314" pub const own_hash = #"01020304050607080910111213140102030405060708091011121314"
@ -46,7 +46,7 @@ test test_simple_oneshot() {
let output = let output =
Output { Output {
address: beneficiary_address(), address: beneficiary_address(),
value: assets.zero(), value: assets.zero,
datum: NoDatum, datum: NoDatum,
reference_script: None, reference_script: None,
} }
@ -59,7 +59,7 @@ test test_simple_oneshot() {
let tx = let tx =
Transaction { Transaction {
..transaction.placeholder(), ..transaction.placeholder,
mint: mint, mint: mint,
extra_signatories: [other_hash], extra_signatories: [other_hash],
inputs: [input], inputs: [input],

View File

@ -1,4 +1,4 @@
use aiken/list.{count as my_count} as native_list use aiken/collection/list.{count as my_count} as native_list
test thing_1() { test thing_1() {
let x = let x =

View File

@ -13,4 +13,4 @@ requirements = []
source = "github" source = "github"
[etags] [etags]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1725021962, nanos_since_epoch = 944823000 }, "cdbbce58b61deb385e7ea787a2e0fc2dc8fe94db9999e0e6275bc9c70e5796be"] "aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1725207295, nanos_since_epoch = 895782000 }, "d79382d2b6ecb3aee9b0755c31d8a5bbafe88a7b3706d7fb8a52fd4d05818501"]

View File

@ -6,7 +6,7 @@
"plutusVersion": "v3", "plutusVersion": "v3",
"compiler": { "compiler": {
"name": "Aiken", "name": "Aiken",
"version": "v1.1.0+9407b67" "version": "v1.1.0+ddfe01e"
}, },
"license": "Apache-2.0" "license": "Apache-2.0"
}, },

View File

@ -1,10 +1,10 @@
use aiken/builtin use aiken/builtin
use aiken/collection/dict use aiken/collection/dict
use aiken/collection/list use aiken/collection/list
use aiken/hash.{blake2b_256} use aiken/crypto.{blake2b_256}
use aiken/primitive/bytearray use aiken/primitive/bytearray
use cardano/address.{Address, PaymentCredential, Script}
use cardano/assets.{PolicyId} use cardano/assets.{PolicyId}
use cardano/credential.{Address, PaymentCredential, Script}
use cardano/transaction.{ use cardano/transaction.{
InlineDatum, Input, Output, OutputReference, Transaction, InlineDatum, Input, Output, OutputReference, Transaction,
} as tx } as tx

View File

@ -1,7 +1,7 @@
use aiken/collection/dict use aiken/collection/dict
use aiken/collection/list use aiken/collection/list
use cardano/address.{Script}
use cardano/assets.{PolicyId} use cardano/assets.{PolicyId}
use cardano/credential.{Script}
use cardano/transaction.{OutputReference, Transaction} as tx use cardano/transaction.{OutputReference, Transaction} as tx
pub type Action { pub type Action {

View File

@ -13,4 +13,4 @@ requirements = []
source = "github" source = "github"
[etags] [etags]
"aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1725021976, nanos_since_epoch = 403974000 }, "cdbbce58b61deb385e7ea787a2e0fc2dc8fe94db9999e0e6275bc9c70e5796be"] "aiken-lang/stdlib@v2" = [{ secs_since_epoch = 1725207187, nanos_since_epoch = 801664000 }, "d79382d2b6ecb3aee9b0755c31d8a5bbafe88a7b3706d7fb8a52fd4d05818501"]

View File

@ -1,5 +1,5 @@
use aiken/collection/list use aiken/collection/list
use cardano/credential.{VerificationKeyHash} use aiken/crypto.{VerificationKeyHash}
use cardano/transaction.{OutputReference, Transaction} use cardano/transaction.{OutputReference, Transaction}
pub type Datum { pub type Datum {
@ -16,7 +16,7 @@ validator hello_world {
redeemer: Redeemer, redeemer: Redeemer,
_: OutputReference, _: OutputReference,
transaction: Transaction, transaction: Transaction,
) -> Bool { ) {
let must_say_hello = redeemer.msg == "Hello, World!" let must_say_hello = redeemer.msg == "Hello, World!"
expect Some(Datum { owner }) = datum expect Some(Datum { owner }) = datum