def fromJSON(json: Dict[str, Any]) -> Any: e1: Element = Element() if json["elements"][0]["descendant"] == "Verification": e1 = Verification.fromJSON(json["elements"][0]) e2: Element = Element() if json["elements"][1]["descendant"] == "Verification": e2 = Verification.fromJSON(json["elements"][1]) result: MeritRemoval = MeritRemoval(json["partial"], e1, e2) result.nonce = json["nonce"] return result
def fromJSON( sendDiff: bytes, dataDiff: bytes, json: Dict[str, List[Dict[str, Any]]] ) -> Any: result = Consensus(sendDiff, dataDiff) for mh in json: for elem in json[mh]: if "signed" in elem: if elem["descendant"] == "Verification": result.add(SignedVerification.fromJSON(elem)) elif elem["descendant"] == "MeritRemoval": if elem["partial"]: result.add(PartiallySignedMeritRemoval.fromJSON(elem)) else: result.add(SignedMeritRemoval.fromJSON(elem)) else: raise Exception("JSON has an unsupported Element type: " + elem["descendant"]) else: if elem["descendant"] == "Verification": result.add(Verification.fromJSON(elem)) elif elem["descendant"] == "MeritRemoval": result.add(MeritRemoval.fromJSON(elem)) else: raise Exception("JSON has an unsupported Element type: " + elem["descendant"]) return result
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"])
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)
def fromJSON(json: Dict[str, Any]) -> Any: e1: Element = Element() if json["elements"][0]["descendant"] == "Verification": e1 = Verification.fromJSON(json["elements"][0]) else: raise Exception( "MeritRemoval constructed from an unsupported type of Element: " + json["elements"][0]["descendant"]) se2: SignedElement = SignedElement() if json["elements"][1]["descendant"] == "Verification": se2 = SignedVerification.fromJSON(json["elements"][1]) else: raise Exception( "MeritRemoval constructed from an unsupported type of Element: " + json["elements"][1]["descendant"]) result: PartiallySignedMeritRemoval = PartiallySignedMeritRemoval( e1, se2) result.nonce = json["nonce"] return result
def fromSignedJSON(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, SignedMeritRemovalVerificationPacket, SignedSendDifficulty, SignedDataDifficulty] = SignedVerification(bytes(32), 0) if json["elements"][0]["descendant"] == "Verification": e1 = Verification.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "VerificationPacket": e1 = SignedMeritRemovalVerificationPacket.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, SignedMeritRemovalVerificationPacket, SignedSendDifficulty, SignedDataDifficulty] = SignedVerification(bytes(32), 0) if json["elements"][1]["descendant"] == "Verification": e2 = SignedVerification.fromSignedJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "VerificationPacket": e2 = SignedMeritRemovalVerificationPacket.fromSignedJSON( json["elements"][1]) elif json["elements"][1]["descendant"] == "SendDifficulty": e2 = SignedSendDifficulty.fromSignedJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "DataDifficulty": e2 = SignedDataDifficulty.fromSignedJSON(json["elements"][1]) return PartialMeritRemoval(e1, e2, json["holder"])