Ejemplo n.º 1
0
    def __init__(
        self,
        genesis: bytes,
        blockTime: int,
        startDifficulty: int
    ) -> None:
        self.blockTime: int = blockTime

        self.startDifficulty: int = startDifficulty
        self.maxDifficulty: int = (2 ** 384) - 1
        self.difficulty: int = startDifficulty
        self.difficultyUntil: int = 1

        self.blocks: List[Block] = [
            Block(
                BlockHeader(
                    0,
                    genesis.rjust(48, b'\0'),
                    0
                ),
                BlockBody(
                    miners = []
                )
            )
        ]
Ejemplo n.º 2
0
    verifs[-1].sign(privKey, d)
    if d < 3:
        consensus.add(verifs[-1])

#Create a MeritRemoval off the last one.
sv: SignedVerification = SignedVerification(b'\0' * 48)
sv.sign(privKey, 5)
removal: SignedMeritRemoval = SignedMeritRemoval(
    SignedElement.fromElement(verifs[5]), SignedElement.fromElement(sv))
consensus.add(removal)

#Generate a Block with the first 3 Elements.
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, 2)])),
    BlockBody([(pubKey, 2, consensus.getMerkle(pubKey, 0, 2))]))
#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(3, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 3, -1)])),
    BlockBody([(pubKey, 3, consensus.getMerkle(pubKey, 3))]))
#Mine it.
block.mine(blockchain.difficulty)
Ejemplo n.º 3
0
#Generate another 6 Blocks.
#Next block should have a record.
block: Block = Block(
    BlockHeader(
        14,
        merit.blockchain.last(),
        int(time()),
        consensus.getAggregate(
            [(blsPubKey, 0, -1)]
        )
    ),
    BlockBody([
        (
            blsPubKey,
            0,
            consensus.getMerkle(
                blsPubKey,
                0
            )
        )
    ])
)
for i in range(15, 21):
    #Mine it.
    block.mine(merit.blockchain.difficulty)

    #Add it.
    merit.add(transactions, consensus, block)
    print("Generated Claimed Mint Block " + str(block.header.nonce) + ".")

    #Create the next Block.
    block = Block(
Ejemplo n.º 4
0
from python_tests.Classes.Merit.Block import Block
from python_tests.Classes.Merit.Blockchain import Blockchain

#Time standard function.
from time import time

#JSON standard lib.
import json

#Blockchain.
blockchain: Blockchain = Blockchain(
    b"MEROS_DEVELOPER_NETWORK", 60,
    int(
        "FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        16))

#Generate blocks.
for i in range(1, 26):
    #Create the Block.
    block: Block = Block(BlockHeader(i, blockchain.last(), int(time())),
                         BlockBody())
    block.mine(blockchain.difficulty)

    #Add it locally.
    blockchain.add(block)
    print("Generated Blank Block " + str(i) + ".")

vectors: IO[Any] = open("python_tests/Vectors/Merit/BlankBlocks.json", "w")
vectors.write(json.dumps(blockchain.toJSON()))
vectors.close()
Ejemplo n.º 5
0
    sends.append(
        Send([(sends[-1].hash, 0)],
             [(edPubKey.to_bytes(), sends[-1].outputs[0][1])]))

#Verify 0 and 1 in order.
order: List[int] = [0, 1]
verif: SignedVerification
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block: Block = Block(
    BlockHeader(21, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 2, -1)])),
    BlockBody([(blsPubKey1, 3, consensus.getMerkle(blsPubKey1, 2))]))
block.mine(blockchain.difficulty)
blockchain.add(block)
print("Generated Fifty Block " + str(block.header.nonce) + ".")

#Verify 3, and then 2, while giving Merit to a second Merit Holder.
order = [3, 2]
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block = Block(
    BlockHeader(22, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 4, -1)])),
    BlockBody([(blsPubKey1, 5, consensus.getMerkle(blsPubKey1, 4))],
Ejemplo n.º 6
0
 def fromJSON(json: Dict[str, Any]) -> Any:
     return Block(BlockHeader.fromJSON(json["header"]),
                  BlockBody.fromJSON(json))
Ejemplo n.º 7
0
#Create two Verifications with the same nonce, yet for the different Datas.
sv1: SignedVerification = SignedVerification(data.hash)
sv1.sign(privKey, 0)

sv2: SignedVerification = SignedVerification(b'\0' * 48)
sv2.sign(privKey, 0)

removal: SignedMeritRemoval = SignedMeritRemoval(
    SignedElement.fromElement(sv1), SignedElement.fromElement(sv2))
consensus.add(removal)

#Generate another Block.
block: Block = Block(
    BlockHeader(2, blockchain.last(), int(time()),
                consensus.getAggregate([(pubKey, 0, -1)])),
    BlockBody([(pubKey, 0, consensus.getMerkle(pubKey, 0))]))
#Mine it.
block.mine(blockchain.difficulty)

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

result: Dict[str, Any] = {
    "blockchain": blockchain.toJSON(),
    "data": data.toJSON(),
    "removal": removal.toSignedJSON()
}
vectors: IO[Any] = open(
    "python_tests/Vectors/Consensus/MeritRemoval/SameNonce.json", "w")
vectors.write(json.dumps(result))
Ejemplo n.º 8
0
 def blockBody(self, body: BlockBody) -> bytes:
     res: bytes = (MessageType.BlockBody.toByte() + body.serialize())
     self.send(res)
     return res