Author

Topic: [ANN] pyspv 0.0.1-alpha - Python 3 Bitcoin SPV library (Read 1481 times)

newbie
Activity: 1
Merit: 0
Does the client still work? I receive the following error message.

Code:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 980, in cmd_version
    self.peer_last_block = struct.unpack("struct.error: unpack requires a buffer of 4 bytes

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 565, in run
    self.step()
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 602, in step
    self.handle_incoming_data()
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 673, in handle_incoming_data
    self.handle_command(command, payload)
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 705, in handle_command
    cmd(payload)
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 984, in cmd_version
    self.manager.peer_is_bad(self.peer_address)
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 336, in peer_is_bad
    self.delete_peer_address(peer_address)
  File "/usr/local/lib/python3.6/dist-packages/pyspv/network.py", line 225, in delete_peer_address
    self.peer_addresses[peer_address]['index'] = old['index']
KeyError: ('54.252.207.160', 18333)
member
Activity: 88
Merit: 10
That's very interesting... Will you keep it exclusive to Python 3? No 2.X port?
I'm asking, because most software out there is still Python 2.X only.

I'll try it out tomorrow. Smiley I have a 32-bit VM (Arch Linux server) which i can fool around with.

I personally won't be porting it to 2.x.  I really don't have an interest in maintaining that backwards compatability, tbh.  If someone wants to submit a patch (and possibly maintain a 2.x-focused branch), I'll likely merge it.
sr. member
Activity: 322
Merit: 250
That's very interesting... Will you keep it exclusive to Python 3? No 2.X port?
I'm asking, because most software out there is still Python 2.X only.

I'll try it out tomorrow. Smiley I have a 32-bit VM (Arch Linux server) which i can fool around with.
member
Activity: 88
Merit: 10
I can't do the same with the PrivateKey: passing both .secret_exponential() or .serialize() objects as PrivateKey secret doesn't return the expected values (a privkey' wif match). What the PrivateKey class is expecting as 'secret' ?  Huh

Code:
pyspv.keys.PrivateKey(secret_exp_as_long.to_bytes(32, "big"))

Right, the private key class takes an array of bytes (= the private key in big endian format).

Thanks for checking out pyspv, I haven't put much work into it since because its announcement went quite unnoticed Sad
legendary
Activity: 1022
Merit: 1000
I can't do the same with the PrivateKey: passing both .secret_exponential() or .serialize() objects as PrivateKey secret doesn't return the expected values (a privkey' wif match). What the PrivateKey class is expecting as 'secret' ?  Huh

Code:
pyspv.keys.PrivateKey(secret_exp_as_long.to_bytes(32, "big"))
hero member
Activity: 980
Merit: 1002
I've spent some time, trying to understand the library layout, but I suppose I'm missing something.

I run a working wallet instance (is embarrassingly easy, Sarchar did an amazing work) and wanted to add some keys into it, to do this as far I've understand, I need to instance some pyspv' keys objects, but since pyspv doesn't have BIP0032 support, I chosen to mantain my pycoin keychain.

While I've managed the PublicKey class:

from pycoin (where I already instantiated a BIP32Node to build a BIP0032 keychain)
Code:
>>> w.subwallets[1]['key'].sec()
b'\x02\xc1\x1b\x18<\xb2S\x8f\xb9\x142N\x1b\x9fY\xd5\x9a1\x1c\xd9@\xea\x9ag\rJU\xe7\x08\xb6\xf8\x07b'
>>> w.subwallets[1]['key'].bitcoin_address()
'1GkkbxV4wHsx45Ph3MQUtdCro3uQHoL2up'

to pyspv (where 'test' is an already running pyspv instance on mainnet)
Code:
>>> pk = keys.PublicKey(b'\x02\xc1\x1b\x18<\xb2S\x8f\xb9\x142N\x1b\x9fY\xd5\x9a1\x1c\xd9@\xea\x9ag\rJU\xe7\x08\xb6\xf8\x07b')
>>> pk.as_address(test.coin)
'1GkkbxV4wHsx45Ph3MQUtdCro3uQHoL2up'

..using the SEC repr of a pubkey.

I can't do the same with the PrivateKey: passing both .secret_exponential() or .serialize() objects as PrivateKey secret doesn't return the expected values (a privkey' wif match). What the PrivateKey class is expecting as 'secret' ?  Huh

https://github.com/sarchar/pyspv/blob/master/pyspv/keys.py#L188
sr. member
Activity: 412
Merit: 287
Clicked notify on this thread, will be watching with interest. Implementing the same in PHP, I'm hoping to leverage electrum servers on different coins since Stratum supports callbacks.. Very handy and light way to monitor for transactions, and you can query multiple servers too.
hero member
Activity: 980
Merit: 1002
I can't believe this implementation was released so silently. I admit I'm still understanding how it works: I relied only on the easy pycoin lib, till today, and I was looking for a pythonic way of broadcasting transactions without rely on a third-party API or a running bitcoind, when I've met pyspv.
As far as I've seen, it looks like the most complete python bitcoin library available ever... why this thread is not hot as hell?  Is pyspv discontinued for the sake of python-bitcoinlib fork by Jeff Garzik and, finally, Peter Todd, or the OP plan to mantain it as well?
sr. member
Activity: 333
Merit: 250
Commander of the Hodl Legions
Congrats, this looks awesome...

watching

PS: I hope this will include compatibility with 2.7 in the final version, loads of apps and webapps are still using 2.x
member
Activity: 88
Merit: 10
Reserved
member
Activity: 88
Merit: 10
pyspv - An extensible Python 3 Bitcoin SPV library

WARNING: This is ALPHA software. USE AT YOUR OWN RISK.

I've been working on this project for the past month and I finally feel that it's time to tell the community about it and ask for some constructive feedback.  I'm also more than happy to accept code contributions Smiley

The goal of this project is to create a library that can be used with Bitcoin (and eventually altcoins) that makes it easy for you to develop applications, both client and server, without doing any of the tedious Blockchain/Network/Transaction programming.  Integrating Bitcoin into your application is now literally a two line change to your code.

Features:
  • SPV implementation, so relatively lightweight
  • Written in Python, so useful for both server and user applications
  • Multisignature support, can create, send to and spend multisignature payments
  • Stealth address support, can create, send to and spend stealth address payments
  • Tor/SOCKS support
  • Testnet support
  • Extensible payment monitor and transaction building system
  • Completely modular, so you can initiate multiple SPV instances in the same application (This would allow for multiple alt-coin wallets)

The source comes with a sample RPC wallet called simple-wallet.py, you can launch it simply:

Code:
$ python3 examples/simple-wallet.py --testnet -v

The README describes the full set of RPC commands available, but here is a small demonstration:

Code:
$ python3 examples/simple-wallet.py getnewstealthaddress
7orJaJ2A3iRh6NAwbCZt8GoKHWUzoiPdwwvsZPpoFX7mreLRAQYXzP1
...
$ python3 examples/simple-wallet.py sendtoaddress 7orJaJ2A3iRh6NAwbCZt8GoKHWUzoiPdwwvsZPpoFX7mreLRAQYXzP1 1.0
(The stealth address implementation was based on sx, so they should be fully compatible)

Code:
$ python3 examples/simple-wallet.py genmultisig 1 2 0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71
{"address": "2MvM4RveSBwk3jwZV2Pe6avBFCYxUKgnDKi", "nreq": 1,
"redemption_script": "51210368b036cc3a4cc6187cb8d51ab25c71e9e98cd830df7f322174a8524f96d772b3210378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c7152ae",
"pubkeys": ["0368b036cc3a4cc6187cb8d51ab25c71e9e98cd830df7f322174a8524f96d772b3", "0378d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71"]}
...
$ python3 examples/simple-wallet.py sendtoaddress 2MvM4RveSBwk3jwZV2Pe6avBFCYxUKgnDKi 0.05
(simple-wallet will generate new keys if not enough are provided on the command-line)

So, anyways.  If you have time, try it out and let me know.  Also, let me know if you end up using it in a project, I'd love to link to it from here.

TODO

* Namecoin support (I actually have this mostly working, but I need to implement AuxPOW for the new blocks)
* Once Namecoin works, I should be able to finish my P2P alt-chain trading code and help automate trades (see https://en.bitcoin.it/wiki/Contracts#Example_5:_Trading_across_chains)
* BIP32 (HDW) and BIP38 (Encryption) support
* BIP70 (Payment protocol) support
* More altcoins? More payment monitors?
* CPU mining support (To aid in the creation of new alt-coins)
* Bug fixes

NOTE: Looks like there's a crash that happens between OpenSSL and Python when using 64-Bit Python build, so refrain from using 64-bit python for now.  I'm looking into it.

Jump to: