Skip to content

Commit

Permalink
Add Aiken as smart contract language (#926)
Browse files Browse the repository at this point in the history
* draft

* save

* revert overview

* revert yarn.lock

* semantic markup for caution about production use

* added Aiken to list of Programming languages

Co-authored-by: Robert Phair <[email protected]>
Co-authored-by: Fill <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2023
1 parent 24966e4 commit 0a091d1
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
99 changes: 99 additions & 0 deletions docs/smart-contracts/aiken.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
id: aiken
title: Aiken
sidebar_label: Aiken
description: Aiken
image: ../img/aiken-logo.png
---

## Introduction

[Aiken](https://github.com/aiken-lang/aiken) is a new programming language and toolchain for developing smart contracts on the Cardano blockchain. It takes inspiration from many modern languages such as Gleam, Rust, and Elm which are known for friendly error messages and an overall excellent developer experience.

The language is exclusively used for creating the on-chain validator-scripts. You will need to write your off-chain code for generating transactions in another language such as Rust, Haskell, Javascript, Python etc.

:::caution

Aiken is a still a work in progress and is NOT recommended for use in production.

:::

## Getting started

A comprehensive guide for getting started with Aiken can be found on the [aiken-lang.org](https://aiken-lang.org) website. For more details about the project you might also want to visit the [Aiken git repository](https://github.com/aiken-lang/aiken).


### Example contract

This is a basic validator written in Aiken

```aiken
use aiken/hash.{Blake2b_224, Hash}
use aiken/list
use aiken/string
use aiken/transaction.{ScriptContext}
use aiken/transaction/credential.{VerificationKey}
pub type Datum {
owner: Hash<Blake2b_224, VerificationKey>,
}
pub type Redeemer {
msg: ByteArray,
}
pub fn spend(datum: Datum, redeemer: Redeemer, context: ScriptContext) -> Bool {
let must_say_hello = string.from_bytearray(redeemer.msg) == "Hello, World!"
let must_be_signed =
list.has(context.transaction.extra_signatories, datum.owner)
must_say_hello && must_be_signed
}
```

### Testing

Tests can be created directly in Aiken and execute them on-the-fly using the "aiken check" command.

Below is an example of how such tests can be defined:

```aiken
use aiken/interval.{Finite, Interval, IntervalBound, PositiveInfinity}
test must_start_after_succeed_when_lower_bound_is_after() {
let range: ValidityRange =
Interval {
lower_bound: IntervalBound { bound_type: Finite(2), is_inclusive: True },
upper_bound: IntervalBound { bound_type: PositiveInfinity, is_inclusive: False },
}
must_start_after(range, 1)
}
test must_start_after_suceed_when_lower_bound_is_equal() {
let range: ValidityRange =
Interval {
lower_bound: IntervalBound { bound_type: Finite(2), is_inclusive: True },
upper_bound: IntervalBound { bound_type: PositiveInfinity, is_inclusive: False },
}
must_start_after(range, 2)
}
test must_start_after_fail_when_lower_bound_is_after() {
let range: ValidityRange =
Interval {
lower_bound: IntervalBound { bound_type: Finite(2), is_inclusive: True },
upper_bound: IntervalBound { bound_type: PositiveInfinity, is_inclusive: False },
}
!must_start_after(range, 3)
}
```


## Links
- [Aiken User-Manual](https://aiken-lang.org/)
- [Aiken Github Repository](https://github.com/aiken-lang/aiken).

2 changes: 2 additions & 0 deletions docs/smart-contracts/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ In another world, you'd like to build programs, possibly even replace a major co

## Programming languages
- [Marlowe](marlowe) - a domain-specific language, it covers the world of financial contracts.
- [Aiken](aiken) - for on-chain validator scripts only: a language & toolchain favouring developer experience.
- [Plutus](plutus) - a platform to write full applications that interact with the Cardano blockchain.
- [eopsin](eopsin) - a programming language for generic Smart Contracts based on Python.

1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ module.exports = {
"smart-contracts/overview",
"smart-contracts/marlowe",
"smart-contracts/plutus",
"smart-contracts/aiken",
"smart-contracts/eopsin",
],
"Be Part of the Governance": [
Expand Down
26 changes: 26 additions & 0 deletions src/aiken.prism.lang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Prism.languages.aiken = {
'string': /".*"/,
'comment': /\/\/.*/,
'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?/i,
'boolean': /\btrue|false\b/,
'class-name': /\b[A-Z]\w*\b/,
'punctuation': /\./,
'function-definition': {
pattern: /\b(fn|test\s)[^(]*/,
alias: 'function',
lookbehind: true
},
'variable': {
pattern: /\b(let\s)[^=]*/,
lookbehind: true
},
'keyword': /\b(if|else|fn|let|when|is|use|pub|type|opaque|const|todo|assert|check|test)\b/,
'operator': [
/&&|\\|\|/,
/\+|\-|\/|\*|%/,
/<=|>=|==|!=|<|>/,
/\.\./,
/\|>/,
/->/
]
};
18 changes: 18 additions & 0 deletions src/theme/prism-include-languages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
import siteConfig from '@generated/docusaurus.config';
const prismIncludeLanguages = (PrismObject) => {
if (ExecutionEnvironment.canUseDOM) {
const {
themeConfig: {prism = {}},
} = siteConfig;
const {additionalLanguages = []} = prism;
window.Prism = PrismObject;
additionalLanguages.forEach((lang) =>
require(`prismjs/components/prism-${lang}`)
);
window.x = require('../aiken.prism.lang.js');
delete window.Prism;
}
};

export default prismIncludeLanguages;
Binary file added static/img/aiken-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0a091d1

Please sign in to comment.