Ejemplo n.º 1
0
    def fromJSON(keys: Dict[bytes, int], jsonArg: Dict[str, Any]) -> Any:
        json: Dict[str, Any] = dict(jsonArg)
        json["elements"] = list(json["elements"])
        json["elements"][0] = dict(json["elements"][0])
        json["elements"][1] = dict(json["elements"][1])

        json["elements"][0]["holder"] = json["holder"]
        json["elements"][1]["holder"] = json["holder"]

        e1: Element = Verification(bytes(32), 0)
        if json["elements"][0]["descendant"] == "Verification":
            e1 = Verification.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "VerificationPacket":
            json["elements"][0]["holders"] = list(
                json["elements"][0]["holders"])
            for h in range(len(json["elements"][0]["holders"])):
                json["elements"][0]["holders"][h] = keys[bytes.fromhex(
                    json["elements"][0]["holders"][h])]
            e1 = VerificationPacket.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "SendDifficulty":
            e1 = SendDifficulty.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "DataDifficulty":
            e1 = DataDifficulty.fromJSON(json["elements"][0])
        else:
            raise Exception(
                "Unknown Element used to construct a MeritRemoval.")

        e2: Element = Verification(bytes(32), 0)
        if json["elements"][1]["descendant"] == "Verification":
            e2 = Verification.fromJSON(json["elements"][1])
        elif json["elements"][1]["descendant"] == "VerificationPacket":
            json["elements"][1]["holders"] = list(
                json["elements"][1]["holders"])
            for h in range(len(json["elements"][1]["holders"])):
                json["elements"][1]["holders"][h] = keys[bytes.fromhex(
                    json["elements"][1]["holders"][h])]
            e2 = VerificationPacket.fromJSON(json["elements"][1])
        elif json["elements"][1]["descendant"] == "SendDifficulty":
            e2 = SendDifficulty.fromJSON(json["elements"][1])
        elif json["elements"][1]["descendant"] == "DataDifficulty":
            e2 = DataDifficulty.fromJSON(json["elements"][1])
        else:
            raise Exception(
                "Unknown Element used to construct a MeritRemoval.")

        return MeritRemoval(e1, e2, json["partial"])
Ejemplo n.º 2
0
    def fromSignedJSON(keys: Dict[bytes, int], jsonArg: Dict[str, Any]) -> Any:
        json: Dict[str, Any] = dict(jsonArg)
        json["elements"] = list(json["elements"])
        json["elements"][0] = dict(json["elements"][0])
        json["elements"][1] = dict(json["elements"][1])

        json["elements"][0]["holder"] = json["holder"]
        json["elements"][1]["holder"] = json["holder"]

        e1: Union[SignedVerification, SignedVerificationPacket,
                  SignedSendDifficulty,
                  SignedDataDifficulty] = SignedVerification(bytes(32), 0)
        if json["elements"][0]["descendant"] == "Verification":
            e1 = Verification.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "VerificationPacket":
            json["elements"][0]["holders"] = list(
                json["elements"][0]["holders"])
            for h in range(len(json["elements"][0]["holders"])):
                json["elements"][0]["holders"][h] = keys[bytes.fromhex(
                    json["elements"][0]["holders"][h])]
            e1 = VerificationPacket.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "SendDifficulty":
            e1 = SendDifficulty.fromJSON(json["elements"][0])
        elif json["elements"][0]["descendant"] == "DataDifficulty":
            e1 = DataDifficulty.fromJSON(json["elements"][0])

        e2: Union[SignedVerification, SignedVerificationPacket,
                  SignedSendDifficulty,
                  SignedDataDifficulty] = SignedVerification(bytes(32), 0)
        if json["elements"][1]["descendant"] == "Verification":
            e2 = SignedVerification.fromSignedJSON(json["elements"][1])
        elif json["elements"][1]["descendant"] == "VerificationPacket":
            json["elements"][1]["holders"] = list(
                json["elements"][1]["holders"])
            for h in range(len(json["elements"][1]["holders"])):
                json["elements"][1]["holders"][h] = keys[bytes.fromhex(
                    json["elements"][1]["holders"][h])]
            e2 = SignedVerificationPacket.fromSignedJSON(json["elements"][1])
        elif json["elements"][1]["descendant"] == "SendDifficulty":
            e2 = SignedSendDifficulty.fromSignedJSON(json["h"][1])
        elif json["elements"][1]["descendant"] == "DataDifficulty":
            e2 = SignedDataDifficulty.fromSignedJSON(json["elements"][1])

        return PartialMeritRemoval(e1, e2)