예제 #1
0
 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])
예제 #2
0
파일: app.py 프로젝트: bsemilie/BlockChain
    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])
예제 #3
0
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)
import json

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.head

print("First block: ")
print(first_block)

blockchain.add_transaction(address, "colas", 10)
blockchain.add_transaction(address, "salim", 30)
blockchain.mine_block()

print("blockchain: ")
print(json.dumps(blockchain.to_dict(), indent=2))
second_block = blockchain.head

print("Second block: ")
print(second_block)