Exemplo n.º 1
0
 def handler(self, c, a):
     while True:
         try:
             data = c.recv(1024)
         # Catch error when client disconnected then remove that client connection
         except Exception as error:
             print(str(a[0]) + ':' + str(a[1]) + " disconnected")
             self.connections.remove(c)
             c.close()
             break
         #create new block data when msg recieved
         block = BlockChain.Block(data.decode('utf-8'))
         blockchain.mine(block)
         # Send new block data to all Clients
         for connection in self.connections:
             connection.send(bytes(str(block.data), 'utf-8'))
         # Disconnect client when they close program
         if not data:
             print(str(a[0]) + ':' + str(a[1]) + " disconnected")
             self.connections.remove(c)
             c.close()
             break
Exemplo n.º 2
0
import FunctionNetwork as Net
import BlockChain
import Wallet
from pycoin import merkle
bc = BlockChain.BlockChain()
#bc.add_block(BlockChain.Block("0",1,0,0))
w = Wallet.Wallet()
w.create_identity("ale", "nardo", "95042429425", "24/4/1995", "m")
b = BlockChain.Block("0", merkle.merkle([w.my_identity.get_hash()]), "0", "0")
b.set_identities([w.my_identity])
bc.add_block(b)

bc.add_block(BlockChain.Block(bc.tip.get_hash(), 1, 0, 0))
a = Net.node(blockChain=bc, ip="127.0.0.1", port=Net.PORT, is_seed=1)