Skip to content

Commit 6416a56

Browse files
committed
Add ssz_{de,}serialize aliases
1 parent 83c04b8 commit 6416a56

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

pysetup/spec_builders/electra.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ElectraSpecBuilder(BaseSpecBuilder):
1010
def imports(cls, preset_name: str):
1111
return f'''
1212
from eth2spec.deneb import {preset_name} as deneb
13-
from eth2spec.utils.ssz.ssz_impl import serialize, deserialize
13+
from eth2spec.utils.ssz.ssz_impl import ssz_serialize, ssz_deserialize
1414
'''
1515

1616
@classmethod

specs/electra/beacon-chain.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,9 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
11461146

11471147
```python
11481148
def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]:
1149-
deposit_bytes = serialize(execution_requests.deposits)
1150-
withdrawal_bytes = serialize(execution_requests.withdrawals)
1151-
consolidation_bytes = serialize(execution_requests.consolidations)
1149+
deposit_bytes = ssz_serialize(execution_requests.deposits)
1150+
withdrawal_bytes = ssz_serialize(execution_requests.withdrawals)
1151+
consolidation_bytes = ssz_serialize(execution_requests.consolidations)
11521152

11531153
return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
11541154
```

specs/electra/validator.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen
195195

196196
```python
197197
def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests:
198-
deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
199-
withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
200-
consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
201-
execution_requests[2])
198+
deposits = ssz_deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
199+
withdrawals = ssz_deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
200+
consolidations = ssz_deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
201+
execution_requests[2])
202202

203203
return ExecutionRequests(deposits, withdrawals, consolidations)
204204
```

tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
from remerkleable.byte_arrays import Bytes32
66

77

8-
def serialize(obj: View) -> bytes:
8+
def ssz_serialize(obj: View) -> bytes:
99
return obj.encode_bytes()
1010

1111

12-
def deserialize(typ: Type[View], data: bytes) -> View:
12+
def serialize(obj: View) -> bytes:
13+
return ssz_serialize(obj)
14+
15+
16+
def ssz_deserialize(typ: Type[View], data: bytes) -> View:
1317
return typ.decode_bytes(data)
1418

1519

20+
def deserialize(typ: Type[View], data: bytes) -> View:
21+
return ssz_deserialize(typ, data)
22+
23+
1624
def hash_tree_root(obj: View) -> Bytes32:
1725
return Bytes32(obj.get_backing().merkle_root())
1826

0 commit comments

Comments
 (0)