IOTA-Python — A Pure-Python implementation of IOTA node

Louie Lu
BiiLabs Co., Ltd.
Published in
3 min readNov 2, 2017
IOTA-Python — A Pure-Python implementation of IOTA node

This post is also available at: https://blog.louie.lu/2017/11/03/iota-python-pure-python-implementation-iota-node/

The target of IOTA-Python is to create a pure Python implementation of IOTA node, and to learn about how IRI works. Currently, it can read out the data from IRI rocksdb without IRI RESTful API. Why? It gave you the full access power of the IRI database!

GitHub: https://github.com/mlouielu/iota-python

0x1 Getting Started

– Dependencies

  • rocksdb

You can see the rocksdb installation guide from facebook/rocksdb — INSTALL.md.

For Arch Linux user, simply typing:

$ yaourt -S rocksdb

– Requirements

0x2 Installation of IOTA-Python

– $ pipenv install iotapy

To install IOTA-Python, simply run this simple command in your terminal of choice:

$ pipenv install iotapy

– Get the Source Code

IOTA-Python is actively developed on GitHub, where the code is always available.

You can clone the source code from repository:

$ git clone https://github.com/mlouielu/iota-python

Once you have a copy of source code, you can install the package easily:

$ cd iota-python
$ pip install -r requirements.txt
$ python setup.py install

0x3 Tutorial — About RocksDBProvider

This is a tutorial of IOTA-Python to read the database from java IRI, and this is what IOTA-Python can do now.

Open IRI rocksdb

Remember, make sure db_path and db_log_path is point to your database path. At this point, IOTA-Python didn’t support writing data back to the database (also, it have a lock on it, if you want to write it), so read_only should also be True.

>>> import iotapy
>>> r = iotapy.storage.providers.rocksdb.RocksDBProvider(
db_path='/var/db/iota/mainnetdb',
db_log_path='/var/db/iota/mainnetdb.log',
read_only=True)
>>> r.init() # Absolute remember to init database
>>>

Access IRI rocksdb

Now you open the database, you can get the data inside it! IRI using rocksdb column family to separate the data stored. For column family list, please visit this blog post

Now, we can try to open a transaction, here we got an example transaction hash:GTXDTJVUTVSNHYFPJUOWFKTGQTCMNKZPJDJXSWVQWTXYRDZAVZTX9KFBRIMRQEQLMCMVAUKMZWMHA9999.

You can check this tx information at this page:

If you are using method such as RocksDBProvider.get, RocksDBProvider.latest, please use the following column family name:

address
approvee
bundle
milestone
state_diff
tag
transaction
transaction_metadata

The full list of column family name can be found at RocksDBProvider.column_family_names, but this list is used for low level database access, it only used at RocksDBProvider.db.

b'default'
b'transaction'
b'transaction-metadata'
b'milestone'
b'stateDiff'
b'address'
b'approvee'
b'bundle'
b'tag'

Example of RocksDBProvider methods:

Low level db access (something you don’t need to touch at this moment):

0x4 EXPLOSION! An example of exploring the IRI database!

EXPLOSION!

Glade you are here, now you gain the full access power of the IRI database.

We all know that IOTA is a DAG, that is, theoretically speaking, we can start from a transaction, and go to its parent, and its parent, and its parent…and we will finally get to the genesis address / node / block whatever.

Here is a small script that I trying to find this answer:

It will run like:

