Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Reduce clutter by removing intermediate variables
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Apr 16, 2020
1 parent 2a712ef commit 551123e
Showing 1 changed file with 37 additions and 73 deletions.
110 changes: 37 additions & 73 deletions trinity/protocol/eth/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,78 +29,63 @@
)


STATUS_V63_STRUCTURE = sedes.List((
sedes.big_endian_int,
sedes.big_endian_int,
sedes.big_endian_int,
hash_sedes,
hash_sedes,
))


class StatusV63(BaseCommand[StatusV63Payload]):
protocol_command_id = 0
serialization_codec: RLPCodec[StatusV63Payload] = RLPCodec(
sedes=STATUS_V63_STRUCTURE,
sedes=sedes.List((
sedes.big_endian_int,
sedes.big_endian_int,
sedes.big_endian_int,
hash_sedes,
hash_sedes,
)),
process_inbound_payload_fn=compose(
lambda args: StatusV63Payload(*args),
),
)


STATUS_STRUCTURE = sedes.List((
sedes.big_endian_int,
sedes.big_endian_int,
sedes.big_endian_int,
hash_sedes,
hash_sedes,
ForkID
))


class Status(BaseCommand[StatusPayload]):
protocol_command_id = 0
serialization_codec: RLPCodec[StatusPayload] = RLPCodec(
sedes=STATUS_STRUCTURE,
sedes=sedes.List((
sedes.big_endian_int,
sedes.big_endian_int,
sedes.big_endian_int,
hash_sedes,
hash_sedes,
ForkID
)),
process_inbound_payload_fn=compose(
lambda args: StatusPayload(*args),
),
)


NEW_BLOCK_HASHES_STRUCTURE = sedes.CountableList(sedes.List([hash_sedes, sedes.big_endian_int]))


class NewBlockHashes(BaseCommand[Tuple[NewBlockHash, ...]]):
protocol_command_id = 1
serialization_codec: RLPCodec[Tuple[NewBlockHash, ...]] = RLPCodec(
sedes=NEW_BLOCK_HASHES_STRUCTURE,
sedes=sedes.CountableList(sedes.List([hash_sedes, sedes.big_endian_int])),
process_inbound_payload_fn=apply_formatter_to_array(lambda args: NewBlockHash(*args)),
)


TRANSACTIONS_STRUCTURE = sedes.CountableList(BaseTransactionFields)


class Transactions(BaseCommand[Tuple[BaseTransactionFields, ...]]):
protocol_command_id = 2
serialization_codec: RLPCodec[Tuple[BaseTransactionFields, ...]] = RLPCodec(
sedes=TRANSACTIONS_STRUCTURE,
sedes=sedes.CountableList(BaseTransactionFields),
)


GET_BLOCK_HEADERS_V65_STRUCTURE = sedes.List((
HashOrNumber(),
sedes.big_endian_int,
sedes.big_endian_int,
sedes.boolean,
))


class GetBlockHeadersV65(BaseCommand[BlockHeadersQuery]):
protocol_command_id = 3
serialization_codec: RLPCodec[BlockHeadersQuery] = RLPCodec(
sedes=GET_BLOCK_HEADERS_V65_STRUCTURE,
sedes=sedes.List((
HashOrNumber(),
sedes.big_endian_int,
sedes.big_endian_int,
sedes.boolean,
)),
process_inbound_payload_fn=lambda args: BlockHeadersQuery(*args),
)

Expand All @@ -115,40 +100,31 @@ class BlockHeadersV65(BaseCommand[Tuple[BlockHeaderAPI, ...]]):
)


GET_BLOCK_BODIES_STRUCTURE = sedes.CountableList(hash_sedes)


class GetBlockBodiesV65(BaseCommand[Tuple[Hash32, ...]]):
protocol_command_id = 5
serialization_codec: RLPCodec[Tuple[Hash32, ...]] = RLPCodec(
sedes=GET_BLOCK_BODIES_STRUCTURE,
sedes=sedes.CountableList(hash_sedes),
)


BLOCK_BODIES_STRUCTURE = sedes.CountableList(BlockBody)


class BlockBodiesV65(BaseCommand[Tuple[BlockBody, ...]]):
protocol_command_id = 6
serialization_codec: RLPCodec[Tuple[BlockBody, ...]] = RLPCodec(
sedes=BLOCK_BODIES_STRUCTURE,
sedes=sedes.CountableList(BlockBody),
)


NEW_BLOCK_STRUCTURE = sedes.List((
sedes.List((
BlockHeader,
sedes.CountableList(BaseTransactionFields),
sedes.CountableList(BlockHeader)
)),
sedes.big_endian_int
))


class NewBlock(BaseCommand[NewBlockPayload]):
protocol_command_id = 7
serialization_codec: RLPCodec[NewBlockPayload] = RLPCodec(
sedes=NEW_BLOCK_STRUCTURE,
sedes=sedes.List((
sedes.List((
BlockHeader,
sedes.CountableList(BaseTransactionFields),
sedes.CountableList(BlockHeader)
)),
sedes.big_endian_int
)),
process_inbound_payload_fn=compose(
lambda args: NewBlockPayload(*args),
apply_formatter_at_index(
Expand Down Expand Up @@ -180,41 +156,29 @@ class PooledTransactionsV65(BaseCommand[Tuple[SignedTransactionAPI, ...]]):
)


GET_NODE_DATA_STRUCTURE = sedes.CountableList(hash_sedes)


class GetNodeDataV65(BaseCommand[Tuple[Hash32, ...]]):
protocol_command_id = 13
serialization_codec: RLPCodec[Tuple[Hash32, ...]] = RLPCodec(
sedes=GET_NODE_DATA_STRUCTURE,
sedes=sedes.CountableList(hash_sedes),
)


NODE_DATA_STRUCTURE = sedes.CountableList(sedes.binary)


class NodeDataV65(BaseCommand[Tuple[bytes, ...]]):
protocol_command_id = 14
serialization_codec: RLPCodec[Tuple[bytes, ...]] = RLPCodec(
sedes=NODE_DATA_STRUCTURE,
sedes=sedes.CountableList(sedes.binary),
)


GET_RECEIPTS_STRUCTURE = sedes.CountableList(hash_sedes)


class GetReceiptsV65(BaseCommand[Tuple[Hash32, ...]]):
protocol_command_id = 15
serialization_codec: RLPCodec[Tuple[Hash32, ...]] = RLPCodec(
sedes=GET_RECEIPTS_STRUCTURE,
sedes=sedes.CountableList(hash_sedes),
)


RECEIPTS_STRUCTURE = sedes.CountableList(sedes.CountableList(Receipt))


class ReceiptsV65(BaseCommand[Tuple[Tuple[ReceiptAPI, ...], ...]]):
protocol_command_id = 16
serialization_codec: RLPCodec[Tuple[Tuple[ReceiptAPI, ...], ...]] = RLPCodec(
sedes=RECEIPTS_STRUCTURE,
sedes=sedes.CountableList(sedes.CountableList(Receipt)),
)

0 comments on commit 551123e

Please sign in to comment.