mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Appropriate hash function not used.
Solution: use `hash()` function instead of `int.from_bytes()`
This commit is contained in:
parent
f7e07e13ec
commit
2bb98ab97f
@ -5,7 +5,7 @@ from functools import lru_cache
|
||||
|
||||
class HDict(dict):
|
||||
def __hash__(self):
|
||||
return int.from_bytes(codecs.decode(self['id'], 'hex'), 'big')
|
||||
return hash(codecs.decode(self['id'], 'hex'))
|
||||
|
||||
|
||||
@lru_cache(maxsize=16384)
|
||||
@ -17,9 +17,9 @@ def memoize_from_dict(func):
|
||||
|
||||
@functools.wraps(func)
|
||||
def memoized_func(*args, **kwargs):
|
||||
print(args)
|
||||
new_args = (args[0], HDict(args[1]), args[2])
|
||||
print(new_args)
|
||||
args = list(args)
|
||||
args[1] = HDict(args[1])
|
||||
new_args = tuple(args)
|
||||
return from_dict(func, *new_args, **kwargs)
|
||||
|
||||
return memoized_func
|
||||
|
||||
@ -77,10 +77,11 @@ class BigchainDB(object):
|
||||
raise ValidationError('Mode must be one of the following {}.'
|
||||
.format(', '.join(self.mode_list)))
|
||||
|
||||
tx_dict = transaction.tx_dict if transaction.tx_dict else transaction.to_dict()
|
||||
payload = {
|
||||
'method': mode,
|
||||
'jsonrpc': '2.0',
|
||||
'params': [encode_transaction(transaction.to_dict())],
|
||||
'params': [encode_transaction(tx_dict)],
|
||||
'id': str(uuid4())
|
||||
}
|
||||
# TODO: handle connection errors!
|
||||
|
||||
@ -256,7 +256,8 @@ def b():
|
||||
def create_tx(alice, user_pk):
|
||||
from bigchaindb.models import Transaction
|
||||
name = f'I am created by the create_tx fixture. My random identifier is {random.random()}.'
|
||||
return Transaction.create([alice.public_key], [([user_pk], 1)], asset={'name': name})
|
||||
return Transaction.create([alice.public_key], [([user_pk], 1)], asset={'name': name})\
|
||||
.sign([alice.private_key])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user