- 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/lbryschema.git
- 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:
- bash <(curl -s https://codecov.io/bash)
- <<: *tests

View file

@ -6,14 +6,11 @@ from requests.exceptions import ConnectionError
from docopt import docopt
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.DaemonControl import start as daemon_main
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):

View file

@ -5,6 +5,20 @@ import requests
import urllib
import json
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 copy import deepcopy
from decimal import Decimal, InvalidOperation

View file

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

View file

@ -1,31 +1,19 @@
import six
import struct
import binascii
from lbryschema.hashing import sha256
from torba.hash import double_sha256
class InvalidProofError(Exception):
pass
def height_to_vch(n):
r = [0 for i in range(8)]
r[4] = n >> 24
r[5] = n >> 16
r[6] = n >> 8
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
def get_hash_for_outpoint(txhash, nout, height_of_last_takeover):
return double_sha256(
double_sha256(txhash) +
double_sha256(str(nout).encode()) +
double_sha256(struct.pack('>Q', height_of_last_takeover))
)
# noinspection PyPep8
@ -80,7 +68,7 @@ def verify_proof(proof, rootHash, name):
raise InvalidProofError("valueHash was invalid")
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]:
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]):
raise InvalidProofError("name fragment does not match proof")
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 twisted.trial import unittest
from lbrynet.core.system_info import get_platform
from lbrynet.cli import normalize_value, main
from lbrynet.core.system_info import get_platform
class CLITest(unittest.TestCase):