Example #1
0
def PoW(TxBlockFile, ChainFile, PoWLen,
        TxLen):  #Updates LongestChain File for Each Block
    block = ""
    if TxBlockFile[-5] != "0":
        chainBuffer = open(ChainFile, "r")
        chain = chainBuffer.readlines()
        chainBuffer.close()
        block = chain[-1]  #PoW for the Previous Transaction Block
    else:  #for TransactionBlock0.txt
        block = "Day Zero Link in the Chain" + "\n"

    block += rootMerkle(TxBlockFile,
                        TxLen) + "\n"  #The Root Hash of the Merkle Tree

    while True:
        new_block = block + str(DSA.bitGenerator(2**128 - 1)) + "\n"
        new_PoW = hashlib.sha3_256(new_block).hexdigest()
        if new_PoW[:PoWLen] == "0" * PoWLen:
            new_PoW += "\n"  #PoW
            block = new_block
            block += new_PoW
            break
    #Write/append to the ChainFile
    if TxBlockFile[-5] != "0":
        chainBuffer = open(ChainFile, "a")
        chainBuffer.write(block)
        chainBuffer.close()
    else:  #for TransactionBlock0.txt
        chainBuffer = open(ChainFile, "w")
        chainBuffer.write(block)
        chainBuffer.close()
Example #2
0
def BeforeSign(p, q, g, payer_b, payee_b): #The Lines of the Transaction to be Signed
    transaction = \
    "*** Bitcoin transaction ***" + "\n" + \
    "Serial number: " + str(DSA.bitGenerator(2**128-1)) + "\n" + \
    "p: " + str(p) + "\n" + \
    "q: " + str(q) + "\n" + \
    "g: " + str(g) + "\n" + \
    "Payer Public Key (beta): " + str(payer_b) + "\n" + \
    "Payee Public Key (beta): " + str(payee_b) + "\n" + \
    "Amount: " + satoshi() + " Satoshi" + "\n"
    return transaction
def nineLine(p, q, g, beta): # First nine lines of single transaction.
    transaction = \
    "*** Bitcoin transaction ***" + "\n" + \
    "Serial number: " + str(DSA.bitGenerator(2**128-1)) + "\n" + \
    "Payer: " + payee() + "\n" + \
    "Payee: " + payee() + "\n" + \
    "Amount: " + satoshi() + " Satoshi" + "\n" + \
    "p: " + str(p) + "\n" + \
    "q: " + str(q) + "\n" + \
    "g: " + str(g) + "\n" + \
    "Public Key (beta): " + str(beta) + "\n"

    return transaction