eopsin-lang


Nameeopsin-lang JSON
Version 0.9.12 PyPI version JSON
download
home_pagehttps://github.com/opshin/eopsin
SummaryA simple pythonic programming language for Smart Contracts on Cardano
upload_time2023-03-14 16:30:58
maintainer
docs_urlNone
authornielstron
requires_python>=3.8,<3.9
licenseMIT
keywords python language programming-language compiler validator smart-contracts cardano
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
<div align="center">

<img  src="https://raw.githubusercontent.com/OpShin/eopsin/c485feda7b5e7eb0d835f3ad39eed679b96aa05c/eopsin.png" width="240" />
<h1 style="text-align: center;">eopsin</h1></br>


<a href="https://app.travis-ci.com/OpShin/eopsin"><img alt="Build Status" src="https://app.travis-ci.com/OpShin/eopsin.svg?branch=master"/></a>
<a href="https://pypi.org/project/eopsin-lang/"><img alt="PyPI version" src="https://badge.fury.io/py/eopsin-lang.svg"/></a>
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/eopsin-lang.svg" />
<a href="https://pypi.org/project/eopsin-lang/"><img alt="PyPI - Status" src="https://img.shields.io/pypi/status/eopsin-lang.svg" /></a>
<a href="https://coveralls.io/github/OpShin/eopsin?branch=master"><img alt="Coverage Status" src="https://coveralls.io/repos/github/OpShin/eopsin/badge.svg?branch=master" /></a>

</div>

> You are building what you want. Why not also build **how** you want?

This is an implementation of smart contracts for Cardano which are written in a strict subset of valid Python.
The general philosophy of this project is to write a compiler that 
ensure the following:

If the program compiles then:

1. it is a valid Python program
2. the output running it with python is the same as running it on-chain.

