1

For my application there is the requirement to run iota.rs for Shimmer and IOTA Chrysalis.

How is that possible?

Bonus question: how can I do that in a docker container?

Antonio Nardella
  • 1,074
  • 5
  • 17

1 Answers1

1

That is only possible by building iota.rs from source.

In bindings/python/native/Cargo.toml change both names:

[package]
- name = "iota-client-python"
+ name = "iota-client-production"
  version = "0.2.0-alpha.3"
  authors = ["IOTA Stiftung"]
  edition = "2021"
  description = "Python bindings for the IOTA client library"
  documentation = "https://wiki.iota.org/iota.rs/welcome"
  homepage = "https://www.iota.org/"
  repository = "https://github.com/iotaledger/iota.rs"
  license = "Apache-2.0"
  keywords = ["iota", "tangle", "client", "python"]
  categories = ["cryptography::cryptocurrencies"]

[lib]

  • name = "iota_client"
  • name = "iota_client_production" crate-type = ["cdylib"]

In bindings/python/native/setup.py:

setup(
-   name="iota_client",
+   name="iota_client_production"
    version="0.1.0",
    classifiers=[
        "License :: SPDX-License-Identifier ::  Apache-2.0",
        "Development Status :: 0.1.0 - Alpha",
        "Intended Audience :: Developers",
        "Programming Language :: Python",
        "Programming Language :: Rust",
        "Operating System :: POSIX",
        "Operating System :: MacOS :: MacOS X",
    ],
    packages=["iota_client"],
    rust_extensions=[
        RustExtension(
            "iota_client.iota_client",
            rustc_flags=get_py_version_cfgs(),
            debug=False,
        ),
    ],
    include_package_data=True,
    zip_safe=False,
)

And in bindings/python/native/src/lib.rs:

/// A Python module implemented in Rust.
#[pymodule]
- fn iota_client(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
+ fn iota_client_production(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
      m.add_class::<Client>()?;
      Ok(())
  }

Install and run maturin:

pip3 install maturin
maturin develop
maturin build --manylinux off

The wheel file is now created in bindings/python/native/target/wheels. You can install it with:

pip3 install [THE_BUILT_WHEEL_FILE]

Once it has been properly installed you can double check it using pip:

pip list

You should see the similar output:

Package                    Version
-------------------------- -------
iota-client-production           0.2.0a3

From here it is necessary import the Chrysalis library using iota_client_production

import iota_client_production # for IOTA Chrysalis
from iota_client import IotaClient as ShimmerClient # Imported as ShimmerClient to prevent confusion

Reference: The Shimmer wiki shows here how to do that.

Bonus answer: Here the dockerfile with the information to build a container with both versions of iota.rs for Python.

FROM python:3.10-slim-bullseye

WORKDIR /app

ADD . /app/

EXPOSE 8000

COPY requirements.txt /app

Install required system dependencies

RUN apt-get update && apt-get install --no-install-recommends -y
libudev-dev
git
curl
build-essential
libdbus-1-dev
libusb-dev
libhidapi-dev
libhidapi-hidraw0
libclang-dev
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
&& rm -rf /var/lib/apt/lists/*

Upgrade PIP

RUN pip install --upgrade pip

Install Rust to compile libs

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y &&
. $HOME/.cargo/env &&
git clone -b develop https://github.com/iotaledger/iota.rs &&
cd iota.rs/client/bindings/python &&
pip install -r requirements-dev.txt &&
pip install . &&
cd /app/iota.rs &&
git stash &&
git checkout production &&
cd bindings/python/native &&
sed -i 's/name="iota_client",/name="iota_client_production",/g' setup.py &&
sed -i 's/name = "iota-client-python"/name = "iota-client-production"/g' Cargo.toml &&
sed -i 's/keywords = ["iota", "tangle", "client", "python"]/keywords = ["iota", "tangle", "client", "python","chrysalis"]/g' Cargo.toml &&
sed -i 's/name = "iota_client"/name = "iota_client_production"/g' Cargo.toml &&
cd src &&
sed -i 's/fn iota_client/fn iota_client_production/g' lib.rs &&
cd .. &&
pip install maturin &&
maturin build --manylinux off &&
cd /app/iota.rs/bindings/python/native/target/wheels/ &&
pip install iota_client_production-0.2.0a3-cp36-abi3-linux_x86_64.whl &&
cd /app &&
rm -rf iota.rs

RUN pip install -r requirements.txt --no-cache-dir

COPY . /app

RUN ["chmod", "+x", "/app/commands.sh"]

ENTRYPOINT ["/app/commands.sh"]

Antonio Nardella
  • 1,074
  • 5
  • 17