Exemplo n.º 1
0
class Receipts(Command):
    _cmd_id = 7
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('receipts', sedes.CountableList(sedes.CountableList(Receipt))),
    ]
Exemplo n.º 2
0
class P2PBlock(rlp.Serializable):
    transaction_class = P2PSendTransaction
    receive_transaction_class = P2PReceiveTransaction
    fields = [
        ('header', BlockHeader),
        ('transactions', sedes.CountableList(P2PSendTransaction)),
        ('receive_transactions', sedes.CountableList(P2PReceiveTransaction)),
        ('reward_bundle', StakeRewardBundle),
    ]
Exemplo n.º 3
0
class MinGasParameters(Command):
    _cmd_id = 32
    structure = [('hist_net_tpc_capability',
                  sedes.CountableList(
                      sedes.List([sedes.big_endian_int,
                                  sedes.big_endian_int]))),
                 ('hist_min_allowed_gas_price',
                  sedes.CountableList(
                      sedes.List([sedes.big_endian_int,
                                  sedes.big_endian_int])))]
Exemplo n.º 4
0
class ProofsV2(Command):
    _cmd_id = 16
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('proof', sedes.CountableList(sedes.raw)),
    ]
Exemplo n.º 5
0
class ContractCodes(Command):
    _cmd_id = 11
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('codes', sedes.CountableList(sedes.binary)),
    ]
Exemplo n.º 6
0
class BlockBodies(Command):
    _cmd_id = 5
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('bodies', sedes.CountableList(BlockBody)),
    ]
Exemplo n.º 7
0
class Proofs(Command):
    _cmd_id = 9
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('proofs', sedes.CountableList(sedes.CountableList(sedes.raw))),
    ]

    def decode_payload(self, rlp_data: bytes) -> _DecodedMsgType:
        decoded = super().decode_payload(rlp_data)
        decoded = cast(Dict[str, Any], decoded)
        # This is just to make Proofs messages compatible with ProofsV2, so that LightPeerChain
        # doesn't have to special-case them. Soon we should be able to drop support for LES/1
        # anyway, and then all this code will go away.
        if not decoded['proofs']:
            decoded['proof'] = []
        else:
            decoded['proof'] = decoded['proofs'][0]
        return decoded
Exemplo n.º 8
0
class Hello(Command):
    _cmd_id = 0
    decode_strict = False
    structure = [
        ('version', sedes.big_endian_int),
        ('client_version_string', sedes.text),
        ('capabilities',
         sedes.CountableList(sedes.List([sedes.text, sedes.big_endian_int]))),
        ('listen_port', sedes.big_endian_int), ('remote_pubkey', sedes.binary)
    ]
Exemplo n.º 9
0
class Announce(Command):
    _cmd_id = 1
    structure = [
        ('head_hash', sedes.binary),
        ('head_number', sedes.big_endian_int),
        ('head_td', sedes.big_endian_int),
        ('reorg_depth', sedes.big_endian_int),
        # TODO: The params CountableList may contain any of the values from the
        # Status msg.  Need to extend this command to process that too.
        ('params', sedes.CountableList(sedes.List([sedes.text, sedes.raw]))),
    ]
Exemplo n.º 10
0
class BlockHeaders(BaseBlockHeaders):
    _cmd_id = 3
    structure = [
        ('request_id', sedes.big_endian_int),
        ('buffer_value', sedes.big_endian_int),
        ('headers', sedes.CountableList(BlockHeader)),
    ]

    def extract_headers(self, msg: _DecodedMsgType) -> Tuple[BlockHeader, ...]:
        msg = cast(Dict[str, Any], msg)
        return cast(Tuple[BlockHeader, ...], tuple(msg['headers']))
Exemplo n.º 11
0
class BlockHeaders(Command):
    _cmd_id = 4
    structure = sedes.CountableList(BlockHeader)
Exemplo n.º 12
0
class Transactions(Command):
    _cmd_id = 2
    structure = sedes.CountableList(P2PSendTransaction)
Exemplo n.º 13
0
class NewBlockHashes(Command):
    _cmd_id = 1
    structure = sedes.CountableList(
        sedes.List([sedes.binary, sedes.big_endian_int]))
Exemplo n.º 14
0
class Blocks(Command):
    _cmd_id = 35
    structure = sedes.CountableList(P2PBlock)
Exemplo n.º 15
0
class GetBlocks(Command):
    _cmd_id = 34
    structure = sedes.CountableList(hash32)
Exemplo n.º 16
0
class ChainHeadTrieBranch(Command):
    _cmd_id = 18
    structure = sedes.CountableList(hash32)
Exemplo n.º 17
0
class NodeData(Command):
    _cmd_id = 14
    structure = sedes.CountableList(sedes.binary)
