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: MeritRemovalElement = 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: MeritRemovalElement = 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"])
def fromJSON(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": e1 = MeritRemovalVerificationPacket.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": e2 = MeritRemovalVerificationPacket.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"], json["holder"])
def fromJSON(json: Dict[str, Any]) -> Any: packets: List[VerificationPacket] = [] elements: List[Element] = [] for packet in json["transactions"]: packets.append( VerificationPacket(bytes.fromhex(packet["hash"]), packet["holders"])) for element in json["elements"]: if element["descendant"] == "SendDifficulty": elements.append(SendDifficulty.fromJSON(element)) elif element["descendant"] == "DataDifficulty": elements.append(DataDifficulty.fromJSON(element)) return BlockBody(packets, elements, Signature(bytes.fromhex(json["aggregate"])))
#Generate a Data to verify for the VerificationPacket Block. data: Data = Data(bytes(32), edPubKey) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) packet: VerificationPacket = VerificationPacket(data.hash, [1]) blocks.append( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, packets=[VerificationPacket(data.hash, [1])], minerID=blsPrivKey).finish(0, merit).toJSON()) #Generate the SendDifficulty Block. blocks.append( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, elements=[SendDifficulty(0, 0, 1)], minerID=blsPrivKey).finish(0, merit).toJSON()) #Generate the DataDifficulty Block. blocks.append( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, elements=[DataDifficulty(0, 0, 1)], minerID=blsPrivKey).finish(0, merit).toJSON()) with open("e2e/Vectors/Consensus/HundredSix/BlockElements.json", "w") as vectors: vectors.write( json.dumps({ "blocks": blocks, "transactions": transactions.toJSON() }))
from e2e.Classes.Consensus.VerificationPacket import VerificationPacket from e2e.Classes.Consensus.SendDifficulty import SendDifficulty from e2e.Classes.Consensus.DataDifficulty import DataDifficulty from e2e.Classes.Consensus.SpamFilter import SpamFilter from e2e.Classes.Merit.Merit import Merit from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain proto: PrototypeChain = PrototypeChain(7) proto.add(1) proto.add(2) proto.add(3) proto.add(4) proto.add(elements=[SendDifficulty(1, 0, 2), SendDifficulty(1, 0, 4)]) merit: Merit = Merit.fromJSON(proto.toJSON()) transactions: Transactions = Transactions() claim: Claim = Claim([(merit.mints[-1], 0)], ed25519.SigningKey(b'\0' * 32).get_verifying_key().to_bytes()) claim.sign(PrivateKey(0)) transactions.add(claim) send: Send = Send([(claim.hash, 0)], [(ed25519.SigningKey( b'\1' * 32).get_verifying_key().to_bytes(), claim.amount)]) send.sign(ed25519.SigningKey(b'\0' * 32)) send.beat(SpamFilter(3)) transactions.add(send)
from typing import IO, Any import json from e2e.Classes.Consensus.SendDifficulty import SendDifficulty from e2e.Classes.Consensus.DataDifficulty import DataDifficulty from e2e.Classes.Merit.Merit import Merit from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain merit: Merit = Merit.fromJSON(PrototypeChain(49).finish().toJSON()) #Add the Difficulties. merit.add( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, elements=[SendDifficulty(2, 0, 0), DataDifficulty(2, 1, 0)], minerID=0).finish(0, merit)) #Close out this, and the next, Checkpoint period to lock our Merit. for _ in range(9): merit.add( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, minerID=0).finish(0, merit)) #Become Pending. merit.add( PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200, minerID=0).finish(1, merit)) vectors: IO[Any] = open("e2e/Vectors/Consensus/Difficulties/LockedMerit.json",
import json from e2e.Classes.Consensus.SendDifficulty import SendDifficulty from e2e.Vectors.Generation.PrototypeChain import PrototypeChain proto: PrototypeChain = PrototypeChain(25) proto.add(elements=[SendDifficulty(2, 0, 0)]) for _ in range(24): proto.add() proto.add(elements=[SendDifficulty(1, 1, 0)]) proto.add(elements=[SendDifficulty(2, 1, 0)]) with open("e2e/Vectors/Consensus/Difficulties/SendDifficulty.json", "w") as vectors: vectors.write(json.dumps(proto.toJSON()))
from typing import IO, Any import json from e2e.Classes.Consensus.SendDifficulty import SendDifficulty from e2e.Classes.Consensus.MeritRemoval import MeritRemoval from e2e.Vectors.Generation.PrototypeChain import PrototypeChain proto: PrototypeChain = PrototypeChain(25) proto.add(elements=[SendDifficulty(2, 0, 0)]) for _ in range(24): proto.add() proto.add(elements=[SendDifficulty(1, 1, 0)]) proto.add(elements=[MeritRemoval(SendDifficulty(1, 1, 0), SendDifficulty(2, 1, 0), True)]) for _ in range(50): proto.add() vectors: IO[Any] = open("e2e/Vectors/Consensus/Difficulties/SendDifficulty.json", "w") vectors.write(json.dumps({ "blockchain": proto.toJSON() })) vectors.close()
bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(data.hash, [1])]), blsPrivKey.toPublicKey().serialize(), blockchain.blocks[-1].header.time + 1200), BlockBody([VerificationPacket(data.hash, [1])], [], blsPrivKey.sign(b""))) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it to the vectors. blocks.append(block.toJSON()) print("Generated Hundred Six Block Elements VerificationPacket Block.") #Generate the SendDifficulty Block. elements: List[Element] = [] elements.append(SendDifficulty(0, 0, 1)) block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], elements), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), []), blsPrivKey.toPublicKey().serialize(), blockchain.blocks[-1].header.time + 1200), BlockBody([], elements, blsPrivKey.sign(b""))) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it to the vectors. blocks.append(block.toJSON()) print("Generated Hundred Six Block Elements SendDifficulty Block.") #Generate the DataDifficulty Block.