def start( ): # wait : thread add_block(txs) txs = [] packing function >1MB or no tx verify if tx are valid couch = couchdb.Server("http://127.0.0.1:5984") try: couch.delete('block_chain') except: pass db = DB("http://127.0.0.1:5984") bc = BlockChain() # only one blockchain called bc utxo_set = UTXOSet() utxo_set.reindex(bc) tcpserver = TCPServer() tcpserver.listen() tcpserver.run() rpc = RPCServer(export_instance=Cli()) rpc.start(False) p2p = P2p() server = PeerServer() server.run(p2p) p2p.run() time.sleep(60) t1 = threading.Thread(target=finding_new_block, args=()) t1.start()
def client2(): f1 = open('u.txt', 'w') a = random.uniform(0, 1) if a > 0.95: f1.write('n') f1.close() return while True: try: f1.write('y') f1.close() f = open('address.txt', 'r') addrs = [] for line in f: addrs.append(line[:34]) f.close() fee = results() amount = 1 bc = BlockChain() tx = bc.new_transaction(addrs[0], addrs[1], amount, fee) tx_pool = TxPool() tx_pool.add(tx) break except: pass try: server = PeerServer() server.broadcast_tx(tx) except Exception as e: pass
def send(self, from_addr, to_addr, amount): # change bc = BlockChain() fee = random.uniform(0.1, 0.6) tx = bc.new_transaction(from_addr, to_addr, amount, fee) # change tx_pool = TxPool() tx_pool.add(tx) try: server = PeerServer() # broadcast to peers server.broadcast_tx(tx) # broadcast to peers # if tx_pool.is_full(): # change # bc.add_block(tx_pool.txs) # change # tx_pool.clear() # change except Exception as e: pass
def send(self, from_addr, to_addr, amount): bc = BlockChain() tx = bc.new_transaction(from_addr, to_addr, amount) # bc.add_block([tx]) tx_pool = TxPool() tx_pool.add(tx) try: server = PeerServer() server.broadcast_tx(tx) if tx_pool.is_full(): bc.add_block(tx_pool.txs) tx_pool.clear() except Exception as e: pass print('send %d from %s to %s' % (amount, from_addr, to_addr))
def start(): bc = BlockChain() utxo_set = UTXOSet() utxo_set.reindex(bc) tcpserver = TCPServer() tcpserver.listen() tcpserver.run() rpc = RPCServer(export_instance=Cli()) rpc.start(False) p2p = P2p() server = PeerServer() server.run(p2p) p2p.run()
def start( ): # wait : thread add_block(txs) txs = [] packing function >1MB or no tx verify if tx are valid couch = couchdb.Server("http://127.0.0.1:5984") try: couch.delete('block_chain') except: pass db = DB("http://127.0.0.1:5984") bc = BlockChain() # only one blockchain called bc utxo_set = UTXOSet() utxo_set.reindex(bc) tcpserver = TCPServer() tcpserver.listen() tcpserver.run() rpc = RPCServer(export_instance=Cli()) rpc.start(False) p2p = P2p() server = PeerServer() server.run(p2p) p2p.run() time.sleep(30) # automatically create a genesis block w1 = Wallet.generate_wallet() ws = Wallets() ws[w1.address] = w1 ws.save() tx = bc.coin_base_tx(w1.address) bc.new_genesis_block(tx) fo = open("address.txt", "w") fo.truncate() fo.write(w1.address) # save the address of the genesis block fo.write("\n") w2 = Wallet.generate_wallet() # create another wallet to send transaction ws[w2.address] = w2 ws.save() fo.write(w2.address) fo.close()
def start( ): # wait : thread add_block(txs) txs = [] packing function >1MB or no tx verify if tx are valid couch = couchdb.Server("http://127.0.0.1:5984") try: couch.delete('block_chain') except: pass env_dist = os.environ db_url1 = "http://couchdb" db_url1 += env_dist.get('DB_URL') db_url1 += ":5984" db = DB(db_url1) bc = BlockChain() # only one blockchain called bc utxo_set = UTXOSet() utxo_set.reindex(bc) try: f = open('address.txt', 'r') addrs = [] for line in f: addrs.append(line[:34]) f.close() tx = bc.coin_base_tx(addrs[0]) bc.new_genesis_block(tx) except: pass tcpserver = TCPServer() tcpserver.listen() tcpserver.run() rpc = RPCServer(export_instance=Cli()) rpc.start(False) t2 = threading.Thread(target=client2, args=()) t2.start() p2p = P2p() server = PeerServer() server.run(p2p) p2p.run()
def start( ): # wait : thread add_block(txs) txs = [] packing function >1MB or no tx verify if tx are valid couch = couchdb.Server("http://127.0.0.1:5984") try: couch.delete('block_chain') except: pass db = DB("http://127.0.0.1:5984") bc = BlockChain() # only one blockchain called bc utxo_set = UTXOSet() utxo_set.reindex(bc) tcpserver = TCPServer() tcpserver.listen() tcpserver.run() rpc = RPCServer(export_instance=Cli()) rpc.start(False) p2p = P2p() server = PeerServer() server.run(p2p) p2p.run() time.sleep(40) fo = open("address.txt", "r") addrs = [] for line in fo: addrs.append(line) fo.close() fee = random.uniform(0.1, 0.6) amount = 1 tx = bc.new_transaction(addrs[0], addrs[1], amount, fee) # change tx_pool = TxPool() tx_pool.add(tx) try: server = PeerServer() server.broadcast_tx(tx) except Exception as e: pass