Skip to content

Commit

Permalink
Day 1 - Simple Spending Validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariady Putra committed May 19, 2024
1 parent 8533763 commit db964fa
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tests

on:
push:
branches: ["main"]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: aiken-lang/[email protected]
with:
version: v1.0.26-alpha

- run: aiken fmt --check
- run: aiken check -D
- run: aiken build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Aiken compilation artifacts
artifacts/
# Aiken's project working directory
build/
# Aiken's default documentation export
docs/
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
# hello_aiken
# hello_aiken

Write validators in the `validators` folder, and supporting functions in the `lib` folder using `.ak` as a file extension.

For example, as `validators/always_true.ak`

```gleam
validator {
fn spend(_datum: Data, _redeemer: Data, _context: Data) -> Bool {
True
}
}
```

## Building

```sh
aiken build
```

## Testing

You can write tests in any module using the `test` keyword. For example:

```gleam
test foo() {
1 + 1 == 2
}
```

To run all tests, simply do:

```sh
aiken check
```

To run only tests matching the string `foo`, do:

```sh
aiken check -m foo
```

## Documentation

If you're writing a library, you might want to generate an HTML documentation for it.

Use:

```sh
aiken docs
```

## Resources

Find more on the [Aiken's user manual](https://aiken-lang.org).
26 changes: 26 additions & 0 deletions aiken.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was generated by Aiken
# You typically do not need to edit this file

[[requirements]]
name = "aiken-lang/stdlib"
version = "1.8.0"
source = "github"

[[requirements]]
name = "aiken-extra/string_util"
version = "3.180.202403"
source = "github"

[[packages]]
name = "aiken-lang/stdlib"
version = "1.8.0"
requirements = []
source = "github"

[[packages]]
name = "aiken-extra/string_util"
version = "3.180.202403"
requirements = []
source = "github"

[etags]
19 changes: 19 additions & 0 deletions aiken.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "cdev-meetup/hello_aiken"
version = "0.0.0"
license = "Apache-2.0"
description = "Aiken contracts for project 'cdev-meetup/hello_aiken'"

[repository]
user = "cdev-meetup"
project = "hello_aiken"
platform = "github"

[[dependencies]]
name = "aiken-lang/stdlib"
version = "1.8.0"
source = "github"

[[dependencies]]
name = "aiken-extra/string_util"
version = "3.180.202403"
source = "github"
4 changes: 4 additions & 0 deletions lib/hello_aiken/alias.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use aiken/hash.{Hash, Blake2b_224}
use aiken/transaction/credential.{VerificationKey}

pub type PubKeyHash = Hash<Blake2b_224, VerificationKey>
49 changes: 49 additions & 0 deletions plutus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"preamble": {
"title": "cdev-meetup/hello_aiken",
"description": "Aiken contracts for project 'cdev-meetup/hello_aiken'",
"version": "0.0.0",
"plutusVersion": "v2",
"compiler": {
"name": "Aiken",
"version": "v1.0.26-alpha+unknown"
},
"license": "Apache-2.0"
},
"validators": [
{
"title": "hello.spend",
"datum": {
"title": "_datum",
"schema": {
"$ref": "#/definitions/Data"
}
},
"redeemer": {
"title": "_redeemer",
"schema": {
"$ref": "#/definitions/Data"
}
},
"parameters": [
{
"title": "user_pkh",
"schema": {
"$ref": "#/definitions/ByteArray"
}
}
],
"compiledCode": "588901000032323232323223222253330063233001001375860166018601860186018601860186018601860126ea8c02cc024dd50011129998058008a5013253330093371e6eb8c03400801c52889980180180098068008a4c2a6600e9211856616c696461746f722072657475726e65642066616c73650013656375c002ae695ce2ab9e5573eae855d101",
"hash": "dcc53c33a437ef11721e6564d69ba8011298ec41bfb5adafbc0ac9f9"
}
],
"definitions": {
"ByteArray": {
"dataType": "bytes"
},
"Data": {
"title": "Data",
"description": "Any Plutus data."
}
}
}
13 changes: 13 additions & 0 deletions validators/hello.ak
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use aiken/list.{has}
use aiken/transaction.{ScriptContext}
use hello_aiken/alias.{PubKeyHash}
use string_util/cbor.{print}

validator(pkh: PubKeyHash) {
fn spend(_datum: Data, _redeemer: Data, context ctx: ScriptContext) -> Bool {
let txn = ctx.transaction

trace print("extra_signatories", txn.extra_signatories)
txn.extra_signatories |> has(pkh)
}
}

0 comments on commit db964fa

Please sign in to comment.