Skip to content

ci test #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: pythonbindings
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# This file is autogenerated by maturin v1.7.8
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- "*"
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-22.04
target: x86
- runner: ubuntu-22.04
target: aarch64
- runner: ubuntu-22.04
target: armv7
- runner: ubuntu-22.04
target: s390x
- runner: ubuntu-22.04
target: ppc64le
steps:
- uses: actions/checkout@v4
- run: cd bindings/ergo-lib-python
- run: pwd
- run: ls -la
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-22.04
target: x86
- runner: ubuntu-22.04
target: aarch64
- runner: ubuntu-22.04
target: armv7
steps:
- uses: actions/checkout@v4
- run: cd bindings/ergo-lib-python
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- run: cd bindings/ergo-lib-python
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-13
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- run: cd bindings/ergo-lib-python
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cd bindings/ergo-lib-python
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
# if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [linux, musllinux, windows, macos, sdist]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/download-artifact@v4
- run: ls -la
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: "wheels-*/*"
- name: Publish to PyPI
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
resolver = "2"
resolver = "2" #
members = [
"sigma-test-util",
"sigma-ser",
Expand Down Expand Up @@ -98,6 +98,7 @@ proptest-derive = "0.3"
pretty_assertions = "1.3"
wasm-bindgen-test = "0.3.37"
expect-test = "1.4.1"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "z"
Expand Down
2 changes: 1 addition & 1 deletion bindings/ergo-lib-c-core/src/box_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub unsafe fn ergo_box_candidate_builder_mint_token(
let builder_mut = mut_ptr_as_mut(builder_mut, "builder_mut")?;
let token = const_ptr_as_ref(token_ptr, "token_ptr")?;
builder_mut.0.mint_token(
token.0.clone(),
token.0,
token_name.into(),
token_desc.into(),
num_decimals,
Expand Down
2 changes: 1 addition & 1 deletion bindings/ergo-lib-c-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub unsafe fn token_get_amount(
/// JSON representation according to EIP-12 <https://github.com/ergoplatform/eips/pull/23>
pub unsafe fn token_to_json_eip12(token_ptr: ConstTokenPtr) -> Result<String, Error> {
let token = const_ptr_as_ref(token_ptr, "token_ptr")?;
let t_dapp: TokenJsonEip12 = token.0.clone().into();
let t_dapp: TokenJsonEip12 = token.0.into();
let s = serde_json::to_string(&t_dapp)?;
Ok(s)
}
6 changes: 5 additions & 1 deletion bindings/ergo-lib-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ name = "ergo_lib_python"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.23.1"
pyo3 = { version = "0.23.4", features = ["indexmap"] }
base16 = { workspace = true }
derive_more = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
ergo-lib = { workspace = true, features = ["mnemonic_gen"] }
sigma-ser = { workspace = true }
serde-pyobject = "0.5.0"
20 changes: 20 additions & 0 deletions bindings/ergo-lib-python/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
7 changes: 7 additions & 0 deletions bindings/ergo-lib-python/docs/_static/propertyfix.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
Fix for horizontal stacking weirdness in the RTD theme with Python properties:
https://github.com/readthedocs/sphinx_rtd_theme/issues/1301
*/
.py.property {
display: block !important;
}
37 changes: 37 additions & 0 deletions bindings/ergo-lib-python/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import ergo_lib_python
project = 'ergo-lib-python'
copyright = '2025, SethDusek (Kamal Ahmad)'
author = 'SethDusek (Kamal Ahmad)'
release = ergo_lib_python.__version__

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

# extensions = ['sphinx.ext.autodoc', 'autoapi.extension']
extensions = ['autoapi.extension', 'sphinx.ext.doctest']
doctest_global_setup = "from ergo_lib_python import *; from ergo_lib_python.chain import *; from ergo_lib_python.wallet import *; from ergo_lib_python.transaction import *"
autoapi_dirs = ['../ergo_lib_python']
autoapi_file_patterns = ['*.pyi']
autoapi_member_order = 'groupwise'
autoapi_python_class_content = 'both'
autoapi_add_toctree_entry = False
autodoc_typehints = 'both'
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_css_files = ["propertyfix.css"]
64 changes: 64 additions & 0 deletions bindings/ergo-lib-python/docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
=========
Examples
=========

Generate mnemonic and address from secret key
=============================================

.. testcode::

from ergo_lib_python.wallet import MnemonicGenerator, ExtSecretKey, DerivationPath
from ergo_lib_python.chain import NetworkPrefix
mnemonic = MnemonicGenerator("english", 128).generate()
# create Extended Secret Key and derive first secret key using default derivation path
ext_secret_key = ExtSecretKey.from_mnemonic(mnemonic, password="").derive(DerivationPath())
address = ext_secret_key.public_key().address()
address.to_str(NetworkPrefix.Mainnet) # 9eg...

Build transaction
===================
.. code-block:: python

from ergo_lib_python.chain import ErgoBoxCandidate
from ergo_lib_python.transaction import TxBuilder
from ergo_lib_python.wallet import select_boxes_simple
# Create a new output candidate with 1 billion nanoErgs (1 ERG)
output_candidate = ErgoBoxCandidate(
value=10 ** 9,
script = Address("9egnPnrYskFS8k1gYiKZEXZ2bhP9fvX9GZvsG1V3BzH3n8sBXrf"),
creation_height = 10000)
boxes = [] # List of boxes belonging to signer, left empty here
fee = 10**7 # Pay 0.01 ERG fee
# Select boxes whose value sums up to amount sent to recipient (1 ERG) and miner fee (0.01 ERG)
selection = select_boxes_simple(boxes, target_balance=output_candidate.value + fee, target_tokens=[])
tx = TxBuilder(box_selection=selection,
output_candidates=[output_candidate],
current_height=1000,
fee_amount=fee,
change_address=Address("....")).build() # UnsignedTransaction
Mint token
=============
.. code-block:: python

from ergo_lib_python.chain import Token, TokenId, ErgoBoxCandidate, TxBuilder
boxes = [] # list of boxes belonging to signer
fee = 10**7 # Pay 0.01 ERG fee
selection = select_boxes_simple(boxes, target_balance=10**9 + fee, [])
# The identifier of the token must be the ID of the first input in the transaction
mint_token = Token(TokenId(selection.boxes[0].box_id), amount=1)

mint_candidate = ErgoBoxCandidate(
value = 10**9,
script = Address("...."),
creation_height = 10000,
mint_token = mint_token,
mint_token_name = "NFT",
mint_token_desc = "desc",
mint_token_decimals = 0
)
tx = TxBuilder(
box_selection=selection,
output_candidates=[output_candidate],
current_height=1000,
fee_amount=fee,
change_address=Address("....")).build() # UnsignedTransaction
23 changes: 23 additions & 0 deletions bindings/ergo-lib-python/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. ergo-lib-python documentation master file, created by
sphinx-quickstart on Fri Jan 31 06:06:45 2025.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

=========================================
ergo-lib-python |release| documentation
=========================================

Python bindings to `sigma-rust <https://github.com/ergoplatform/sigma-rust>`_ crate. Includes functionality for building transactions, generating private keys, signing transactions and various chain types







.. toctree::
:caption: Table of Contents
:maxdepth: 2

/examples
API reference <autoapi/ergo_lib_python/index>
Loading
Loading