Esempio n. 1
0
    def _deserialize_kv_pairs(
            cls,
            serialized_enr: Sequence[bytes]) -> Iterable[Tuple[bytes, Any]]:
        serialized_keys = serialized_enr[1::2]
        serialized_values = serialized_enr[2::2]

        keys = tuple(
            binary.deserialize(serialized_key)
            for serialized_key in serialized_keys)
        cls._validate_key_uniqueness(keys, serialized_enr)
        cls._validate_key_order(keys, serialized_enr)

        value_deserializers = tuple(
            ENR_KEY_SEDES_MAPPING.get(key, FALLBACK_ENR_VALUE_SEDES)
            for key in keys)
        values = tuple(
            excepts(
                DeserializationError,
                value_deserializer.deserialize,
                lambda v: FALLBACK_ENR_VALUE_SEDES.deserialize(serialized_value
                                                               ),
            )(serialized_value)
            for value_deserializer, serialized_value in zip(
                value_deserializers, serialized_values))

        return dict(zip(keys, values))
Esempio n. 2
0
 def deserialize(
     cls,
     serialized_enr: Sequence[bytes],
 ) -> "ENR":
     cls._validate_serialized_length(serialized_enr)
     signature = binary.deserialize(serialized_enr[0])
     unsigned_enr = ENRContentSedes.deserialize(serialized_enr[1:], )
     return ENR(
         unsigned_enr.sequence_number,
         dict(unsigned_enr),
         signature,
     )
 def deserialize(
     cls,
     serialized_enr: Sequence[bytes],
     identity_scheme_registry:
     IdentitySchemeRegistry = default_id_scheme_registry,
 ) -> "ENR":
     cls._validate_serialized_length(serialized_enr)
     signature = binary.deserialize(serialized_enr[0])
     unsigned_enr = ENRContentSedes.deserialize(
         serialized_enr[1:],
         identity_scheme_registry=identity_scheme_registry,
     )
     return ENR(
         unsigned_enr.sequence_number,
         dict(unsigned_enr),
         signature,
         identity_scheme_registry,
     )
Esempio n. 4
0
    def deserialize(
        cls,
        serialized_enr: Sequence[bytes],
        identity_scheme_registry:
        IdentitySchemeRegistryAPI = default_id_scheme_registry,
    ) -> ENRAPI:
        from eth_enr.enr import ENR  # noqa: F811

        cls._validate_serialized_length(serialized_enr)
        signature = binary.deserialize(serialized_enr[0])
        unsigned_enr = ENRContentSedes.deserialize(
            serialized_enr[1:],
            identity_scheme_registry=identity_scheme_registry)
        return ENR(
            unsigned_enr.sequence_number,
            dict(unsigned_enr),
            signature,
            identity_scheme_registry,
        )