remove second hash cache, type as Bytes32

This commit is contained in:
protolambda 2020-07-24 01:53:14 +02:00
parent 230e5ce345
commit 951c552ecc
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 4 additions and 12 deletions

View File

@ -1,17 +1,9 @@
from hashlib import sha256 from hashlib import sha256
from typing import Dict, Union from remerkleable.byte_arrays import Bytes32
from typing import Union
ZERO_BYTES32 = b'\x00' * 32 ZERO_BYTES32 = b'\x00' * 32
def _hash(x: Union[bytes, bytearray, memoryview]) -> bytes: def hash(x: Union[bytes, bytearray, memoryview]) -> Bytes32:
return sha256(x).digest() return Bytes32(sha256(x).digest())
hash_cache: Dict[bytes, bytes] = {}
def hash(x: bytes) -> bytes:
if x in hash_cache:
return hash_cache[x]
return _hash(x)