### Why eopsin?
- 100% valid Python. Leverage the existing tool stack for Python, syntax highlighting, linting, debugging, unit-testing, [property-based testing](https://hypothesis.readthedocs.io/), [verification](https://github.com/marcoeilers/nagini)
- Intuitive. Just like Python.
- Flexible. Imperative, functional, the way you want it.
- Efficient & Secure. Static type inference ensures strict typing and optimized code


### Getting Started

#### Eopsin Pioneer Program

Check out the [eopsin-pioneer-program](
https://github.com/OpShin/eopsin-pioneer-program) for a host of educational example contracts, test cases and off-chain code.

#### Example repository

Check out the [eopsin-example](
https://github.com/OpShin/eopsin-example) repository for a quick start in setting up a development environment
and compiling some sample contracts yourself.


You can replace the contracts in your local copy of the repository with code from the
`examples` section here to start exploring different contracts.

#### Developer Community and Questions

This repository contains a discussions page.
Feel free to open up a new discussion with questions regarding development using eopsin and using certain features.
Others may be able to help you and will also benefit from the previously shared questions.

Check out the community [here](https://github.com/OpShin/eopsin/discussions)

You can also chat with other developers [in the welcoming discord
community](https://discord.gg/2ETSZnQQH9) of OpShin

#### Installation

Install Python 3.8. Then run

```bash
python3.8 -m pip install eopsin-lang
```

#### Writing a Smart Contract

A short non-complete introduction in starting to write smart contracts follows.

1. Make sure you understand EUTxOs, Addresses, Validators etc on Cardano. [There is a wonderful crashcourse by @KtorZ](https://aiken-lang.org/fundamentals/eutxo). The contract will work on these concepts
2. Make sure you understand python. Eopsin works like python and uses python. There are tons of tutorials for python, choose what suits you best.
3. Make sure your contract is valid python and the types check out. Write simple contracts first and run them using `eopsin eval` to get a feeling for how they work.
4. Make sure your contract is valid eopsin code. Run `eopsin compile` and look at the compiler erros for guidance along what works and doesn't work and why.
5. Dig into the [`examples`](https://github.com/OpShin/eopsin/tree/master/examples) to understand common patterns. Check out the [`prelude`](https://opshin.github.io/eopsin/prelude.html) for understanding how the Script Context is structured and how complex datums are defined.
6. Check out the [sample repository](https://github.com/OpShin/eopsin-example) to find a sample setup for developing your own contract.


In summary, a smart contract in eopsin is defined by the function `validator` in your contract file.
The function validates that a specific value can be spent, minted, burned, withdrawn etc, depending
on where it is invoked/used as a credential.
If the function fails (i.e. raises an error of any kind such as a `KeyError` or `AssertionError`)
the validation is denied, and the funds can not be spent, minted, burned etc.

> There is a subtle difference here in comparison to most other Smart Contract languages.
> In eopsin a validator may return anything (in particular also `False`) - as long as it does not fail, the execution is considered valid.
> This is more similar to how contracts in Solidity always pass, unless they run out of gas or hit an error.
> So make sure to `assert` what you want to ensure to hold for validation!

A simple contract called the "Gift Contract" verifies that only specific wallets can withdraw money.
They are authenticated by a signature.
If you don't understand what a pubkeyhash is and how this validates anything, check out [this gentle introduction into Cardanos EUTxO](https://aiken-lang.org/fundamentals/eutxo).
Also see the [tutorial by `pycardano`](https://pycardano.readthedocs.io/en/latest/guides/plutus.html) for explanations on what each of the parameters to the validator means
and how to build transactions with the contract.


```python3
from eopsin.prelude import *

@dataclass()
class CancelDatum(PlutusData):
    pubkeyhash: bytes


def validator(datum: CancelDatum, redeemer: None, context: ScriptContext) -> None:
    sig_present = False
    for s in context.tx_info.signatories:
        if datum.pubkeyhash == s:
            sig_present = True
    assert sig_present, "Required signature missing"
```

All contracts written in eopsin are 100% valid python.
Minting policies expect only a redeemer and script context as argument.
Check out the [Architecture guide](https://github.com/OpShin/eopsin/blob/master/ARCHITECTURE.md#minting-policy---spending-validator-double-function)
for details on how to write double functioning contracts.
The [`examples`](https://github.com/OpShin/eopsin/blob/master/examples) folder contains more examples.
Also check out the [eopsin-pioneer-program](
https://github.com/OpShin/eopsin-pioneer-program)
 and [eopsin-example](
https://github.com/OpShin/eopsin-example) repo.

### Compiling

Write your program in python. You may start with the content of `examples`.
Arguments to scripts are passed in as Plutus Data objects in JSON notation.

You can run any of the following commands
```bash
# Evaluate script in Python - this can be used to make sure there are no obvious errors
eopsin eval examples/smart_contracts/assert_sum.py "{\"int\": 4}" "{\"int\": 38}" "{\"constructor\": 0, \"fields\": []}"

# Compile script to 'uplc', the Cardano Smart Contract assembly
eopsin compile examples/smart_contracts/assert_sum.py
```

### Deploying

The deploy process generates all artifacts required for usage with common libraries like [pycardano](https://github.com/Python-Cardano/pycardano), [lucid](https://github.com/spacebudz/lucid) and the [cardano-cli](https://github.com/input-output-hk/cardano-node).

```bash
# Automatically generate all artifacts needed for using this contract
eopsin build examples/smart_contracts/assert_sum.py
```

See the [tutorial by `pycardano`](https://pycardano.readthedocs.io/en/latest/guides/plutus.html) for explanations how to build transactions with `eopsin` contracts.

### The small print

_Not every valid python program is a valid smart contract_.
Not all language features of python will or can be supported.
The reasons are mainly of practical nature (i.e. we can't infer types when functions like `eval` are allowed).
Specifically, only a pure subset of python is allowed.
Further, only immutable objects may be generated.

For your program to be accepted, make sure to only make use of language constructs supported by the compiler.
You will be notified of which constructs are not supported when trying to compile.

### Name

> Eopsin (Korean: 업신; Hanja: 業神) is the goddess of the storage and wealth in Korean mythology and shamanism. 
> [...] Eopsin was believed to be a pitch-black snake that had ears. [[1]](https://en.wikipedia.org/wiki/Eopsin)

Since this project tries to merge Python (a large serpent) and Pluto/Plutus (Greek wealth gods), the name appears fitting.

The name is pronounced _op-shin_.

## Contributing

### Architecture

This program consists of a few independent components:
1. An aggressive static type inferencer
2. Rewriting tools to simplify complex python expressions
3. A compiler from a subset of python into UPLC

### Debugging artefacts

For debugging purposes, you can also run

```bash
# Compile script to 'uplc', and evaluate the script in UPLC (for debugging purposes)
python3 -m eopsin eval_uplc examples/smart_contracts/assert_sum.py "{\"int\": 4}" "{\"int\": 38}" "{\"constructor\": 0, \"fields\": []}"

# Compile script to 'pluto', an intermediate language (for debugging purposes)
python3 -m eopsin compile_pluto examples/smart_contracts/assert_sum.py
```

### Sponsoring

You can sponsor the development of eopsin through GitHub or [Teiki](https://alpha.teiki.network/projects/opshin) or just by sending ADA. Drop me a message on social media and let me know what it is for.

- **[Teiki](https://alpha.teiki.network/projects/opshin)** Stake your ada to support OpShin at [Teiki](https://alpha.teiki.network/projects/opshin)
- **GitHub** Sponsor the developers of this project through the button "Sponsor" next to them
- **ADA** Donation in ADA can be submitted to `$opshin` or `addr1qyz3vgd5xxevjy2rvqevz9n7n7dney8n6hqggp23479fm6vwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjns74lhmr`.

### Supporters

<a href="https://github.com/inversion-dev"><img src="https://avatars.githubusercontent.com/u/127298233?s=200&v=4" width="50"></a>
<a href="https://github.com/MuesliSwapTeam/"><img  src="https://avatars.githubusercontent.com/u/91151317?v=4" width="50" /></a>
<a href="https://github.com/AadaFinance/"><img  src="https://avatars.githubusercontent.com/u/89693711?v=4" width="50" /></a>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/opshin/eopsin",
    "name": "eopsin-lang",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<3.9",
    "maintainer_email": "",
    "keywords": "python,language,programming-language,compiler,validator,smart-contracts,cardano",
    "author": "nielstron",
    "author_email": "n.muendler@web.de",
    "download_url": "https://files.pythonhosted.org/packages/f7/5f/7260b64f5c18916b6c69e90c7fdf70139d678e9e6bc8bac64f3538ea678b/eopsin_lang-0.9.12.tar.gz",
    "platform": null,
    "description": "\n<div align=\"center\">\n\n<img  src=\"https://raw.githubusercontent.com/OpShin/eopsin/c485feda7b5e7eb0d835f3ad39eed679b96aa05c/eopsin.png\" width=\"240\" />\n<h1 style=\"text-align: center;\">eopsin</h1></br>\n\n\n<a href=\"https://app.travis-ci.com/OpShin/eopsin\"><img alt=\"Build Status\" src=\"https://app.travis-ci.com/OpShin/eopsin.svg?branch=master\"/></a>\n<a href=\"https://pypi.org/project/eopsin-lang/\"><img alt=\"PyPI version\" src=\"https://badge.fury.io/py/eopsin-lang.svg\"/></a>\n<img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/eopsin-lang.svg\" />\n<a href=\"https://pypi.org/project/eopsin-lang/\"><img alt=\"PyPI - Status\" src=\"https://img.shields.io/pypi/status/eopsin-lang.svg\" /></a>\n<a href=\"https://coveralls.io/github/OpShin/eopsin?branch=master\"><img alt=\"Coverage Status\" src=\"https://coveralls.io/repos/github/OpShin/eopsin/badge.svg?branch=master\" /></a>\n\n</div>\n\n> You are building what you want. Why not also build **how** you want?\n\nThis is an implementation of smart contracts for Cardano which are written in a strict subset of valid Python.\nThe general philosophy of this project is to write a compiler that \nensure the following:\n\nIf the program compiles then:\n\n1. it is a valid Python program\n2. the output running it with python is the same as running it on-chain.\n\n### Why eopsin?\n- 100% valid Python. Leverage the existing tool stack for Python, syntax highlighting, linting, debugging, unit-testing, [property-based testing](https://hypothesis.readthedocs.io/), [verification](https://github.com/marcoeilers/nagini)\n- Intuitive. Just like Python.\n- Flexible. Imperative, functional, the way you want it.\n- Efficient & Secure. Static type inference ensures strict typing and optimized code\n\n\n### Getting Started\n\n#### Eopsin Pioneer Program\n\nCheck out the [eopsin-pioneer-program](\nhttps://github.com/OpShin/eopsin-pioneer-program) for a host of educational example contracts, test cases and off-chain code.\n\n#### Example repository\n\nCheck out the [eopsin-example](\nhttps://github.com/OpShin/eopsin-example) repository for a quick start in setting up a development environment\nand compiling some sample contracts yourself.\n\n\nYou can replace the contracts in your local copy of the repository with code from the\n`examples` section here to start exploring different contracts.\n\n#### Developer Community and Questions\n\nThis repository contains a discussions page.\nFeel free to open up a new discussion with questions regarding development using eopsin and using certain features.\nOthers may be able to help you and will also benefit from the previously shared questions.\n\nCheck out the community [here](https://github.com/OpShin/eopsin/discussions)\n\nYou can also chat with other developers [in the welcoming discord\ncommunity](https://discord.gg/2ETSZnQQH9) of OpShin\n\n#### Installation\n\nInstall Python 3.8. Then run\n\n```bash\npython3.8 -m pip install eopsin-lang\n```\n\n#### Writing a Smart Contract\n\nA short non-complete introduction in starting to write smart contracts follows.\n\n1. Make sure you understand EUTxOs, Addresses, Validators etc on Cardano. [There is a wonderful crashcourse by @KtorZ](https://aiken-lang.org/fundamentals/eutxo). The contract will work on these concepts\n2. Make sure you understand python. Eopsin works like python and uses python. There are tons of tutorials for python, choose what suits you best.\n3. Make sure your contract is valid python and the types check out. Write simple contracts first and run them using `eopsin eval` to get a feeling for how they work.\n4. Make sure your contract is valid eopsin code. Run `eopsin compile` and look at the compiler erros for guidance along what works and doesn't work and why.\n5. Dig into the [`examples`](https://github.com/OpShin/eopsin/tree/master/examples) to understand common patterns. Check out the [`prelude`](https://opshin.github.io/eopsin/prelude.html) for understanding how the Script Context is structured and how complex datums are defined.\n6. Check out the [sample repository](https://github.com/OpShin/eopsin-example) to find a sample setup for developing your own contract.\n\n\nIn summary, a smart contract in eopsin is defined by the function `validator` in your contract file.\nThe function validates that a specific value can be spent, minted, burned, withdrawn etc, depending\non where it is invoked/used as a credential.\nIf the function fails (i.e. raises an error of any kind such as a `KeyError` or `AssertionError`)\nthe validation is denied, and the funds can not be spent, minted, burned etc.\n\n> There is a subtle difference here in comparison to most other Smart Contract languages.\n> In eopsin a validator may return anything (in particular also `False`) - as long as it does not fail, the execution is considered valid.\n> This is more similar to how contracts in Solidity always pass, unless they run out of gas or hit an error.\n> So make sure to `assert` what you want to ensure to hold for validation!\n\nA simple contract called the \"Gift Contract\" verifies that only specific wallets can withdraw money.\nThey are authenticated by a signature.\nIf you don't understand what a pubkeyhash is and how this validates anything, check out [this gentle introduction into Cardanos EUTxO](https://aiken-lang.org/fundamentals/eutxo).\nAlso see the [tutorial by `pycardano`](https://pycardano.readthedocs.io/en/latest/guides/plutus.html) for explanations on what each of the parameters to the validator means\nand how to build transactions with the contract.\n\n\n```python3\nfrom eopsin.prelude import *\n\n@dataclass()\nclass CancelDatum(PlutusData):\n    pubkeyhash: bytes\n\n\ndef validator(datum: CancelDatum, redeemer: None, context: ScriptContext) -> None:\n    sig_present = False\n    for s in context.tx_info.signatories:\n        if datum.pubkeyhash == s:\n            sig_present = True\n    assert sig_present, \"Required signature missing\"\n```\n\nAll contracts written in eopsin are 100% valid python.\nMinting policies expect only a redeemer and script context as argument.\nCheck out the [Architecture guide](https://github.com/OpShin/eopsin/blob/master/ARCHITECTURE.md#minting-policy---spending-validator-double-function)\nfor details on how to write double functioning contracts.\nThe [`examples`](https://github.com/OpShin/eopsin/blob/master/examples) folder contains more examples.\nAlso check out the [eopsin-pioneer-program](\nhttps://github.com/OpShin/eopsin-pioneer-program)\n and [eopsin-example](\nhttps://github.com/OpShin/eopsin-example) repo.\n\n### Compiling\n\nWrite your program in python. You may start with the content of `examples`.\nArguments to scripts are passed in as Plutus Data objects in JSON notation.\n\nYou can run any of the following commands\n```bash\n# Evaluate script in Python - this can be used to make sure there are no obvious errors\neopsin eval examples/smart_contracts/assert_sum.py \"{\\\"int\\\": 4}\" \"{\\\"int\\\": 38}\" \"{\\\"constructor\\\": 0, \\\"fields\\\": []}\"\n\n# Compile script to 'uplc', the Cardano Smart Contract assembly\neopsin compile examples/smart_contracts/assert_sum.py\n```\n\n### Deploying\n\nThe deploy process generates all artifacts required for usage with common libraries like [pycardano](https://github.com/Python-Cardano/pycardano), [lucid](https://github.com/spacebudz/lucid) and the [cardano-cli](https://github.com/input-output-hk/cardano-node).\n\n```bash\n# Automatically generate all artifacts needed for using this contract\neopsin build examples/smart_contracts/assert_sum.py\n```\n\nSee the [tutorial by `pycardano`](https://pycardano.readthedocs.io/en/latest/guides/plutus.html) for explanations how to build transactions with `eopsin` contracts.\n\n### The small print\n\n_Not every valid python program is a valid smart contract_.\nNot all language features of python will or can be supported.\nThe reasons are mainly of practical nature (i.e. we can't infer types when functions like `eval` are allowed).\nSpecifically, only a pure subset of python is allowed.\nFurther, only immutable objects may be generated.\n\nFor your program to be accepted, make sure to only make use of language constructs supported by the compiler.\nYou will be notified of which constructs are not supported when trying to compile.\n\n### Name\n\n> Eopsin (Korean: \uc5c5\uc2e0; Hanja: \u696d\u795e) is the goddess of the storage and wealth in Korean mythology and shamanism. \n> [...] Eopsin was believed to be a pitch-black snake that had ears. [[1]](https://en.wikipedia.org/wiki/Eopsin)\n\nSince this project tries to merge Python (a large serpent) and Pluto/Plutus (Greek wealth gods), the name appears fitting.\n\nThe name is pronounced _op-shin_.\n\n## Contributing\n\n### Architecture\n\nThis program consists of a few independent components:\n1. An aggressive static type inferencer\n2. Rewriting tools to simplify complex python expressions\n3. A compiler from a subset of python into UPLC\n\n### Debugging artefacts\n\nFor debugging purposes, you can also run\n\n```bash\n# Compile script to 'uplc', and evaluate the script in UPLC (for debugging purposes)\npython3 -m eopsin eval_uplc examples/smart_contracts/assert_sum.py \"{\\\"int\\\": 4}\" \"{\\\"int\\\": 38}\" \"{\\\"constructor\\\": 0, \\\"fields\\\": []}\"\n\n# Compile script to 'pluto', an intermediate language (for debugging purposes)\npython3 -m eopsin compile_pluto examples/smart_contracts/assert_sum.py\n```\n\n### Sponsoring\n\nYou can sponsor the development of eopsin through GitHub or [Teiki](https://alpha.teiki.network/projects/opshin) or just by sending ADA. Drop me a message on social media and let me know what it is for.\n\n- **[Teiki](https://alpha.teiki.network/projects/opshin)** Stake your ada to support OpShin at [Teiki](https://alpha.teiki.network/projects/opshin)\n- **GitHub** Sponsor the developers of this project through the button \"Sponsor\" next to them\n- **ADA** Donation in ADA can be submitted to `$opshin` or `addr1qyz3vgd5xxevjy2rvqevz9n7n7dney8n6hqggp23479fm6vwpj9clsvsf85cd4xc59zjztr5zwpummwckmzr2myjwjns74lhmr`.\n\n### Supporters\n\n<a href=\"https://github.com/inversion-dev\"><img src=\"https://avatars.githubusercontent.com/u/127298233?s=200&v=4\" width=\"50\"></a>\n<a href=\"https://github.com/MuesliSwapTeam/\"><img  src=\"https://avatars.githubusercontent.com/u/91151317?v=4\" width=\"50\" /></a>\n<a href=\"https://github.com/AadaFinance/\"><img  src=\"https://avatars.githubusercontent.com/u/89693711?v=4\" width=\"50\" /></a>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple pythonic programming language for Smart Contracts on Cardano",
    "version": "0.9.12",
    "split_keywords": [
        "python",
        "language",
        "programming-language",
        "compiler",
        "validator",
        "smart-contracts",
        "cardano"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9610357e5cb99f0fd7327e503f632fe94e688332169698b8d4d2848fc2b0bb72",
                "md5": "6140e9357e5c38d58be4e73bd5b0eac5",
                "sha256": "047bf002fd35129459b9bc89a9a094b2ecae2c45cb862f1dafb35d521fa34a6c"
            },
            "downloads": -1,
            "filename": "eopsin_lang-0.9.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6140e9357e5c38d58be4e73bd5b0eac5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.9",
            "size": 57072,
            "upload_time": "2023-03-14T16:30:56",
            "upload_time_iso_8601": "2023-03-14T16:30:56.461023Z",
            "url": "https://files.pythonhosted.org/packages/96/10/357e5cb99f0fd7327e503f632fe94e688332169698b8d4d2848fc2b0bb72/eopsin_lang-0.9.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f75f7260b64f5c18916b6c69e90c7fdf70139d678e9e6bc8bac64f3538ea678b",
                "md5": "3e9467847df50a007cda39601861aad2",
                "sha256": "f219a7f18265f76316f06fa3766e6d7d5f49dc9f23efe09d41173a5c9027c599"
            },
            "downloads": -1,
            "filename": "eopsin_lang-0.9.12.tar.gz",
            "has_sig": false,
            "md5_digest": "3e9467847df50a007cda39601861aad2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.9",
            "size": 49627,
            "upload_time": "2023-03-14T16:30:58",
            "upload_time_iso_8601": "2023-03-14T16:30:58.271934Z",
            "url": "https://files.pythonhosted.org/packages/f7/5f/7260b64f5c18916b6c69e90c7fdf70139d678e9e6bc8bac64f3538ea678b/eopsin_lang-0.9.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-14 16:30:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "opshin",
    "github_project": "eopsin",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "eopsin-lang"
}
        
Elapsed time: 0.08767s