Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from OpShin/bump/0.12.3
Browse files Browse the repository at this point in the history
Bump/0.12.3
  • Loading branch information
nielstron authored Apr 15, 2023
2 parents 3d4e4fc + 9ad092c commit f96603f
Show file tree
Hide file tree
Showing 70 changed files with 9,917 additions and 4,626 deletions.
11 changes: 11 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
changelog:
categories:
- title: 🏕 Features
labels:
- '*'
exclude:
labels:
- dependencies
- title: 👒 Dependencies
labels:
- dependencies
8 changes: 8 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# If there isn't a release for this version, create a new one.
- uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
makeLatest: true
prerelease: true
skipIfReleaseExists: true
# Build and publish the package to pypi.
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ repos:
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.8
language_version: python3.10
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ script:
coverage run -a --source=hebi -m hebi compile_pluto examples/smart_contracts/assert_sum.py
- >
coverage run -a --source=hebi -m hebi build examples/smart_contracts/assert_sum.py
- >
for i in $(find examples -type f -name "*.py" -not \( -name "broken*" -o -name "extract*" \)); do
coverage run -a --source=hebi -m hebi compile "$i"
done
after_success:
- coverage report
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<h1 style="text-align: center;">hebi</h1></br>


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

</div>

Expand Down Expand Up @@ -85,8 +85,8 @@ A short non-complete introduction in starting to write smart contracts follows.
2. Make sure you understand python. hebi 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 `hebi eval` to get a feeling for how they work.
4. Make sure your contract is valid hebi code. Run `hebi 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/hebi/tree/master/examples) to understand common patterns. Check out the [`prelude`](https://opshin.github.io/hebi/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.
5. Dig into the [`examples`](https://github.com/OpShin/hebi/tree/main/examples) to understand common patterns. Check out the [`prelude`](https://hebi.opshin.dev/hebi/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/opshin-starter-kit) to find a sample setup for developing your own contract.


In summary, a smart contract in hebi is defined by the function `validator` in your contract file.
Expand All @@ -109,20 +109,20 @@ and how to build transactions with the contract.
```python3
from hebi.prelude import *

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


