libblkmaker icon indicating copy to clipboard operation
libblkmaker copied to clipboard

Provide python bindings

Open vpereira opened this issue 9 years ago • 6 comments

Hi, since the python-blkmaker is outdated (and it looks unmaintained), wouldn't be a good idea to add python bindings to the libblkmaker?

vpereira avatar May 30 '16 08:05 vpereira

I've been pondering this for a week or so, actually, but I'm not sure if C code with Python bindings is sufficiently usable in Python code, or if python-blkmaker should be updated. Nor do I have any experience with writing Python bindings that get installed properly. (Is this something perhaps you could contribute?)

luke-jr avatar May 30 '16 15:05 luke-jr

I was looking into that right now... Normally You don't have to write python at all (http://intermediate-and-advanced-software-carpentry.readthedocs.io/en/latest/c++-wrapping.html) I wrote in the past some FFI classes and ctype interfaces to access C code from python code.. Let's see what I can do with Pyrex..

Or maybe I can help updating the python-blkmaker.. what do you prefer?

BTW, this python "miner" getblocktemplate implementation looks good and works even with testnet (all tested with bitcoind 0.12.1) https://github.com/vsergeev/ntgbtminer/blob/master/ntgbtminer.py

vpereira avatar May 30 '16 15:05 vpereira

IMO in an ideal world, there would be a pure-Python python-blkmaker and also libblkmaker Python bindings that are interchangeable, but that may take too much time to maintain.

The main advantage of python-blkmaker is that users/developers don't need to compile a C library. The main advantage of bindings would be a more common codebase.

Gentoo downstream tells me the preferred way to do bindings would be a separate repo for the bindings themselves, using distutils/setuptools for their install.

Updating python-blkmaker at this point would require porting:

  • a221293 Refactor construction of block submissions to allow for results from get_mdata
  • e3465d3 Refactor blkmk_assemble_submission2_ to work with either extranonce/mdata or dataid/data
  • 58aa6a3 Refactor to eliminate blkmk_assemble_submission_ wrapper
  • 7bf7e80 Bugfix: Expose blkmk_submitm_jansson for submitting results for blkmk_get_mdata
  • c94e438 Bugfix: Always avoid data/mdata size conflict in blkmk_append_coinbase_safe2 since nothing else checks merkle_only (nor has it available to check)

I've pushed a more recently updated python-blkmaker to https://github.com/luke-jr/python-blkmaker for now.

luke-jr avatar May 30 '16 15:05 luke-jr

There, finished updating python-blkmaker...

luke-jr avatar May 30 '16 17:05 luke-jr

great! One advantage to have the Python wrapper is to use it to unit test the whole lib. Unit test in python is way easier than in C.

vpereira avatar May 30 '16 20:05 vpereira

Yes, I'd still welcome Python bindings for that reason. :)

luke-jr avatar May 30 '16 21:05 luke-jr