Skip to main content

Ccurl PoW Interface for PyOTA

Project description

A python interface to load Ccurl library and perform proof of work locally, without relying on a node. To be used together with PyOTA, the Python Client Library for IOTA. For more info, read the docs.

Motivation

Currently, PyOTA doesn’t support performing proof of work locally. The attach_to_tangle API command sends the prepared transaction trytes to an IOTA node, that does the PoW by filling out attachment_timestamp* fields and calculating nonce with Curl P-81. In case of bundles, transactions are chained together through their transaction hash.

Installation

To use the module, follow the steps: - Clone the repo from GitHub:

$ git clone https://github.com/lzpap/ccurl.interface.py.git

  • Make sure you have cmake availabke on your system. This is a build dependecy for the ccurl library.

  • Build ccurl according to build instructions and put the .so library into the src folder, or run the init script in the main folder to build and initialize:

$ ./init.sh

  • Create a vitual environment / activate the one you use for PyOTA.

  • Install th python package from source by running:

$ pip install -e .

How to use?

Once installed, you can use the module to replace attach_to_tangle core api call in PyOTA. Just import the ccurl_interface module from the pow package and you are good to go.

An example code below illustrates how to do PoW for a bundle consisting of two transactions.

Code Example

import iota
from pprint import *
from pow import ccurl_interface

# Generate seed
myseed = iota.crypto.types.Seed.random()

#Generate two addresses
addres_generator = iota.crypto.addresses.AddressGenerator(myseed)
addys = addres_generator.get_addresses(1, count=2)

# preparing transactions
pt = iota.ProposedTransaction(address = iota.Address(addys[0]),
                              tag     = iota.Tag(b'LOCALATTACHINTERFACE99999'),
                              value   = 0)

pt2 = iota.ProposedTransaction(address = iota.Address(addys[1]),
                               tag     = iota.Tag(b'LOCALATTACHINTERFACE99999'),
                               value   = 0)

# preparing bundle that consists of both transactions prepared in the previous example
pb = iota.ProposedBundle(transactions=[pt2,pt])

# generate bundle hash
pb.finalize()

# declare a api instance
api = iota.Iota("https://nodes.thetangle.org:443") # selecting IOTA node

# get tips to be approved by your bundle
gta = api.get_transactions_to_approve(depth=3)

minimum_weight_magnitude = 14 # target is mainnet

# perform PoW locally
bundle_trytes =\
    ccurl_interface.attach_to_tangle(
        pb.as_tryte_strings(),
        gta['trunkTransaction'],
        gta['branchTransaction'],
        mwm
    )

# Broadcast transactions on the Tangle
broadcasted = api.broadcast_and_store(bundle_trytes)

bundle_broadcasted =iota.Bundle.from_tryte_strings(broadcasted['trytes'])

pprint('Local pow broadcasted transactions are:')
pprint(bundle_broadcasted.as_json_compatible())

Tests

Run nosetests to test in current environment. Run tox -v -p all to test in Python 2.7, 3.5, 3.6 and 3.8.

Contribute

Raise issues: https://github.com/lzpap/ccurl.interface.py/issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyOTA-PoW-1.0.1.tar.gz (37.6 kB view details)

Uploaded Source

Built Distribution

PyOTA_PoW-1.0.1-py3-none-any.whl (36.5 kB view details)

Uploaded Python 3

File details

Details for the file PyOTA-PoW-1.0.1.tar.gz.

File metadata

  • Download URL: PyOTA-PoW-1.0.1.tar.gz
  • Upload date:
  • Size: 37.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0

File hashes

Hashes for PyOTA-PoW-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5668e1b1d1986aef707ccc6c54f64086ff02736093887bb4ef761c89f681f68a
MD5 90011c71ed1b46c296c2e330598eba89
BLAKE2b-256 b71f65f6a9c22c312ff6e627efc1a42c659275addd22250d89220360928045a1

See more details on using hashes here.

File details

Details for the file PyOTA_PoW-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: PyOTA_PoW-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 36.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0

File hashes

Hashes for PyOTA_PoW-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32dcbf8543d6576f8917a9c8f778a9ed109188651a049a854d42446f759b7b97
MD5 c59661f8ebb169d20ceacea7efec7691
BLAKE2b-256 9c6c32275c7bab0c3d984815e7dfe2f34dd63d7987715aeab651655261390eed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page