Skip to content

Commit 68f07f0

Browse files
author
Atif Nazir
committed
python3 compatibility fixes, ecdsa update, version bump
1 parent 19ea84b commit 68f07f0

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
*~
12
*.pyc

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ For more information, see [Python API Docs](https://block.io/api/simple/python).
3434

3535
## Windows Users, Please Note:
3636

37-
You can install it like so on Windows: "pip install block-io==1.1.10"
37+
You can install it like so on Windows: "pip install block-io==1.1.11"
3838

3939
Now regarding the vcvarsall.bat error -- that error is due to the fact that pycrypto library is being compiled when you're trying to install the block-io library.
4040

block_io/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self, privkey, pubkey = None, compressed = True):
4242
self.public_key = BlockIo.Helper.compress_pubkey(self.private_key.get_verifying_key().to_string())
4343
else:
4444
# use the uncompressed public key
45-
self.public_key = unhexlify('04' + hexlify(self.private_key.get_verifying_key().to_string()))
45+
self.public_key = unhexlify('04' + hexlify(self.private_key.get_verifying_key().to_string()).decode("utf-8"))
4646

4747
def sign(self, data_to_sign):
4848
der_sig = self.private_key.sign_digest_deterministic(data_to_sign, sha256, util.sigencode_der_canonize)
@@ -72,8 +72,8 @@ def from_wif(privkey):
7272
raise Exception("Invalid Private Key provided. Must be in Wallet Import Format.")
7373

7474
# is this a compressed WIF or not?
75-
is_compressed = len(hexlify(extended_key_bytes)) == 68 and hexlify(extended_key_bytes)[-2:] == "01"
76-
75+
is_compressed = len(hexlify(extended_key_bytes)) == 68 and hexlify(extended_key_bytes)[-2:].decode("utf-8") == "01"
76+
7777
# Drop the network bytes
7878
extended_key_bytes = extended_key_bytes[1:]
7979

@@ -191,7 +191,7 @@ def sweep_meta(self, method, **kwargs):
191191
key = self.Key.from_wif(kwargs['private_key'])
192192

193193
del kwargs['private_key'] # remove the key, we're not going to pass it on
194-
kwargs['public_key'] = key.pubkey_hex()
194+
kwargs['public_key'] = key.pubkey_hex().decode("utf-8")
195195

196196
response = self.api_call(method, **kwargs)
197197

examples/basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from block_io import BlockIo
44
from decimal import *
5+
import os
56
import six # for python2 back-compatibility in printing messages using print as a function
67
import random
78
import sys
89

910
version = 2 # API version
1011

1112
# use a testnet api key here, say, dogecoin
12-
block_io = BlockIo('TESTNET API KEY', 'SECRET PIN', version)
13+
block_io = BlockIo(os.environ.get('BLOCK_IO_API_KEY'), os.environ.get('BLOCK_IO_PIN'), version)
1314
getcontext().prec = 8 # coins are 8 decimal places at most
1415

1516
# create a new address with a random label

examples/dtrust.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@
1010
import six # for python2 back-compatibility in printing messages using print as a function
1111
import random
1212
import sys
13+
import os
1314

1415
version = 2 # API version
1516

1617
# use a testnet api key here, say, dogecoin
17-
block_io = BlockIo('Your API Key', 'Your Secret PIN', version)
18+
block_io = BlockIo(os.environ.get('BLOCK_IO_API_KEY'), os.environ.get('BLOCK_IO_PIN'), version)
1819
getcontext().prec = 8 # coins are 8 decimal places at most
1920

2021
# create a new address with a random label
2122
address_label = 'dtrust'+str(int(random.random()*10000))
2223

2324
# create the key objects for each private key
24-
keys = [ BlockIo.Key.from_passphrase('alpha1alpha2alpha3alpha4'), BlockIo.Key.from_passphrase('alpha2alpha3alpha4alpha1'), BlockIo.Key.from_passphrase('alpha3alpha4alpha1alpha2'), BlockIo.Key.from_passphrase('alpha4alpha1alpha2alpha3') ]
25+
keys = [ BlockIo.Key.from_passphrase('alpha1alpha2alpha3alpha4'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha2alpha3alpha4alpha1'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha3alpha4alpha1alpha2'.encode('utf-8')), BlockIo.Key.from_passphrase('alpha4alpha1alpha2alpha3'.encode('utf-8')) ]
2526

