Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Python3 grammar. #50

Open
wants to merge 1 commit 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
5 changes: 2 additions & 3 deletions pybitcoin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
:license: MIT, see LICENSE for more details.
"""

import services
from .services import *

import transactions
from . import transactions
from .transactions import *

import passphrases
from . import passphrases
from .passphrases import create_passphrase
from .passphrases.legacy import (
random_160bit_passphrase, random_256bit_passphrase
Expand Down
28 changes: 14 additions & 14 deletions pybitcoin/rpc/namecoind_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from .config import NAMECOIND_USE_HTTPS, VALUE_MAX_LIMIT

import ssl
import httplib
import http.client as httplib

create_ssl_authproxy = False
create_ssl_authproxy = False
do_wrap_socket = False

if hasattr( ssl, "_create_unverified_context" ):
#opt-out for verifying self-signed certificates (typically used in namecoin/bitcoind)
ssl._create_default_https_context = ssl._create_unverified_context
create_ssl_authproxy = True
create_ssl_authproxy = True

if not hasattr( ssl, "create_default_context" ):
create_ssl_authproxy = False
Expand All @@ -37,17 +37,17 @@ class NamecoindConnection( httplib.HTTPSConnection ):
"""

def __init__(self, host, port, timeout=None ):

httplib.HTTPSConnection.__init__(self, host, port )
self.timeout = timeout

def connect( self ):

sock = socket.create_connection((self.host, self.port), self.timeout)
if self._tunnel_host:
self.sock = sock
self._tunnel()

self.sock = ssl.wrap_socket( sock, cert_reqs=ssl.CERT_NONE )


Expand All @@ -59,7 +59,7 @@ def __init__(self, server=NAMECOIND_SERVER, port=NAMECOIND_PORT,
passphrase=NAMECOIND_WALLET_PASSPHRASE):

global create_ssl_authproxy, do_wrap_socket

