Example #1
0
def print_chain(bc):
    for block in bc.blocks:
        print("Prev. hash: {0}".format(block.prev_block_hash))
        print("Data: {0}".format(block.data))
        print("Hash: {0}".format(block.hash))
        pow = Pow(block)
        print("PoW: {0}".format(pow.validate()))
Example #2
0
def print_chain(bc):
    for block in bc.blocks:
        print("Prev. hash: {0}".format(block.prev_block_hash))
        print("Data: {0}".format(block.data))
        print("Hash: {0}".format(block.hash))
        pow = Pow(block)
        print("PoW: {0}".format(pow.validate()))
Example #3
0
def print_chain():
    bc = Blockchain()

    for block in bc.blocks:
        print("Prev. hash: {0}".format(block.prev_block_hash))
        print("Hash: {0}".format(block.hash))
        pow = Pow(block)
        print("PoW: {0}".format(pow.validate()))
Example #4
0
def print_block(bc, height):
    block = bc.blocks[height - 1]
    print("Prev hash: %s" % (block.prev_block_hash))
    #print("Data: %s" % (block.data))
    print("Hash: %s" % (block.hash))
    pw = Pow(block)
    print("Transactions: %s" % block.transactions[0])
    print("PoW: %s" % (pw.validate()))
Example #5
0
def print_chain(bc):
    for block in bc.blocks:
        print("Prev hash: %s" % (block.prev_block_hash))
        #print("Data: %s" % (block.data))
        print("Hash: %s" % (block.hash))
        pw = Pow(block)
        print("Transactions: %s" % block.transactions[0])
        print("PoW: %s" % (pw.validate()))
Example #6
0
def print_block(height):
    bc = Blockchain()

    for block in bc.blocks:
        if (block.height == height):
            print("Prev. hash: {0}".format(block.prev_block_hash))
            print("Hash: {0}".format(block.hash))
            print("Height: {0}".format(block.height))
            pow = Pow(block)
            print("PoW: {0}".format(pow.validate()))
            break
Example #7
0
 def pow_of_block(self):
     # Makes the proof of work of the current Block
     pow = Pow(self)
     nonce, hash = pow.run()
     self._nonce, self._hash = nonce, utils.encode(hash)
     return self
Example #8
0
from blockchain import Blockchain
from pow import Pow

if __name__ == '__main__':
    bc = Blockchain()
    bc.add_block("Send 1 BTC to Ivan")
    bc.add_block("Send 2 more BTC to Ivan")

    for block in bc.blocks:
        print("Prev. hash: {0}".format(block.prev_block_hash))
        print("Data: {0}".format(block.data))
        print("Hash: {0}".format(block.hash))
        pow = Pow(block)
        print("PoW: {0}".format(pow.validate()))
Example #9
0
 def pow_of_block(self):
     pow_worker = Pow(self)
     self.nonce, self.hash = pow_worker.run()
     return self
Example #10
0
 def pow_of_block(self):
     pw = Pow(self)
     self._nonce, self._hash = pw.mine()
     self._hash = encode(self._hash)
     return self
Example #11
0
 def pow_of_block(self):
     pow = Pow(self)
     nonce, hash = pow.run()
     self._nonce, self._hash = nonce, utils.encode(hash)
     return self
Example #12
0
 def set_hash(self):
   pow = Pow(self)
   self._nonce, self._hash = pow.run()
   while not pow.validate():
     random.shuffle(self._transaction)
     self._nonce, self._hash = pow.run()
Example #13
0
from blockchain import Blockchain
from pow import Pow
import pickle

if __name__ == '__main__':
    try:
        f = open("../blocks/blockchain.pkl", "rb")
        bc = pickle.load(f)
        f.close()
        print("loaded data")
        bc.add_block("block %s" % str(len(bc.blocks)))
    except:
        bc = Blockchain(12)
        bc.add_block("block 1")
        bc.add_block("block 2")

    for block in bc.blocks:
        print("Prev hash: %s" % (block.prev_block_hash))
        print("Data: %s" % (block.data))
        print("Hash: %s" % (block.hash))
        pw = Pow(block)
        print("PoW: %s" % (pw.validate()))
    f = open("../blocks/blockchain.pkl", "wb+")
    pickle.dump(bc, f)
    f.close()
Example #14
0
 def pow_of_block(self):
     # Makes the proof of work of the current Block
     pow = Pow(self)
     nonce, hash = pow.run()
     self._nonce, self._hash = nonce, utils.encode(hash)
     return self