chainside / btcpy

A Python3 SegWit-compliant library which provides tools to handle Bitcoin data structures in a simple fashion.
https://www.chainside.net
GNU Lesser General Public License v3.0
271 stars 74 forks source link

Maybe the default version of segwit addresses should be zero #35

Closed bilthon closed 6 years ago

bilthon commented 6 years ago

If I do:

>>> pubKey = PublicKey.unhexlify('034486893a383d2b5d6c1c2ea72b918f5ce3b14b1737ecd987faffa1a4f954a797')
>>> str(pubKey.to_segwit_address())

This gives me:

'bc1pna5zac9rgecdktqfs920me8x6ys7ad5fsdw3dh'

Which is not the address I'm looking for. If I however explicitly specify the segwit program version:

>>> str(pubKey.to_segwit_address(0))

I finally get:

'bc1qna5zac9rgecdktqfs920me8x6ys7ad5fmne6qu'

It would be easy to submit a PR with this change, but I'm new to this library and don't know if this would break things or go somewhat against the desired behavior. I'm just saying that, as a user, at this point I expect the version to be zero by default.

SimoneBronzini commented 6 years ago

Hello, thanks for reporting this! Which version of btcpy are you using? In the current version pubKey.to_segwit_address() without parameters would not work, as it is declared as

def to_segwit_address(self, version, mainnet=None):