if use_https:
http_string = 'https://'
else:
Expand All @@ -69,19 +69,19 @@ def __init__(self, server=NAMECOIND_SERVER, port=NAMECOIND_PORT,

self.passphrase = passphrase
self.server = server

if do_wrap_socket:
# ssl._create_unverified_context and ssl.create_default_context are not supported.
# wrap the socket directly
# wrap the socket directly
connection = NamecoindConnection( server, int(port) )
self.obj = AuthServiceProxy(authproxy_config_uri, connection=connection)

elif create_ssl_authproxy:
# ssl has _create_unverified_context, so we're good to go
# ssl has _create_unverified_context, so we're good to go
self.obj = AuthServiceProxy(authproxy_config_uri)

else:
# have to set up an unverified context ourselves
# have to set up an unverified context ourselves
ssl_ctx = ssl.create_default_context()
ssl_ctx.check_hostname = False
ssl_ctx.verify_mode = ssl.CERT_NONE
Expand Down
13 changes: 6 additions & 7 deletions pybitcoin/rpc/namecoind_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:copyright: (c) 2015 by Halfmoon Labs
:license: MIT, see LICENSE for more details.
"""

from __future__ import print_function
import os
import sys
import json
Expand Down Expand Up @@ -146,7 +146,7 @@ def rebroadcast_tx(server, raw_tx):

namecoind = NamecoindClient(server)

print namecoind.sendrawtransaction(raw_tx)
print(namecoind.sendrawtransaction(raw_tx))


# -----------------------------------
Expand Down Expand Up @@ -186,7 +186,7 @@ def get_receiver_address(server):

if info['ismine'] is not True:
msg = "something went wrong"
print msg
print(msg)
reply['error'] = msg
else:
reply['address'] = address
Expand All @@ -205,7 +205,7 @@ def check_if_needs_reload(server, min_balance=MIN_BALANCE):
balance = float(info['balance'])

if balance < min_balance:
print "%s needs reloading" % server
print("%s needs reloading" % server)
return True


Expand All @@ -218,7 +218,7 @@ def send_payment(server, payments):

namecoind.unlock_wallet(NAMECOIND_WALLET_PASSPHRASE)
for payment in payments:
print namecoind.sendtoaddress(payment['address'], payment['amount'])
print(namecoind.sendtoaddress(payment['address'], payment['amount']))


# -----------------------------------
Expand All @@ -227,7 +227,7 @@ def reload_wallets(main_server, slave_servers=LOAD_SERVERS):
payments = []

for server in LOAD_SERVERS:
#print get_receiver_address(server)
#print(get_receiver_address(server))
if check_if_needs_reload(server):
reload_tx = {}
reload_tx['amount'] = RELOAD_AMOUNT
Expand All @@ -248,4 +248,3 @@ def reload_wallets(main_server, slave_servers=LOAD_SERVERS):
pass

check_servers(LOAD_SERVERS, clean=False)

16 changes: 8 additions & 8 deletions pybitcoin/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"""

from .blockchain_client import BlockchainClient
from blockcypher import BlockcypherClient
from blockchain_info import BlockchainInfoClient
from chain_com import ChainComClient
from bitcoind import BitcoindClient, create_bitcoind_service_proxy
from .blockcypher import BlockcypherClient
from .blockchain_info import BlockchainInfoClient
from .chain_com import ChainComClient
from .bitcoind import BitcoindClient, create_bitcoind_service_proxy

import blockcypher
import blockchain_info
import chain_com
import bitcoind
from . import blockcypher
from . import blockchain_info
from . import chain_com
from . import bitcoind
2 changes: 1 addition & 1 deletion pybitcoin/services/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:license: MIT, see LICENSE for more details.
"""

import httplib
import http.client as httplib

from bitcoinrpc.authproxy import AuthServiceProxy

Expand Down
6 changes: 3 additions & 3 deletions pybitcoin/services/blockchain_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def get_unspents(address, blockchain_client=BlockchainInfoClient()):
r = requests.get(url, auth=auth)
try:
unspents = r.json()["unspent_outputs"]
except ValueError, e:
except ValueError as e:
raise Exception('Invalid response from blockchain.info.')

return format_unspents(unspents)

def broadcast_transaction(hex_tx, blockchain_client=BlockchainInfoClient()):
Expand All @@ -60,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)

if 'submitted' in r.text.lower():
return {'success': True}
else:
Expand Down
6 changes: 3 additions & 3 deletions pybitcoin/services/chain_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def get_unspents(address, blockchain_client=ChainComClient()):

try:
unspents = r.json()
except ValueError, e:
except ValueError as e:
raise Exception('Received non-JSON response from chain.com.')

return format_unspents(unspents)

def broadcast_transaction(hex_tx, blockchain_client):
Expand All @@ -72,7 +72,7 @@ def broadcast_transaction(hex_tx, blockchain_client):

try:
data = r.json()
except ValueError, e:
except ValueError as e:
raise Exception('Received non-JSON from chain.com.')

if 'transaction_hash' in data:
Expand Down
2 changes: 1 addition & 1 deletion pybitcoin/transactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:license: MIT, see LICENSE for more details.
"""

import opcodes
from . import opcodes

from .network import broadcast_transaction, send_to_address, get_unspents, \
embed_data_in_blockchain, make_send_to_address_tx, make_op_return_tx, \
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'pybitcointools==1.1.15',
'python-bitcoinrpc>=0.1',
'keychain>=0.1.4',
'bitcoin>=1.1.39'
'bitcoin>=1.1.39',
'future',
],
classifiers=[
'Intended Audience :: Developers',
Expand Down
4 changes: 2 additions & 2 deletions unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def test_send_transaction_bitcoind(self):
def test_build_transaction(self):
signed_tx = make_send_to_address_tx(
recipient_address, 1000, private_key, client)
#print signed_tx
#print(signed_tx)
self.assertTrue(True)
"""

Expand Down Expand Up @@ -615,7 +615,7 @@ def test_hex_op_return_tx(self):
def test_short_hex_op_return_tx(self):
resp = embed_data('0'*2)
self.assertTrue(resp.get('success'))

def test_bin_op_return_tx(self):
resp = embed_data("Hello, Blockchain!")
self.assertTrue(resp.get('success'))
Expand Down