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):
|
class HDict(dict):
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return int.from_bytes(codecs.decode(self['id'], 'hex'), 'big')
|
return hash(codecs.decode(self['id'], 'hex'))
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=16384)
|
@lru_cache(maxsize=16384)
|
||||||
@ -17,9 +17,9 @@ def memoize_from_dict(func):
|
|||||||
|
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def memoized_func(*args, **kwargs):
|
def memoized_func(*args, **kwargs):
|
||||||
print(args)
|
args = list(args)
|
||||||
new_args = (args[0], HDict(args[1]), args[2])
|
args[1] = HDict(args[1])
|
||||||
print(new_args)
|
new_args = tuple(args)
|
||||||
return from_dict(func, *new_args, **kwargs)
|
return from_dict(func, *new_args, **kwargs)
|
||||||
|
|
||||||
return memoized_func
|
return memoized_func
|
||||||
|
|||||||
@ -77,10 +77,11 @@ class BigchainDB(object):
|
|||||||
raise ValidationError('Mode must be one of the following {}.'
|
raise ValidationError('Mode must be one of the following {}.'
|
||||||
.format(', '.join(self.mode_list)))
|
.format(', '.join(self.mode_list)))
|
||||||
|
|
||||||
|
tx_dict = transaction.tx_dict if transaction.tx_dict else transaction.to_dict()
|
||||||
payload = {
|
payload = {
|
||||||
'method': mode,
|
'method': mode,
|
||||||
'jsonrpc': '2.0',
|
'jsonrpc': '2.0',
|
||||||
'params': [encode_transaction(transaction.to_dict())],
|
'params': [encode_transaction(tx_dict)],
|
||||||
'id': str(uuid4())
|
'id': str(uuid4())
|
||||||
}
|
}
|
||||||
# TODO: handle connection errors!
|
# TODO: handle connection errors!
|
||||||
|
|||||||
@ -256,7 +256,8 @@ def b():
|
|||||||
def create_tx(alice, user_pk):
|
def create_tx(alice, user_pk):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
name = f'I am created by the create_tx fixture. My random identifier is {random.random()}.'
|
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
|
@pytest.fixture
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user