forked from LBRYCommunity/lbry-sdk
py3 support in resolve
This commit is contained in:
parent
59e4ac30c2
commit
159e84468c
6 changed files with 21 additions and 20 deletions
|
@ -70,12 +70,12 @@ class Account(BaseAccount):
|
||||||
failed += 1
|
failed += 1
|
||||||
log.info('Checked: {}, Converted: {}, Failed: {}'.format(total, succeded, failed))
|
log.info('Checked: {}, Converted: {}, Failed: {}'.format(total, succeded, failed))
|
||||||
|
|
||||||
def get_balance(self, include_claims=False):
|
def get_balance(self, confirmations=6, include_claims=False):
|
||||||
if include_claims:
|
if include_claims:
|
||||||
return super(Account, self).get_balance()
|
return super(Account, self).get_balance(confirmations)
|
||||||
else:
|
else:
|
||||||
return super(Account, self).get_balance(
|
return super(Account, self).get_balance(
|
||||||
is_claim=0, is_update=0, is_support=0
|
confirmations, is_claim=0, is_update=0, is_support=0
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_unspent_outputs(self, include_claims=False):
|
def get_unspent_outputs(self, include_claims=False):
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import six
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
from lbryschema.hashing import sha256
|
from lbryschema.hashing import sha256
|
||||||
|
@ -29,11 +30,11 @@ def get_hash_for_outpoint(txhash, nOut, nHeightOfLastTakeover):
|
||||||
# noinspection PyPep8
|
# noinspection PyPep8
|
||||||
def verify_proof(proof, rootHash, name):
|
def verify_proof(proof, rootHash, name):
|
||||||
previous_computed_hash = None
|
previous_computed_hash = None
|
||||||
reverse_computed_name = ''
|
reverse_computed_name = b''
|
||||||
verified_value = False
|
verified_value = False
|
||||||
for i, node in enumerate(proof['nodes'][::-1]):
|
for i, node in enumerate(proof['nodes'][::-1]):
|
||||||
found_child_in_chain = False
|
found_child_in_chain = False
|
||||||
to_hash = ''
|
to_hash = b''
|
||||||
previous_child_character = None
|
previous_child_character = None
|
||||||
for child in node['children']:
|
for child in node['children']:
|
||||||
if child['character'] < 0 or child['character'] > 255:
|
if child['character'] < 0 or child['character'] > 255:
|
||||||
|
@ -42,7 +43,7 @@ def verify_proof(proof, rootHash, name):
|
||||||
if previous_child_character >= child['character']:
|
if previous_child_character >= child['character']:
|
||||||
raise InvalidProofError("children not in increasing order")
|
raise InvalidProofError("children not in increasing order")
|
||||||
previous_child_character = child['character']
|
previous_child_character = child['character']
|
||||||
to_hash += chr(child['character'])
|
to_hash += six.int2byte(child['character'])
|
||||||
if 'nodeHash' in child:
|
if 'nodeHash' in child:
|
||||||
if len(child['nodeHash']) != 64:
|
if len(child['nodeHash']) != 64:
|
||||||
raise InvalidProofError("invalid child nodeHash")
|
raise InvalidProofError("invalid child nodeHash")
|
||||||
|
@ -53,7 +54,7 @@ def verify_proof(proof, rootHash, name):
|
||||||
if found_child_in_chain is True:
|
if found_child_in_chain is True:
|
||||||
raise InvalidProofError("already found the next child in the chain")
|
raise InvalidProofError("already found the next child in the chain")
|
||||||
found_child_in_chain = True
|
found_child_in_chain = True
|
||||||
reverse_computed_name += chr(child['character'])
|
reverse_computed_name += six.int2byte(child['character'])
|
||||||
to_hash += previous_computed_hash
|
to_hash += previous_computed_hash
|
||||||
|
|
||||||
if not found_child_in_chain:
|
if not found_child_in_chain:
|
||||||
|
@ -62,9 +63,9 @@ def verify_proof(proof, rootHash, name):
|
||||||
if i == 0 and 'txhash' in proof and 'nOut' in proof and 'last takeover height' in proof:
|
if i == 0 and 'txhash' in proof and 'nOut' in proof and 'last takeover height' in proof:
|
||||||
if len(proof['txhash']) != 64:
|
if len(proof['txhash']) != 64:
|
||||||
raise InvalidProofError("txhash was invalid: {}".format(proof['txhash']))
|
raise InvalidProofError("txhash was invalid: {}".format(proof['txhash']))
|
||||||
if not isinstance(proof['nOut'], (long, int)):
|
if not isinstance(proof['nOut'], six.integer_types):
|
||||||
raise InvalidProofError("nOut was invalid: {}".format(proof['nOut']))
|
raise InvalidProofError("nOut was invalid: {}".format(proof['nOut']))
|
||||||
if not isinstance(proof['last takeover height'], (long, int)):
|
if not isinstance(proof['last takeover height'], six.integer_types):
|
||||||
raise InvalidProofError(
|
raise InvalidProofError(
|
||||||
'last takeover height was invalid: {}'.format(proof['last takeover height']))
|
'last takeover height was invalid: {}'.format(proof['last takeover height']))
|
||||||
to_hash += get_hash_for_outpoint(
|
to_hash += get_hash_for_outpoint(
|
||||||
|
@ -93,6 +94,6 @@ def verify_proof(proof, rootHash, name):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Hash(x):
|
def Hash(x):
|
||||||
if type(x) is unicode:
|
if isinstance(x, six.text_type):
|
||||||
x = x.encode('utf-8')
|
x = x.encode('utf-8')
|
||||||
return sha256(sha256(x))
|
return sha256(sha256(x))
|
||||||
|
|
|
@ -8,15 +8,15 @@ class WalletDatabase(BaseDatabase):
|
||||||
|
|
||||||
CREATE_TXO_TABLE = """
|
CREATE_TXO_TABLE = """
|
||||||
create table if not exists txo (
|
create table if not exists txo (
|
||||||
txoid integer primary key,
|
txid text references tx,
|
||||||
txhash blob references tx,
|
txoid text primary key,
|
||||||
address blob references pubkey_address,
|
address text references pubkey_address,
|
||||||
position integer not null,
|
position integer not null,
|
||||||
amount integer not null,
|
amount integer not null,
|
||||||
script blob not null,
|
script blob not null,
|
||||||
is_reserved boolean not null default 0,
|
is_reserved boolean not null default 0,
|
||||||
|
|
||||||
claim_id blob,
|
claim_id text,
|
||||||
claim_name text,
|
claim_name text,
|
||||||
is_claim boolean not null default 0,
|
is_claim boolean not null default 0,
|
||||||
is_update boolean not null default 0,
|
is_update boolean not null default 0,
|
||||||
|
@ -41,9 +41,9 @@ class WalletDatabase(BaseDatabase):
|
||||||
if txo.script.is_claim_involved:
|
if txo.script.is_claim_involved:
|
||||||
row['claim_name'] = txo.script.values['claim_name']
|
row['claim_name'] = txo.script.values['claim_name']
|
||||||
if txo.script.is_update_claim or txo.script.is_support_claim:
|
if txo.script.is_update_claim or txo.script.is_support_claim:
|
||||||
row['claim_id'] = sqlite3.Binary(txo.script.values['claim_id'])
|
row['claim_id'] = txo.script.values['claim_id']
|
||||||
elif txo.script.is_claim_name:
|
elif txo.script.is_claim_name:
|
||||||
row['claim_id'] = sqlite3.Binary(tx.get_claim_id(txo.index))
|
row['claim_id'] = tx.get_claim_id(txo.position)
|
||||||
return row
|
return row
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -149,7 +149,7 @@ class MainNetLedger(BaseLedger):
|
||||||
parse_lbry_uri(uri)
|
parse_lbry_uri(uri)
|
||||||
except URIParseError as err:
|
except URIParseError as err:
|
||||||
defer.returnValue({'error': err.message})
|
defer.returnValue({'error': err.message})
|
||||||
resolutions = yield self.network.get_values_for_uris(self.headers.hash(), *uris)
|
resolutions = yield self.network.get_values_for_uris(self.headers.hash().decode(), *uris)
|
||||||
resolver = Resolver(self.headers.claim_trie_root, self.headers.height, self.transaction_class,
|
resolver = Resolver(self.headers.claim_trie_root, self.headers.height, self.transaction_class,
|
||||||
hash160_to_address=lambda x: self.hash160_to_address(x), network=self.network)
|
hash160_to_address=lambda x: self.hash160_to_address(x), network=self.network)
|
||||||
defer.returnValue((yield resolver._handle_resolutions(resolutions, uris, page, page_size)))
|
defer.returnValue((yield resolver._handle_resolutions(resolutions, uris, page, page_size)))
|
||||||
|
|
|
@ -194,7 +194,7 @@ class Resolver:
|
||||||
# a table of index counts for the sorted claim ids, including ignored claims
|
# a table of index counts for the sorted claim ids, including ignored claims
|
||||||
absolute_position_index = {}
|
absolute_position_index = {}
|
||||||
|
|
||||||
block_sorted_infos = sorted(channel_claim_infos.iteritems(), key=lambda x: int(x[1][1]))
|
block_sorted_infos = sorted(channel_claim_infos.items(), key=lambda x: int(x[1][1]))
|
||||||
per_block_infos = {}
|
per_block_infos = {}
|
||||||
for claim_id, (name, height) in block_sorted_infos:
|
for claim_id, (name, height) in block_sorted_infos:
|
||||||
claims = per_block_infos.get(height, [])
|
claims = per_block_infos.get(height, [])
|
||||||
|
|
|
@ -12,8 +12,8 @@ from lbryschema.claim import ClaimDict # pylint: disable=unused-import
|
||||||
from .script import InputScript, OutputScript
|
from .script import InputScript, OutputScript
|
||||||
|
|
||||||
|
|
||||||
def claim_id_hash(txid, n):
|
def claim_id_hash(tx_hash, n):
|
||||||
return hash160(txid + struct.pack('>I', n))
|
return hash160(tx_hash + struct.pack('>I', n))
|
||||||
|
|
||||||
|
|
||||||
class Input(BaseInput):
|
class Input(BaseInput):
|
||||||
|
|
Loading…
Add table
Reference in a new issue