2627
pubkeys = []
2728

2829
for key in keys:
29-
pubkeys.insert(len(pubkeys), key.pubkey_hex())
30+
pubkeys.insert(len(pubkeys), key.pubkey_hex().decode("utf-8"))
3031
six.print_(key.pubkey_hex())
3132

3233
# create a dTrust address that requires 4 out of 5 keys (4 of ours, 1 at Block.io).
3334
# Block.io automatically adds +1 to specified required signatures because of its own key
3435

35-
print "* Creating a new 4 of 5 MultiSig address for DOGETEST"
36+
six.print_("* Creating a new 4 of 5 MultiSig address for DOGETEST")
3637
six.print_(','.join(str(x) for x in pubkeys))
3738
response = block_io.get_new_dtrust_address(label=address_label,public_keys=','.join(str(x) for x in pubkeys),required_signatures=3)
3839

@@ -89,6 +90,8 @@
8990
# sign the withdrawal request, one signature at a time
9091

9192
for key in keys:
93+
94+
pub_hex = key.pubkey_hex().decode("utf-8")
9295

9396
for input in response['data']['inputs']:
9497

@@ -97,15 +100,15 @@
97100
# find the object to put our signature in
98101
for signer in input['signers']:
99102

100-
if signer['signer_public_key'] == key.pubkey_hex():
103+
if signer['signer_public_key'] == pub_hex:
101104
# found it, let's add the signature to this object
102-
signer['signed_data'] = key.sign_hex(data_to_sign)
105+
signer['signed_data'] = key.sign_hex(data_to_sign).decode("utf-8")
103106

104-
six.print_("* Data Signed By:", key.pubkey_hex())
107+
six.print_("* Data Signed By:", pub_hex)
105108

106109
# let's have Block.io record this signature we just created
107110
block_io.sign_transaction(signature_data=json.dumps(response['data']))
108-
six.print_(">> Signatures relayed to Block.io for Public Key=", key.pubkey_hex())
111+
six.print_(">> Signatures relayed to Block.io for Public Key=", pub_hex)
109112

110113
# finalize the transaction now that's it been signed by all our keys
111114
six.print_("* Finalizing transaction")

examples/sweep.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99

1010
from block_io import BlockIo
1111
import six
12+
import os
1213

1314
# must use private key of the address we're trying to sweep from
14-
private_key = 'PRIVATE KEY IN WALLET IMPORT FORMAT FORM' # this key never goes to Block.io, it stays here with you
15+
private_key = os.environ.get('PRIVATE_KEY') # this key never goes to Block.io, it stays here with you
1516

16-
from_address = 'SWEEP COINS FROM THIS ADDRESS' # the address to sweep from
17-
to_address = 'SWEEP COINS INTO THIS ADDRESS' # the address to send coins to
17+
from_address = os.environ.get('FROM_ADDRESS') # the address to sweep from
18+
to_address = os.environ.get('TO_ADDRESS') # the address to send coins to
1819

1920
api_version = 2 # must use API V2
20-
block_io = BlockIo('YOUR API KEY', 'PIN - NOT NEEDED HERE', api_version)
21+
block_io = BlockIo(os.environ.get('BLOCK_IO_API_KEY'), "", api_version)
2122

2223
try:
2324
response = block_io.sweep_from_address(from_address=from_address,private_key=private_key,to_address=to_address)
2425
six.print_("Sweep Complete. Transaction ID:", response['data']['txid'])
25-
except Exception, err:
26+
except (Exception) as err:
2627
six.print_(err)
27-
28+

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from setuptools import setup
22

33
setup(name='block-io',
4-
version='1.1.10',
4+
version='1.1.11',
55
description='The easiest way to integrate Bitcoin, Dogecoin and Litecoin in your applications. Sign up at Block.io for your API key.',
66
url='https://github.com/BlockIo/block_io-python',
77
author='Atif Nazir',
88
author_email='a@block.io',
99
license='MIT',
1010
packages=['block_io'],
11+
python_requires='>=2.7, <4',
1112
install_requires=[
1213
'requests>=2.20.0',
1314
'pycryptodome>=3.6.6,<4.0',
14-
'ecdsa==0.13',
15+
'ecdsa==0.13.3',
1516
'six>=1.8.0',
16-
'base58>=1.0.0'
17+
'base58==1.0.3'
1718
],
1819
zip_safe=False)
1920

0 commit comments

Comments
 (0)