コード例 #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)
コード例 #4
0
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)