Esempio n. 1
0
    def decode(cls, kwargs_protobuf_object: Any) -> "Kwargs":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class is created that matches the protocol buffer object in the 'kwargs_protobuf_object' argument.

        :param kwargs_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'kwargs_protobuf_object' argument.
        """
        kwargs = DictProtobufStructSerializer.decode(kwargs_protobuf_object.kwargs)
        return cls(kwargs)
Esempio n. 2
0
    def decode(cls, state_protobuf_object) -> "State":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class must be created that matches the protocol buffer object in the 'state_protobuf_object' argument.

        :param state_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'state_protobuf_object' argument.
        """
        state_dict = DictProtobufStructSerializer.decode(
            state_protobuf_object.state)
        return cls(state_dict["ledger_id"], state_dict["body"])
Esempio n. 3
0
    def decode(cls, agents_info_protobuf_object: Any) -> "AgentsInfo":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class is created that matches the protocol buffer object in the 'agents_info_protobuf_object' argument.

        :param agents_info_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'agents_info_protobuf_object' argument.
        """
        body = DictProtobufStructSerializer.decode(
            agents_info_protobuf_object.agents_info)
        return cls(body)
Esempio n. 4
0
    def decode(cls, raw_transaction_protobuf_object) -> "RawTransaction":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class must be created that matches the protocol buffer object in the 'raw_transaction_protobuf_object' argument.

        :param raw_transaction_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'raw_transaction_protobuf_object' argument.
        """
        raw_transaction_dict = DictProtobufStructSerializer.decode(
            raw_transaction_protobuf_object.raw_transaction)
        return cls(raw_transaction_dict["ledger_id"],
                   raw_transaction_dict["body"])
Esempio n. 5
0
def test_encode_decode_ii():
    """Test encode decode logic."""
    case = {
        "key1": True,
        "key2": 0.12,
        "key3": 100,
        "key4": "some string",
        "key5": b"some bytes string",
        "key6": {"key1": True, "key2": 0.12},
    }
    encoded = DictProtobufStructSerializer.encode(case)
    assert isinstance(encoded, bytes)
    decoded = DictProtobufStructSerializer.decode(encoded)
    assert case == decoded
Esempio n. 6
0
    def decode(cls,
               transaction_digest_protobuf_object: Any) -> "TransactionDigest":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class must be created that matches the protocol buffer object in the 'transaction_digest_protobuf_object' argument.

        :param transaction_digest_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'transaction_digest_protobuf_object' argument.
        """
        transaction_digest_dict = DictProtobufStructSerializer.decode(
            transaction_digest_protobuf_object.transaction_digest)

        return cls(transaction_digest_dict["ledger_id"],
                   transaction_digest_dict["body"])
Esempio n. 7
0
    def decode(cls, signed_message_protobuf_object: Any) -> "SignedMessage":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class must be created that matches the protocol buffer object in the 'signed_message_protobuf_object' argument.

        :param signed_message_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'signed_message_protobuf_object' argument.
        """
        signed_message_dict = DictProtobufStructSerializer.decode(
            signed_message_protobuf_object.signed_message)
        return cls(
            signed_message_dict["ledger_id"],
            signed_message_dict["body"],
            signed_message_dict["is_deprecated_mode"],
        )
Esempio n. 8
0
    def decode(cls, terms_protobuf_object) -> "Terms":
        """
        Decode a protocol buffer object that corresponds with this class into an instance of this class.

        A new instance of this class must be created that matches the protocol buffer object in the 'terms_protobuf_object' argument.

        :param terms_protobuf_object: the protocol buffer object whose type corresponds with this class.
        :return: A new instance of this class that matches the protocol buffer object in the 'terms_protobuf_object' argument.
        """
        terms_dict = DictProtobufStructSerializer.decode(
            terms_protobuf_object.terms)

        return cls(
            terms_dict["ledger_id"],
            terms_dict["sender_address"],
            terms_dict["counterparty_address"],
            terms_dict["amount_by_currency_id"],
            terms_dict["quantities_by_good_id"],
            terms_dict["nonce"],
            terms_dict["is_sender_payable_tx_fee"],
            dict(terms_dict["fee_by_currency_id"]),
            terms_dict["is_strict"],
            **dict(terms_dict["kwargs"]),
        )