Ejemplo n.º 1
0
    [(claim, 0), (claim, 0)],
    [(edPubKey.to_bytes(),
      Claim.fromTransaction(transactions.txs[claim]).amount * 2)])
send.sign(edPrivKey)
send.beat(sendFilter)
transactions.add(send)

#Create a Verification/VerificationPacket for the Send.
sv: SignedVerification = SignedVerification(send.hash)
sv.sign(0, blsPrivKey)
packet: VerificationPacket = VerificationPacket(send.hash, [0])

#Add a Block verifying it.
block: Block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([packet]), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), [packet]), 0,
                blockchain.blocks[-1].header.time + 1200),
    BlockBody([packet], [], sv.signature))

#Mine the Block.
block.mine(blsPrivKey, blockchain.difficulty())

#Add the Block.
blockchain.add(block)
print("Generated Same Input Block " + str(len(blockchain.blocks) - 1) + ".")

#Save the vector.
result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "transactions": transactions.toJSON()
}
Ejemplo n.º 2
0
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 Invalid Competing 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),
Ejemplo n.º 3
0
            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())
Ejemplo n.º 4
0
data: Data = Data(bytes(32), edPubKey.to_bytes())
data.sign(edPrivKey)
data.beat(spamFilter)
transactions.add(data)

verifs: List[SignedVerification] = [
    SignedVerification(data.hash),
    SignedVerification(data.hash)
]
verifs[0].sign(0, blsPrivKeys[0])
verifs[1].sign(1, blsPrivKeys[1])
packets: List[VerificationPacket] = [VerificationPacket(data.hash, [0])]

block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents(packets), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), packets), 1,
                blockchain.blocks[-1].header.time + 1200),
    BlockBody(packets, [], verifs[0].signature))
for _ in range(6):
    block.mine(blsPrivKeys[1], blockchain.difficulty())
    blockchain.add(block)
    print("Generated Hundred Forty Two Block " + str(len(blockchain.blocks)) +
          ".")

    #Create the next Block.
    block = Block(
        BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 1,
                    blockchain.blocks[-1].header.time + 1200), BlockBody())

#Save the appended data (3 Blocks and 12 Sends).
result: Dict[str, Any] = {
Ejemplo n.º 5
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([],
Ejemplo n.º 6
0
firstVerif.sign(0, blsPrivKey)

secondVerif: SignedVerification = SignedVerification(second.hash)
secondVerif.sign(0, blsPrivKey)

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(