Exemplo n.º 1
0
#Verify it.
competitorVerif: SignedVerification = SignedVerification(competitor.hash)
competitorVerif.sign(0, blsPrivKey)

#Mine one more Block.
block = Block(
  BlockHeader(
    0,
    merit.blockchain.last(),
    BlockHeader.createContents([VerificationPacket(competitor.hash, [0])]),
    1,
    bytes(4),
    BlockHeader.createSketchCheck(bytes(4), [VerificationPacket(competitor.hash, [0])]),
    0,
    merit.blockchain.blocks[-1].header.time + 1200
  ),
  BlockBody([VerificationPacket(competitor.hash, [0])], [], competitorVerif.signature)
)
block.mine(blsPrivKey, merit.blockchain.difficulty())
merit.add(block)
print("Generated Competing Finalized Block " + str(len(merit.blockchain.blocks) - 1) + ".")

result: Dict[str, Any] = {
  "blockchain": merit.blockchain.toJSON(),
  "transactions": transactions.toJSON()
}
vectors: IO[Any] = open("e2e/Vectors/Transactions/CompetingFinalized.json", "w")
vectors.write(json.dumps(result))
vectors.close()
Exemplo n.º 2
0
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] = {
    "blockchain": blockchain.toJSON(),
    "transactions": transactions.toJSON(),
    "verification": verifs[1].toSignedJSON(),
    "transaction": data.hash.hex().upper()
Exemplo n.º 3
0
    alt.add(Block.fromJSON(blocks[b]))

#Generate an alternative five Blocks.
for i in range(1, 5):
    #Create the next Block.
    block = Block(
        BlockHeader(
            0,
            alt.last(),
            bytes(32),
            1,
            bytes(4),
            bytes(32),
            0,
            alt.blocks[-1].header.time +
            1  #Use a much shorter time to acquire more work.
        ),
        BlockBody())

    #Mine the Block.
    block.mine(privKey, alt.difficulty())

    #Add it locally.
    alt.add(block)
    print("Generated Shorter Chain, More Work Block " + str(i) + ".")

vectors: IO[Any] = open(
    "e2e/Vectors/Merit/Reorganizations/ShorterChainMoreWork.json", "w")
vectors.write(json.dumps({"main": main.toJSON(), "alt": alt.toJSON()}))
vectors.close()
Exemplo n.º 4
0
#Create the Block to the first miner.
block: Block = Block(
    BlockHeader(0, main.last(), bytes(32), 1, bytes(4), bytes(32),
                privKeys[0].toPublicKey().serialize(),
                main.blocks[-1].header.time + 1200), BlockBody())
block.mine(privKeys[0], main.difficulty())
main.add(block)
alt.add(block)
print("Generated Reorganizations Depth One Block 1.")

#Create the Block to the second miner.
block = Block(
    BlockHeader(0, main.last(), bytes(32), 1, bytes(4), bytes(32),
                privKeys[1].toPublicKey().serialize(),
                main.blocks[-1].header.time + 1200), BlockBody())
block.mine(privKeys[1], alt.difficulty())
main.add(block)
alt.add(block)
print("Generated Reorganizations Depth One Block 2.")

#Create the competing Block to the first miner.
block = Block(
    BlockHeader(0, main.last(), bytes(32), 1, bytes(4), bytes(32), 0,
                main.blocks[-1].header.time + 1200), BlockBody())
block.mine(privKeys[0], main.difficulty())
main.add(block)
print("Generated Reorganizations Depth One Block 3.")

#Create the competing Block to the second miner.
#Since the difficulty is fixed at the start, they're guaranteed to have the same amount of work.
#Because of that, we can't just mine the Block; we need to mine it until it has a lower hash than the above Block.
Exemplo n.º 5
0
#Generate a Block granting the holder Merit.
block = Block(
  BlockHeader(
    0,
    e1Chain.last(),
    bytes(32),
    1,
    bytes(4),
    bytes(32),
    blsPubKey.serialize(),
    e1Chain.blocks[-1].header.time + 1200
  ),
  BlockBody()
)
#Mine it.
block.mine(blsPrivKey, e1Chain.difficulty())

#Add it.
e1Chain.add(block)
e2Chain.add(block)
print("Generated Hundred Thirty Three Block 1/2 " + str(len(e1Chain.blocks)) + ".")

#Create the initial Data and two competing Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
  data.sign(edPrivKey)
  data.beat(spamFilter)

#Create Verifications for all 3.
Exemplo n.º 6
0
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#SpamFilter.
spamFilter: SpamFilter = SpamFilter(5)

#Blockchains.
packetedChain: Blockchain = Blockchain()
reorderedChain: Blockchain = Blockchain()

#Generate a Block granting the holder Merit.
block = Block(
    BlockHeader(0, packetedChain.last(), bytes(32), 1, bytes(4), bytes(32),
                blsPubKey.serialize(),
                packetedChain.blocks[-1].header.time + 1200), BlockBody())
#Mine it.
block.mine(blsPrivKey, packetedChain.difficulty())

#Add it.
packetedChain.add(block)
reorderedChain.add(block)
print("Generated Hundred Twenty Three Packet Block 1/2 " +
      str(len(packetedChain.blocks)) + ".")

#Create the initial Data and two competing Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
    data.sign(edPrivKey)
    data.beat(spamFilter)