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( ): # 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