Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc 0.9.10 #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pybitcoin/privatekey.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ecdsa
from binascii import hexlify, unhexlify
from ecdsa.keys import SigningKey
from utilitybelt import is_int, dev_random_entropy, dev_urandom_entropy
from utilitybelt import is_int, dev_urandom_entropy
from bitcoin import compress, encode_privkey, get_privkey_format

from .errors import _errors
Expand All @@ -29,7 +29,7 @@ def random_secret_exponent(curve_order):
# than the curve order
while True:
# generate a random 256 bit hex string
random_hex = hexlify(dev_random_entropy(32))
random_hex = hexlify(dev_urandom_entropy(32))
random_int = int(random_hex, 16)
if random_int >= 1 and random_int < curve_order:
break
Expand Down
7 changes: 4 additions & 3 deletions pybitcoin/services/blockchain_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from .blockchain_client import BlockchainClient

class BlockchainInfoClient(BlockchainClient):
def __init__(self, api_key=None):
def __init__(self, api_key=None, timeout=30):
self.type = 'blockchain.info'
self.timeout = timeout
if api_key:
self.auth = (api_key, '')
else:
Expand Down Expand Up @@ -46,7 +47,7 @@ def get_unspents(address, blockchain_client=BlockchainInfoClient()):
if auth and len(auth) == 2 and isinstance(auth[0], str):
url = url + "&api_code=" + auth[0]

r = requests.get(url, auth=auth)
r = requests.get(url, auth=auth, timeout=blockchain_client.timeout)
try:
unspents = r.json()["unspent_outputs"]
except ValueError, e:
Expand All @@ -59,7 +60,7 @@ def broadcast_transaction(hex_tx, blockchain_client=BlockchainInfoClient()):
"""
url = BLOCKCHAIN_API_BASE_URL + '/pushtx'
payload = {'tx': hex_tx}
r = requests.post(url, data=payload, auth=blockchain_client.auth)
r = requests.post(url, data=payload, auth=blockchain_client.auth, timeout=blockchain_client.timeout)

if 'submitted' in r.text.lower():
return {'success': True}
Expand Down
10 changes: 6 additions & 4 deletions pybitcoin/services/blockcypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@


class BlockcypherClient(BlockchainClient):
def __init__(self, api_key=None):
def __init__(self, api_key=None, timeout=30):
self.type = 'blockcypher.com'
if api_key:
self.auth = (api_key, '')
else:
self.auth = None

self.timeout = timeout


def format_unspents(unspents):

Expand Down Expand Up @@ -52,9 +54,9 @@ def get_unspents(address, blockchain_client=BlockcypherClient()):
BLOCKCYPHER_BASE_URL, address)

if blockchain_client.auth:
r = requests.get(url + '&token=' + blockchain_client.auth[0])
r = requests.get(url + '&token=' + blockchain_client.auth[0], timeout=blockchain_client.timeout)
else:
r = requests.get(url)
r = requests.get(url, timeout=blockchain_client.timeout)

try:
unspents = r.json()
Expand All @@ -74,7 +76,7 @@ def broadcast_transaction(hex_tx, blockchain_client):

url = '%s/txs/push' % (BLOCKCYPHER_BASE_URL)
payload = json.dumps({'tx': hex_tx})
r = requests.post(url, data=payload)
r = requests.post(url, data=payload, timeout=blockchain_client.timeout)

try:
data = r.json()
Expand Down
9 changes: 5 additions & 4 deletions pybitcoin/services/chain_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
from .blockchain_client import BlockchainClient

class ChainComClient(BlockchainClient):
def __init__(self, api_key_id=None, api_key_secret=None):
def __init__(self, api_key_id=None, api_key_secret=None, timeout=30):
self.type = 'chain.com'
self.timeout = timeout
if api_key_id and api_key_secret:
self.auth = (api_key_id, api_key_secret)
else:
Expand Down Expand Up @@ -45,9 +46,9 @@ def get_unspents(address, blockchain_client=ChainComClient()):

auth = blockchain_client.auth
if auth:
r = requests.get(url, auth=auth)
r = requests.get(url, auth=auth, timeout=blockchain_client.timeout)
else:
r = requests.get(url + '?api-key-id=DEMO-4a5e1e4')
r = requests.get(url + '?api-key-id=DEMO-4a5e1e4', timeout=blockchain_client.timeout)

try:
unspents = r.json()
Expand All @@ -68,7 +69,7 @@ def broadcast_transaction(hex_tx, blockchain_client):

url = CHAIN_API_BASE_URL + '/bitcoin/transactions/send'
payload = json.dumps({ 'signed_hex': hex_tx })
r = requests.post(url, data=payload, auth=auth)
r = requests.post(url, data=payload, auth=auth, timeout=blockchain_client.timeout)

try:
data = r.json()
Expand Down