- replaced old lbryum function with struct.pack, per @BrannonKing review

- make copy of keys so we can modify the dictionary
This commit is contained in:
Lex Berezhny 2018-08-08 21:19:15 -04:00 committed by Jack Robison
parent 892758be65
commit a204f0d3e6
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
6 changed files with 28 additions and 34 deletions

View file

@ -23,7 +23,7 @@ jobs:
- pip install git+https://github.com/lbryio/torba.git - pip install git+https://github.com/lbryio/torba.git
- pip install git+https://github.com/lbryio/lbryschema.git - pip install git+https://github.com/lbryio/lbryschema.git
- pip install -e .[test] - pip install -e .[test]
script: HOME=/tmp coverage run --source=lbrynet -m twisted.trial tests.unit script: HOME=/tmp coverage run --source=lbrynet -m twisted.trial --reactor=asyncio tests.unit
after_success: after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)
- <<: *tests - <<: *tests

View file

@ -6,14 +6,11 @@ from requests.exceptions import ConnectionError
from docopt import docopt from docopt import docopt
from textwrap import dedent from textwrap import dedent
from twisted.internet.asyncioreactor import install
install(asyncio.get_event_loop())
from lbrynet.daemon.auth.client import LBRYAPIClient
from lbrynet.core.system_info import get_platform
from lbrynet.daemon.Daemon import Daemon from lbrynet.daemon.Daemon import Daemon
from lbrynet.daemon.DaemonControl import start as daemon_main from lbrynet.daemon.DaemonControl import start as daemon_main
from lbrynet.daemon.DaemonConsole import main as daemon_console from lbrynet.daemon.DaemonConsole import main as daemon_console
from lbrynet.daemon.auth.client import LBRYAPIClient
from lbrynet.core.system_info import get_platform
async def execute_command(method, params, conf_path=None): async def execute_command(method, params, conf_path=None):

View file

@ -5,6 +5,20 @@ import requests
import urllib import urllib
import json import json
import textwrap import textwrap
#import sys
#from twisted.internet import asyncioreactor
#if 'twisted.internet.reactor' not in sys.modules:
# asyncioreactor.install()
#else:
# from twisted.internet import reactor
# if not isinstance(reactor, asyncioreactor.AsyncioSelectorReactor):
# # pyinstaller hooks install the default reactor before
# # any of our code runs, see kivy for similar problem:
# # https://github.com/kivy/kivy/issues/4182
# del sys.modules['twisted.internet.reactor']
# asyncioreactor.install()
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from copy import deepcopy from copy import deepcopy
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation

View file

@ -46,7 +46,7 @@ class Account(BaseAccount):
'previous-corrupted': 0 'previous-corrupted': 0
} }
for maybe_claim_id in self.certificates.keys(): for maybe_claim_id in list(self.certificates):
results['total'] += 1 results['total'] += 1
if ':' not in maybe_claim_id: if ':' not in maybe_claim_id:
claims = yield self.ledger.network.get_claims_by_ids(maybe_claim_id) claims = yield self.ledger.network.get_claims_by_ids(maybe_claim_id)

View file

@ -1,31 +1,19 @@
import six import six
import struct
import binascii import binascii
from torba.hash import double_sha256
from lbryschema.hashing import sha256
class InvalidProofError(Exception): class InvalidProofError(Exception):
pass pass
def height_to_vch(n): def get_hash_for_outpoint(txhash, nout, height_of_last_takeover):
r = [0 for i in range(8)] return double_sha256(
r[4] = n >> 24 double_sha256(txhash) +
r[5] = n >> 16 double_sha256(str(nout).encode()) +
r[6] = n >> 8 double_sha256(struct.pack('>Q', height_of_last_takeover))
r[7] = n % 256 )
# need to reset each value mod 256 because for values like 67784
# 67784 >> 8 = 264, which is obviously larger then the maximum
# value input into chr()
return b''.join([six.int2byte(x % 256) for x in r])
def get_hash_for_outpoint(txhash, nOut, nHeightOfLastTakeover):
txhash_hash = Hash(txhash)
nOut_hash = Hash(str(nOut))
height_of_last_takeover_hash = Hash(height_to_vch(nHeightOfLastTakeover))
outPointHash = Hash(txhash_hash + nOut_hash + height_of_last_takeover_hash)
return outPointHash
# noinspection PyPep8 # noinspection PyPep8
@ -80,7 +68,7 @@ def verify_proof(proof, rootHash, name):
raise InvalidProofError("valueHash was invalid") raise InvalidProofError("valueHash was invalid")
to_hash += binascii.unhexlify(node['valueHash'])[::-1] to_hash += binascii.unhexlify(node['valueHash'])[::-1]
previous_computed_hash = Hash(to_hash) previous_computed_hash = double_sha256(to_hash)
if previous_computed_hash != binascii.unhexlify(rootHash)[::-1]: if previous_computed_hash != binascii.unhexlify(rootHash)[::-1]:
raise InvalidProofError("computed hash does not match roothash") raise InvalidProofError("computed hash does not match roothash")
@ -93,8 +81,3 @@ def verify_proof(proof, rootHash, name):
if not name.startswith(reverse_computed_name[::-1]): if not name.startswith(reverse_computed_name[::-1]):
raise InvalidProofError("name fragment does not match proof") raise InvalidProofError("name fragment does not match proof")
return True return True
def Hash(x):
if isinstance(x, six.text_type):
x = x.encode('utf-8')
return sha256(sha256(x))

View file

@ -3,8 +3,8 @@ import json
from io import StringIO from io import StringIO
from twisted.trial import unittest from twisted.trial import unittest
from lbrynet.core.system_info import get_platform
from lbrynet.cli import normalize_value, main from lbrynet.cli import normalize_value, main
from lbrynet.core.system_info import get_platform
class CLITest(unittest.TestCase): class CLITest(unittest.TestCase):