1
0

updates for python3

This commit is contained in:
ThomasV
2017-03-15 12:13:20 +01:00
parent 65aeb0bd3c
commit ab15ff3a00
27 changed files with 50 additions and 51 deletions

View File

@@ -74,7 +74,7 @@ class BaseWizard(object):
def new(self):
name = os.path.basename(self.storage.path)
title = _("Create") + ' ' + name.decode('utf8')
title = _("Create") + ' ' + name
message = '\n'.join([
_("What kind of wallet do you want to create?")
])

View File

@@ -39,7 +39,7 @@ def serialize_header(res):
return s
def deserialize_header(s, height):
hex_to_int = lambda s: int('0x' + s[::-1].encode('hex'), 16)
hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16)
h = {}
h['version'] = hex_to_int(s[0:4])
h['prev_block_hash'] = hash_encode(s[4:36])
@@ -55,7 +55,7 @@ def hash_header(header):
return '0' * 64
if header.get('prev_block_hash') is None:
header['prev_block_hash'] = '00'*32
return hash_encode(Hash(serialize_header(header).decode('hex')))
return hash_encode(Hash(bfh(serialize_header(header))))
blockchains = {}
@@ -107,7 +107,7 @@ class Blockchain(util.PrintError):
return blockchains[self.parent_id]
def get_max_child(self):
children = filter(lambda y: y.parent_id==self.checkpoint, blockchains.values())
children = list(filter(lambda y: y.parent_id==self.checkpoint, blockchains.values()))
return max([x.checkpoint for x in children]) if children else None
def get_checkpoint(self):
@@ -141,7 +141,7 @@ class Blockchain(util.PrintError):
def update_size(self):
p = self.path()
self._size = os.path.getsize(p)/80 if os.path.exists(p) else 0
self._size = os.path.getsize(p)//80 if os.path.exists(p) else 0
def verify_header(self, header, prev_header, bits, target):
prev_hash = hash_header(prev_header)
@@ -230,7 +230,7 @@ class Blockchain(util.PrintError):
def save_header(self, header):
delta = header.get('block_height') - self.checkpoint
data = serialize_header(header).decode('hex')
data = bfh(serialize_header(header))
assert delta == self.size()
assert len(data) == 80
self.write(data, delta*80)
@@ -309,7 +309,7 @@ class Blockchain(util.PrintError):
prev_hash = hash_header(previous_header)
if prev_hash != header.get('prev_block_hash'):
return False
bits, target = self.get_target(height / 2016)
bits, target = self.get_target(height // 2016)
try:
self.verify_header(header, previous_header, bits, target)
except:

View File

@@ -232,7 +232,7 @@ class Commands:
elif txin.get('redeemScript'):
raise BaseException('Not implemented')
outputs = map(lambda x: (TYPE_ADDRESS, x['address'], int(x['value'])), outputs)
outputs = [(TYPE_ADDRESS, x['address'], int(x['value'])) for x in outputs]
tx = Transaction.from_io(inputs, outputs, locktime=locktime)
tx.sign(keypairs)
return tx.as_dict()

View File

@@ -170,7 +170,7 @@ class BitStamp(ExchangeBase):
class Bitvalor(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['total']['last'])}
@@ -253,7 +253,7 @@ class Coinsecure(ExchangeBase):
class Foxbit(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['exchanges']['FOX']['last'])}
@@ -297,7 +297,7 @@ class MercadoBitcoin(ExchangeBase):
class NegocieCoins(ExchangeBase):
def get_rates(self,ccy):
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
json = self.get_json('api.bitvalor.com', '/v1/ticker.json')
return {'BRL': Decimal(json['ticker_1h']['exchanges']['NEG']['last'])}
def history_ccys(self):

View File

@@ -544,7 +544,7 @@ class Hardware_KeyStore(KeyStore, Xpub):
def bip39_normalize_passphrase(passphrase):
return normalize('NFKD', unicode(passphrase or ''))
return normalize('NFKD', passphrase or '')
def bip39_to_seed(mnemonic, passphrase):
import pbkdf2, hashlib, hmac

View File

@@ -517,7 +517,7 @@ class Network(util.DaemonThread):
if self.server_is_lagging() and self.auto_connect:
# switch to one that has the correct header (not height)
header = self.blockchain().read_header(self.get_local_height())
filtered = map(lambda x:x[0], filter(lambda x: x[1].tip_header==header, self.interfaces.items()))
filtered = list(map(lambda x:x[0], filter(lambda x: x[1].tip_header==header, self.interfaces.items())))
if filtered:
choice = random.choice(filtered)
self.switch_to_interface(choice)
@@ -1047,7 +1047,7 @@ class Network(util.DaemonThread):
def get_blockchains(self):
out = {}
for k, b in self.blockchains.items():
r = filter(lambda i: i.blockchain==b, self.interfaces.values())
r = list(filter(lambda i: i.blockchain==b, self.interfaces.values()))
if r:
out[k] = r
return out

View File

@@ -225,7 +225,7 @@ class SimpleConfig(PrintError):
def reverse_dynfee(self, fee_per_kb):
import operator
l = self.fee_estimates.items() + [(1, self.dynfee(4))]
l = list(self.fee_estimates.items()) + [(1, self.dynfee(4))]
dist = map(lambda x: (x[0], abs(x[1] - fee_per_kb)), l)
min_target, min_value = min(dist, key=operator.itemgetter(1))
if fee_per_kb < self.fee_estimates.get(25)/2:

View File

@@ -39,7 +39,7 @@ from .i18n import _
from .util import NotEnoughFunds, PrintError, profiler
from .plugins import run_hook, plugin_loaders
from .keystore import bip44_derivation
import .bitcoin
from . import bitcoin
# seed_version is now used for the version of the wallet file

View File

@@ -286,7 +286,7 @@ def match_decoded(decoded, to_match):
def parse_sig(x_sig):
return map(lambda x: None if x == NO_SIGNATURE else x, x_sig)
return [None if x == NO_SIGNATURE else x for x in x_sig]
def safe_parse_pubkey(x):
try:
@@ -488,7 +488,7 @@ def multisig_script(public_keys, m):
assert m <= n
op_m = format(opcodes.OP_1 + m - 1, 'x')
op_n = format(opcodes.OP_1 + n - 1, 'x')
keylist = [op_push(len(k)/2) + k for k in public_keys]
keylist = [op_push(len(k)//2) + k for k in public_keys]
return op_m + ''.join(keylist) + op_n + 'ae'

View File

@@ -65,7 +65,7 @@ class UserCancelled(Exception):
class MyEncoder(json.JSONEncoder):
def default(self, obj):
from transaction import Transaction
from .transaction import Transaction
if isinstance(obj, Transaction):
return obj.as_dict()
return super(MyEncoder, self).default(obj)
@@ -497,7 +497,7 @@ testnet_block_explorers = {
}
def block_explorer_info():
import bitcoin
from . import bitcoin
return testnet_block_explorers if bitcoin.TESTNET else mainnet_block_explorers
def block_explorer(config):

View File

@@ -60,6 +60,8 @@ from .mnemonic import Mnemonic
from . import paymentrequest
from .paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
from .paymentrequest import InvoiceStore
from .contacts import Contacts
from .storage import WalletStorage