예제 #1
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)
예제 #2
0
#Generate an alternative fifteen Blocks.
for i in range(1, 15):
    #Create the next Block.
    block = Block(
        BlockHeader(
            0,
            alt.last(),
            bytes(32),
            1,
            bytes(4),
            bytes(32),
            0,
            alt.blocks[-1].header.time + 1201 #Use a slightly different time to ensure a different hash.
        ),
        BlockBody()
    )

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

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

vectors: IO[Any] = open("PythonTests/Vectors/Merit/Reorganizations/LongerChainMoreWork.json", "w")
vectors.write(json.dumps({
    "main": main.toJSON(),
    "alt": alt.toJSON()
}))
vectors.close()
예제 #3
0
#Verify the Send.
competingVerif: SignedVerification = SignedVerification(send.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, merit.blockchain.last(),
                BlockHeader.createContents([], [], [mr]), 1, bytes(4),
                BlockHeader.createSketchCheck(bytes(4), []), 0,
                merit.blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [mr], mr.signature))
#Mine it.
block.mine(blsPrivKey, merit.blockchain.difficulty())

#Add it.
merit.blockchain.add(block)
print("Generated Invalid Competing Block " +
      str(len(merit.blockchain.blocks)) + ".")

result: Dict[str, Any] = {
    "blockchain": merit.toJSON(),
    "transactions": transactions.toJSON(),
    "removal": mr.toSignedJSON()
}
vectors: IO[Any] = open(
    "PythonTests/Vectors/Consensus/MeritRemoval/InvalidCompeting.json", "w")
vectors.write(json.dumps(result))
vectors.close()
예제 #4
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()
예제 #5
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.
예제 #6
0
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, 5)])),
    BlockBody([(pubKey, 5, consensus.getMerkle(pubKey, 0, 5))]))
#Mine it.
block.mine(blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Pending Actions Block " + str(block.header.nonce) + ".")

#Generate 4 more Blocks.
for i in range(3, 7):
    block = Block(BlockHeader(i, blockchain.last(), int(time())), BlockBody())
    #Mine it.
    block.mine(blockchain.difficulty())

    #Add it.
    blockchain.add(block)
    print("Generated Pending Actions Block " + str(block.header.nonce) + ".")

#Generate a Block with the MeritRemoval.
block = Block(
    BlockHeader(7, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 6, -1)])),
    BlockBody([(pubKey, 6, consensus.getMerkle(pubKey, 6))]))
#Mine it.
block.mine(blockchain.difficulty())

#Add it.
blockchain.add(block)
예제 #7
0
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#SpamFilter.
spamFilter: SpamFilter = SpamFilter(5)

#Blockchains.
e1Chain: Blockchain = Blockchain()
e2Chain: Blockchain = Blockchain()

#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)
예제 #8
0
#Claim the new Mint.
claim: Claim = Claim([merit.mints[0].hash], edPubKey.to_bytes())
claim.amount = merit.mints[0].output[1]
claim.sign([blsPrivKey])
claim.verified = True
transactions.add(claim)

#Verify the Claim..
verif = SignedVerification(claim.hash)
verif.sign(blsPrivKey, 1)
consensus.add(verif)

#Mine one more Block.
block = Block(
    BlockHeader(12, merit.blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey, 1, -1)])),
    BlockBody([(blsPubKey, 1, consensus.getMerkle(blsPubKey, 1))]))
block.mine(merit.blockchain.difficulty())
merit.add(transactions, consensus, block)
print("Generated Claimed Mint Block " + str(block.header.nonce) + ".")

result: Dict[str, Any] = {
    "blockchain": merit.blockchain.toJSON(),
    "transactions": transactions.toJSON(),
    "consensus": consensus.toJSON()
}
vectors: IO[Any] = open("PythonTests/Vectors/Transactions/ClaimedMint.json",
                        "w")
vectors.write(json.dumps(result))
vectors.close()