Exemplo n.º 18
0
class Chains(Command):
    _cmd_id = 28
    structure = [('chains', sedes.CountableList(sedes.CountableList(P2PBlock)))
                 ]
Exemplo n.º 19
0
class GetReceipts(Command):
    _cmd_id = 15
    structure = sedes.CountableList(sedes.binary)
Exemplo n.º 20
0
class UnorderedBlockHeaderHash(Command):
    _cmd_id = 22
    structure = sedes.CountableList(BlockHashKey)
Exemplo n.º 21
0
class GetUnorderedBlockHeaderHash(Command):
    _cmd_id = 21
    structure = sedes.CountableList(BlockNumberKey)
Exemplo n.º 22
0
class ChainHeadRootHashTimestamps(Command):
    _cmd_id = 20
    # this way is actually almost twice as fast as using a key... structure is [timestamp, root_hash]
    structure = sedes.CountableList(
        sedes.List([sedes.big_endian_int, sedes.binary]))
Exemplo n.º 23
0
class GetBlockBodies(Command):
    _cmd_id = 5
    structure = sedes.CountableList(sedes.binary)
Exemplo n.º 24
0
class ChronologicalBlockWindow(Command):
    _cmd_id = 30
    structure = [('blocks', sedes.CountableList(P2PBlock)),
                 ('final_root_hash', hash32)]
Exemplo n.º 25
0
class BlockBodies(Command):
    _cmd_id = 6
    structure = sedes.CountableList(BlockBody)
Exemplo n.º 26
0
class Status(Command):
    _cmd_id = 0
    decode_strict = False
    # A list of (key, value) pairs is all a Status msg contains, but since the values can be of
    # any type, we need to use the raw sedes here and do the actual deserialization in
    # decode_payload().
    structure = sedes.CountableList(sedes.List([sedes.text, sedes.raw]))
    # The sedes used for each key in the list above. Keys that use None as their sedes are
    # optional and have no value -- IOW, they just need to be present in the msg when appropriate.
    items_sedes = {
        'protocolVersion':
        sedes.big_endian_int,
        'networkId':
        sedes.big_endian_int,
        'headTd':
        sedes.big_endian_int,
        'headHash':
        sedes.binary,
        'headNum':
        sedes.big_endian_int,
        'genesisHash':
        sedes.binary,
        'serveHeaders':
        None,
        'serveChainSince':
        sedes.big_endian_int,
        'serveStateSince':
        sedes.big_endian_int,
        'txRelay':
        None,
        'flowControl/BL':
        sedes.big_endian_int,
        'flowControl/MRC':
        sedes.CountableList(
            sedes.List([
                sedes.big_endian_int, sedes.big_endian_int,
                sedes.big_endian_int
            ])),
        'flowControl/MRR':
        sedes.big_endian_int,
    }

    @to_dict
    def decode_payload(self, rlp_data: bytes) -> Iterator[Tuple[str, Any]]:
        data = cast(List[Tuple[str, bytes]], super().decode_payload(rlp_data))
        # The LES/Status msg contains an arbitrary list of (key, value) pairs, where values can
        # have different types and unknown keys should be ignored for forward compatibility
        # reasons, so here we need an extra pass to deserialize each of the key/value pairs we
        # know about.
        for key, value in data:
            if key not in self.items_sedes:
                continue
            yield key, self._deserialize_item(key, value)

    def encode_payload(
            self, data: Union[_DecodedMsgType, sedes.CountableList]) -> bytes:
        response = [
            (key, self._serialize_item(key, value))
            for key, value in sorted(cast(Dict[str, Any], data).items())
        ]
        return super().encode_payload(response)

    def _deserialize_item(self, key: str, value: bytes) -> Any:
        sedes = self.items_sedes[key]
        if sedes is not None:
            return sedes.deserialize(value)
        else:
            # See comment in the definition of item_sedes as to why we do this.
            return b''

    def _serialize_item(self, key: str, value: bytes) -> bytes:
        sedes = self.items_sedes[key]
        if sedes is not None:
            return sedes.serialize(value)
        else:
            # See comment in the definition of item_sedes as to why we do this.
            return b''
Exemplo n.º 27
0
class GetStakeForAddresses(Command):
    _cmd_id = 25
    structure = [('addresses', sedes.CountableList(address))]
Exemplo n.º 28
0
class Receipts(Command):
    _cmd_id = 16
    structure = sedes.CountableList(sedes.CountableList(Receipt))
Exemplo n.º 29
0
class BlockBody(rlp.Serializable):
    fields = [
        ('send_transactions', sedes.CountableList(P2PSendTransaction)),
        ('receive_transactions', sedes.CountableList(P2PReceiveTransaction)),
    ]
Exemplo n.º 30
0
class StakeForAddresses(Command):
    _cmd_id = 26
    structure = [
        ('stakes',
         sedes.CountableList(sedes.List([address, sedes.big_endian_int])))
    ]