def validator(datum: CancelDatum, redeemer: None, context: ScriptContext) -> None:
def validator(datum: WithdrawDatum, redeemer: None, context: ScriptContext) -> None:
assert datum.pubkeyhash in context.tx_info.signatories, "Required signature missing"
```

All contracts written in hebi are 100% valid python.
Minting policies expect only a redeemer and script context as argument.
Check out the [Architecture guide](https://github.com/OpShin/hebi/blob/master/ARCHITECTURE.md#minting-policy---spending-validator-double-function)
Check out the [Architecture guide](https://github.com/OpShin/hebi/blob/main/ARCHITECTURE.md#minting-policy---spending-validator-double-function)
for details on how to write double functioning contracts.
The [`examples`](https://github.com/OpShin/hebi/blob/master/examples) folder contains more examples.
The [`examples`](https://github.com/OpShin/hebi/blob/main/examples) folder contains more examples.
Also check out the [opshin-pioneer-program](
https://github.com/OpShin/opshin-pioneer-program)
and [opshin-starter-kit](
Expand Down Expand Up @@ -217,4 +217,4 @@ The main sponsor of this project is [Inversion](https://inversion.dev/cardano/).
> At Inversion, we pride ourselves on our passion for life and our ability to create exceptional software solutions for our clients. Our team of experts, with over a century of cumulative experience, is dedicated to harnessing the power of the Cardano blockchain to bring innovative and scalable decentralized applications to life. We've successfully built applications for NFT management, staking and delegation, chain data monitoring, analytics, and web3 integrations, as well as countless non-blockchain systems. With a focus on security, transparency, and sustainability, our team is excited to contribute to the Cardano ecosystem, pushing the boundaries of decentralized technologies to improve lives worldwide. Trust Inversion to be your go-to partner for robust, effective, and forward-thinking solutions, whether blockchain based, traditional systems, or a mix of the two.
They have recently started a podcast, called "Africa On Chain", which you can check out here:
https://www.youtube.com/@africaonchain
https://www.youtube.com/@africaonchain
75 changes: 66 additions & 9 deletions docs/hebi/builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ <h1 class="title">Module <code>hebi.builder</code></h1>
import cbor2
import pycardano

from .util import datum_to_cbor


@dataclasses.dataclass
class ScriptArtifacts:
Expand All @@ -88,7 +90,12 @@ <h1 class="title">Module <code>hebi.builder</code></h1>
policy_id: str


def build(contract_file: str, *args: pycardano.PlutusData, force_three_params=False):
def build(
contract_file: str,
*args: pycardano.Datum,
force_three_params=False,
validator_function_name=&#34;validator&#34;,
):
&#34;&#34;&#34;
Expects a python module and returns the build artifacts from compiling it
&#34;&#34;&#34;
Expand All @@ -105,26 +112,30 @@ <h1 class="title">Module <code>hebi.builder</code></h1>
code = code.term
# UPLC lambdas may only take one argument at a time, so we evaluate by repeatedly applying
for d in args:
code = uplc.ast.Apply(code, uplc.ast.data_from_cbor(d.to_cbor(&#34;bytes&#34;)))
code = uplc.ast.Apply(code, uplc.ast.data_from_cbor(datum_to_cbor(d)))
code = uplc.ast.Program((1, 0, 0), code)
return _build(code)


def _build(contract: uplc.ast.Program):
# create cbor file for use with pycardano/lucid
cbor = flatten(contract)
cbor_hex = cbor.hex()
return pycardano.PlutusV2Script(cbor)


def generate_artifacts(contract: pycardano.PlutusV2Script):
cbor_hex = contract.hex()
# double wrap
cbor_wrapped = cbor2.dumps(cbor)
cbor_wrapped = cbor2.dumps(contract)
cbor_wrapped_hex = cbor_wrapped.hex()
# create plutus file
d = {
&#34;type&#34;: &#34;PlutusScriptV2&#34;,
&#34;description&#34;: f&#34;opshin {__version__} Smart Contract&#34;,
&#34;description&#34;: f&#34;hebi {__version__} Smart Contract&#34;,
&#34;cborHex&#34;: cbor_wrapped_hex,
}
plutus_json = json.dumps(d, indent=2)
script_hash = pycardano.plutus_script_hash(pycardano.PlutusV2Script(cbor))
script_hash = pycardano.plutus_script_hash(pycardano.PlutusV2Script(contract))
policy_id = script_hash.to_primitive().hex()
# generate policy ids
addr_mainnet = pycardano.Address(
Expand All @@ -151,15 +162,20 @@ <h1 class="title">Module <code>hebi.builder</code></h1>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="hebi.builder.build"><code class="name flex">
<span>def <span class="ident">build</span></span>(<span>contract_file: str, *args: pycardano.plutus.PlutusData, force_three_params=False)</span>
<span>def <span class="ident">build</span></span>(<span>contract_file: str, *args: Union[pycardano.plutus.PlutusData, dict, pycardano.serialization.IndefiniteList, int, bytes, pycardano.serialization.RawCBOR, pycardano.plutus.RawPlutusData], force_three_params=False, validator_function_name='validator')</span>
</code></dt>
<dd>
<div class="desc"><p>Expects a python module and returns the build artifacts from compiling it</p></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def build(contract_file: str, *args: pycardano.PlutusData, force_three_params=False):
<pre><code class="python">def build(
contract_file: str,
*args: pycardano.Datum,
force_three_params=False,
validator_function_name=&#34;validator&#34;,
):
&#34;&#34;&#34;
Expects a python module and returns the build artifacts from compiling it
&#34;&#34;&#34;
Expand All @@ -176,11 +192,51 @@ <h2 class="section-title" id="header-functions">Functions</h2>
code = code.term
# UPLC lambdas may only take one argument at a time, so we evaluate by repeatedly applying
for d in args:
code = uplc.ast.Apply(code, uplc.ast.data_from_cbor(d.to_cbor(&#34;bytes&#34;)))
code = uplc.ast.Apply(code, uplc.ast.data_from_cbor(datum_to_cbor(d)))
code = uplc.ast.Program((1, 0, 0), code)
return _build(code)</code></pre>
</details>
</dd>
<dt id="hebi.builder.generate_artifacts"><code class="name flex">
<span>def <span class="ident">generate_artifacts</span></span>(<span>contract: pycardano.plutus.PlutusV2Script)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def generate_artifacts(contract: pycardano.PlutusV2Script):
cbor_hex = contract.hex()
# double wrap
cbor_wrapped = cbor2.dumps(contract)
cbor_wrapped_hex = cbor_wrapped.hex()
# create plutus file
d = {
&#34;type&#34;: &#34;PlutusScriptV2&#34;,
&#34;description&#34;: f&#34;hebi {__version__} Smart Contract&#34;,
&#34;cborHex&#34;: cbor_wrapped_hex,
}
plutus_json = json.dumps(d, indent=2)
script_hash = pycardano.plutus_script_hash(pycardano.PlutusV2Script(contract))
policy_id = script_hash.to_primitive().hex()
# generate policy ids
addr_mainnet = pycardano.Address(
script_hash, network=pycardano.Network.MAINNET
).encode()
# generate addresses
addr_testnet = pycardano.Address(
script_hash, network=pycardano.Network.TESTNET
).encode()
return ScriptArtifacts(
cbor_hex,
plutus_json,
addr_mainnet,
addr_testnet,
policy_id,
)</code></pre>
</details>
</dd>
</dl>
</section>
<section>
Expand Down Expand Up @@ -297,6 +353,7 @@ <h1>Index</h1>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="hebi.builder.build" href="#hebi.builder.build">build</a></code></li>
<li><code><a title="hebi.builder.generate_artifacts" href="#hebi.builder.generate_artifacts">generate_artifacts</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
Expand Down
Loading

0 comments on commit f96603f

Please sign in to comment.