def mine(): global blockchain if blockchain == None: blockchain = Blockchain(difficulty) blockchain.create_genesis_block() return "Blockchain created \n", 200 else: blockchain.mine_block() return "Block mined\n", 200
def mine_call(self): # need to call the mining function global blockchain if not blockchain: blockchain = Blockchain(difficulty) blockchain.create_genesis_block(wallet) else: blockchain.mine_block(wallet) print(blockchain.tokens) self.define_block(blockchain.blocks[-1]) data = blockchain.to_dict() dataJson = json.dumps(data).encode() socket.send_multipart([b'chain', dataJson])
def mine_call(self): global blockchain if not blockchain: blockchain = Blockchain(difficulty) blockchain.create_genesis_block(wallet) else: blockchain.mine_block(wallet) self.define_block(blockchain.chain[-1]) chain = blockchain.to_dict() chain_data = json.dumps({ "length": len(chain), "chain": chain }).encode() socket.send_multipart([b'chain', chain_data])
from chain import Blockchain from key import BitcoinAccount wallet = BitcoinAccount() address = wallet.to_address() difficulty = 4 blockchain = Blockchain(difficulty) blockchain.create_genesis_block() print("blockchain: ") print(blockchain.to_dict()) first_block = blockchain.blocks_list[-1] print("First block: ") print(first_block) blockchain.add_transaction(address, "colas", 10) blockchain.add_transaction(address, "salim", 30) blockchain.mine_block() print("blockchain: ") print(blockchain.to_dict()) second_block = blockchain.blocks_list[-1] print("Second block: ") print(second_block)