packets: List[VerificationPacket] = [ VerificationPacket(first.hash, [0]), VerificationPacket(second.hash, [0]), ] #Generate another 6 Blocks. #Next block should have the packets. block: Block = Block( BlockHeader( 0, merit.blockchain.last(), BlockHeader.createContents(packets), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 0, merit.blockchain.blocks[-1].header.time + 1200 ), BlockBody(packets, [], Signature.aggregate([firstVerif.signature, secondVerif.signature])) ) for _ in range(6): #Mine it. block.mine(blsPrivKey, merit.blockchain.difficulty()) #Add it. merit.add(block) print("Generated Competing Finalized Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Create the next Block. block = Block(
verifs[-1][v].sign(v, blsPrivKeys[v]) #Create the packets. packets: List[SignedVerificationPacket] = [] for packet in verifs: packets.append( SignedVerificationPacket( packet[0].hash, [0, 1], Signature.aggregate([packet[0].signature, packet[1].signature]))) #Create Blocks containing these packets. for packet in packets: block = Block( BlockHeader(0, merit.blockchain.last(), BlockHeader.createContents([packet]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [packet]), 1, merit.blockchain.blocks[-1].header.time + 1200), BlockBody([packet], [], packet.signature)) block.mine(blsPrivKeys[1], merit.blockchain.difficulty()) merit.add(block) print("Generated Aggregated Claim Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Generate another 5 Blocks to close the Epochs. #Next block should have the packet. for _ in range(5): block = Block( BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 0, merit.blockchain.blocks[-1].header.time + 1200), BlockBody())
data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Verify it. verif: SignedVerification = SignedVerification(data.hash) verif.sign(0, blsPrivKey) #Generate another 6 Blocks. #Next block should have a packet. block: Block = Block( BlockHeader( 0, merit.blockchain.last(), BlockHeader.createContents([VerificationPacket(verif.hash, [0])]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(verif.hash, [0])]), 0, merit.blockchain.blocks[-1].header.time + 1200), BlockBody([VerificationPacket(verif.hash, [0])], [], verif.signature)) for _ in range(6): #Mine it. block.mine(blsPrivKey, merit.blockchain.difficulty()) #Add it. merit.add(block) print("Generated Claimed Mint Block " + str(len(merit.blockchain.blocks) - 1) + ".") #Create the next Block. block = Block( BlockHeader(0, merit.blockchain.last(), bytes(32), 1, bytes(4), bytes(32),
#Verify them in unique Blocks. packet: List[VerificationPacket] for data in datas: verif: SignedVerification = SignedVerification(data.hash) verif.sign(0, blsPrivKey) packet = [VerificationPacket(data.hash, [0])] block = Block( BlockHeader( 0, merit.blockchain.last(), BlockHeader.createContents(packet), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), packet), 0, merit.blockchain.blocks[-1].header.time + 1200 ), BlockBody(packet, [], verif.signature) ) block.mine(blsPrivKey, merit.blockchain.difficulty()) merit.add(block) #Generate another 5 Blocks to close the Epochs. for _ in range(5): block = Block( BlockHeader( 0, merit.blockchain.last(), bytes(32),
transactions.add(competingData) #Verify the Datas. verif: SignedVerification = SignedVerification(data.hash) verif.sign(0, blsPrivKey) competingVerif: SignedVerification = SignedVerification(competingData.hash) competingVerif.sign(0, blsPrivKey) #Create a MeritRemoval out of the conflicting Verifications. mr: SignedMeritRemoval = SignedMeritRemoval(verif, competingVerif) #Generate a Block containing the MeritRemoval. block = Block( BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [mr]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), []), 0, blockchain.blocks[-1].header.time + 1200), BlockBody([], [mr], mr.signature)) #Mine it. block.mine(blsPrivKey, blockchain.difficulty()) #Add it. blockchain.add(block) print("Generated Invalid Competing Block " + str(len(blockchain.blocks)) + ".") result: Dict[str, Any] = { "blockchain": blockchain.toJSON(), "transactions": transactions.toJSON(), "removal": mr.toSignedJSON() } vectors: IO[Any] = open(
BlockBody() ) blank.mine(blsPrivKey, blockchain.difficulty()) blockchain.add(blank) #Generate a Block which has a VP with no holders. vp: VerificationPacket = VerificationPacket(b'z' * 32, []) blocks.append( Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([vp]), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), [vp]), 0, blockchain.blocks[-1].header.time + 1200 ), BlockBody([vp], [], blsPrivKey.sign(b'')) ) ) blocks[-1].mine(blsPrivKey, blockchain.difficulty()) #Generate a Block which has a MR VP with no holders. mr: MeritRemoval = MeritRemoval( MeritRemovalVerificationPacket(b'z' * 32, []), MeritRemovalVerificationPacket(b'z' * 32, []), False, 0 )
#BLS Private Key. blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest()) #Create a Data for the VerificationPacket. data: Data = Data(bytes(32), edPubKey.to_bytes()) data.sign(edPrivKey) data.beat(dataFilter) transactions.add(data) #Generate the VerificationPacket Block. block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents([VerificationPacket(data.hash, [1])]), 1, 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([],
for h in order[0]: for s in order[0][h]: if s not in packets: packets[s] = VerificationPacket(sends[s].hash, []) packets[s].holders.append(h) verif: SignedVerification = SignedVerification(sends[s].hash) verif.sign(h, blsPrivKeys[h]) toAggregate.append(verif.signature) block: Block = Block( BlockHeader( 0, blockchain.last(), BlockHeader.createContents(list(packets.values())), 1, bytes(4), BlockHeader.createSketchCheck(bytes(4), list(packets.values())), order[1], blockchain.blocks[-1].header.time + 1200), BlockBody(list(packets.values()), [], Signature.aggregate(toAggregate))) miner: Union[bytes, int] = order[1] if isinstance(miner, bytes): for k in range(len(blsPubKeys)): if miner == blsPubKeys[k].serialize(): block.mine(blsPrivKeys[k], blockchain.difficulty()) break else: block.mine(blsPrivKeys[miner], blockchain.difficulty()) blockchain.add(block) print("Generated Fifty Block " + str(len(blockchain.blocks) - 1) + ".")