mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-02-18 13:36:29 +00:00
Add ssz_{de,}serialize aliases
This commit is contained in:
parent
83c04b8469
commit
6416a562ab
@ -10,7 +10,7 @@ class ElectraSpecBuilder(BaseSpecBuilder):
|
|||||||
def imports(cls, preset_name: str):
|
def imports(cls, preset_name: str):
|
||||||
return f'''
|
return f'''
|
||||||
from eth2spec.deneb import {preset_name} as deneb
|
from eth2spec.deneb import {preset_name} as deneb
|
||||||
from eth2spec.utils.ssz.ssz_impl import serialize, deserialize
|
from eth2spec.utils.ssz.ssz_impl import ssz_serialize, ssz_deserialize
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1146,9 +1146,9 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]:
|
def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]:
|
||||||
deposit_bytes = serialize(execution_requests.deposits)
|
deposit_bytes = ssz_serialize(execution_requests.deposits)
|
||||||
withdrawal_bytes = serialize(execution_requests.withdrawals)
|
withdrawal_bytes = ssz_serialize(execution_requests.withdrawals)
|
||||||
consolidation_bytes = serialize(execution_requests.consolidations)
|
consolidation_bytes = ssz_serialize(execution_requests.consolidations)
|
||||||
|
|
||||||
return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
|
return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
|
||||||
```
|
```
|
||||||
|
@ -195,10 +195,10 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests:
|
def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests:
|
||||||
deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
|
deposits = ssz_deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
|
||||||
withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
|
withdrawals = ssz_deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
|
||||||
consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
|
consolidations = ssz_deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
|
||||||
execution_requests[2])
|
execution_requests[2])
|
||||||
|
|
||||||
return ExecutionRequests(deposits, withdrawals, consolidations)
|
return ExecutionRequests(deposits, withdrawals, consolidations)
|
||||||
```
|
```
|
||||||
|
@ -5,14 +5,22 @@ from remerkleable.core import Type, View
|
|||||||
from remerkleable.byte_arrays import Bytes32
|
from remerkleable.byte_arrays import Bytes32
|
||||||
|
|
||||||
|
|
||||||
def serialize(obj: View) -> bytes:
|
def ssz_serialize(obj: View) -> bytes:
|
||||||
return obj.encode_bytes()
|
return obj.encode_bytes()
|
||||||
|
|
||||||
|
|
||||||
def deserialize(typ: Type[View], data: bytes) -> View:
|
def serialize(obj: View) -> bytes:
|
||||||
|
return ssz_serialize(obj)
|
||||||
|
|
||||||
|
|
||||||
|
def ssz_deserialize(typ: Type[View], data: bytes) -> View:
|
||||||
return typ.decode_bytes(data)
|
return typ.decode_bytes(data)
|
||||||
|
|
||||||
|
|
||||||
|
def deserialize(typ: Type[View], data: bytes) -> View:
|
||||||
|
return ssz_deserialize(typ, data)
|
||||||
|
|
||||||
|
|
||||||
def hash_tree_root(obj: View) -> Bytes32:
|
def hash_tree_root(obj: View) -> Bytes32:
|
||||||
return Bytes32(obj.get_backing().merkle_root())
|
return Bytes32(obj.get_backing().merkle_root())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user