NQRZKAE9CDFGJUPOMTHCVPOQE9LENTSHNJYDXCWZJ9IRXKLWTGRIHYZCZWSEIOKQFVBBEBNTXHNBA9999 Thu Oct 26 11:23:31 2017
KMRPH9BVZVFRCEGDEROQBMZTNOQECYRKIJJ9MWGNOUMWVPLFIJ9PRANLDXSTZCVJGHTXTYCWYGJFZ9999 Thu Oct 26 08:40:52 2017
JQLXELCKS9QSNWZNHJJICAQMGZRTGFPGNRRNJWTBEPZWKEHLJINXVLPOMMQCMQSOEUZGRHSKBNWEA9999 Thu Oct 26 06:40:31 2017
IOKLUAGDGKSU9RGHZXCQJIBRTFPCNVCIVG9TQNIGE9DVIYIUDCEVTMPYBZQXHNYLNSNFTXDWNH9BA9999 Thu Oct 26 05:41:28 2017
AUEDLXAJZPW9URCQZABSRNJGYOOSDG9OFHUMXINMVULHOIVWOBDLSSS9DPNTSXHTDKG9MGKMUESD99999 Thu Oct 26 04:38:37 2017
DZRYEISPEUXXVQMGBSPVMOFFTWPDYQ9EWVYZUQTNX9NPSEWRGNMSZMY9BOTABSLPCTKMIGWAAIPJA9999 Thu Oct 26 03:45:03 2017
UPAIBMKZEOTUEHHLEYZEEKZFLDGWHWJ9UZLGLRV9NGZPWSGWY9DPITWSDZPQQZDBOYFJDLJYTDKXZ9999 Thu Oct 26 02:51:53 2017
MZPRET9XVFBK9LQZLFNN9UGQLLBYAVGAKJGODQIKVZWHPDLZQLOTFMMGEAGSGWGPEYBLJLLJJXOEZ9999 Thu Oct 26 02:08:16 2017
XPMVSHVFNKYSTKPSHLPHDQCKEGWTERKEHTDRUKIQRE9KDDQVAQHUOQHYOPTRZGIIQHLYGYCPTLAEA9999 Thu Oct 26 01:17:58 2017
MHDQIXDMBOFHCOMLGNHPSJGNIXIDAQQNW9CJKSXPYIOIITQES99KNYTPNPOQBTVZQXYOKBVEIZB999999 Thu Oct 26 00:37:14 2017
...
GXWKBVNFPFX99PGDCH9EQZMLHITMBFAPDQRNNGNGOOXYXEEYYDDDFWJRDQINOEJFSITMEUY9VMVO99999 Tue Oct 24 06:37:13 2017
UAPTGGCKCGCPWGVQEKBCPKNQUWOPVRBAFAQYHSDU9AJMVINJFVZSM9URBYUAIHCPKOJRBWSOOSHLZ9999 Tue Oct 24 06:16:17 2017
FPPJWECLHTF9HGGEMNH9FUIAVYJWDOIOXYFRRJ9S9HENTSESTGJYLYOSNNJGKDOUOGXOWFURNDNEZ9999 Tue Oct 24 05:56:10 2017
HSDV9SKUYCBWNXFIHKLNAXEVPDTGLSPMTMTXCYISS9M9SPL9DERO9GCQLNWY9KBIHOLPYBCTCYECA9999 Tue Oct 24 05:35:44 2017
LQPVJDHGQPILXVUPCCZGJMCAQHROJLHQKBILEUDBKQAEHMHEOEK9GMRDWEKVRXRB99TOYQQLTZDGZ9999 Tue Oct 24 05:14:13 2017
FOCMONRMEOBQEBDOJOQPOOPLRIYCI9PMSJXXNEWAZPBRCDGZTZB9KI9SSMKKFBGBDONMILXWOBEFA9999 Tue Oct 24 04:53:03 2017
BEFSRMKVEWXXHERTONXCQLOAVQYVRPFFZCQIDGUOLLZCFLTRPRHEVYNAPQFKGJOCDAJYNVUJDQIRZ9999 Tue Oct 24 04:32:48 2017
QVHPAOWGDFTTLYQERDRNBBNCJJCWTJSDBIKBLDYZOLJ9PWFWFWUXP9DGPKTLRZDFZNLFRYXSZF9O99999 Tue Oct 24 04:12:07 2017

Probably the genesis?
9PPVIKDMKUDXTYJFF9YNWUPPMOYZTYKRBFGLGDCNNNIMWAMGVJGEHOCOUDYRVYPPSDKDKDQXUBMYA9999

Check this transaction on thetangle

0x5 Documentation

<del>Source code is your best friend</del>

Documentation is still under construct.

0x6 Additional

That’s all! Have a nice day!

If you like this post, you can tip here:

  • IOTA: CWLGNZADHTQHUZRYXKQMRYOSQKQDHDSINUZKIJ9KWIHVDUXUMZJLXMSEWTOFJFDVHZPAWHDQPZUHKVZACUSKQYMJSX
  • BTC: 3AsymiF89R3xguzrCUjS5rPUS1KeCXrfHF
  • ETH: 0x6FAA7CEdBeDaC6edf5E218D2f95B83B34499fc6F
  • LTC: MNBTs339PLXKdv2U2Z8dpvdLBMsqATkEyR
  • LTC(ddeprecated): 3FyKZ9dBSDftqQkZvg9J1HNvrfHP89PJFk
  • DASH: XehuTHVnBfF6dqRYQfA9SV9oYyFhrNxiyW
  • BCH: 12YGnthT4RSUW6a4WDivDp9rLogGkcpcCP

--

--