def post(tx, DB): address=addr(tx) adjust('amount', address, -tx['amount']-custom.fee, DB) adjust('count', address, 1, DB) post={'reputation':tx['amount'], 'msg':tx['msg'], 'parent':tx['parent'], 'children':[]} id_=postid(post) DB['posts'].append(id_) blockchain.db_put(id_, post, DB)
def adjust_amount(pubkey, amount, DB): try: acc=blockchain.db_get(pubkey, DB) except: blockchain.db_put(pubkey, {'amount': amount}, DB) return if 'amount' not in acc: acc['amount']=amount else: acc['amount']+=amount blockchain.db_put(pubkey, acc, DB)
def adjust_count(pubkey, DB, upward=True): try: acc=blockchain.db_get(pubkey, DB) except: blockchain.db_put(pubkey, {'count': 1}, DB) return if 'count' not in acc: acc['count']=0 if upward: acc['count']+=1 else: acc['count']-=1 blockchain.db_put(pubkey, acc, DB)
def adjust_amount(pubkey, amount, DB): try: acc = blockchain.db_get(pubkey, DB) except: blockchain.db_put(pubkey, {"amount": amount}, DB) return if "amount" not in acc: acc["amount"] = amount else: acc["amount"] += amount blockchain.db_put(pubkey, acc, DB)
def adjust_count(pubkey, DB, upward=True): try: acc = blockchain.db_get(pubkey, DB) except: blockchain.db_put(pubkey, {"count": 1}, DB) return if "count" not in acc: acc["count"] = 0 if upward: acc["count"] += 1 else: acc["count"] -= 1 blockchain.db_put(pubkey, acc, DB)
def post(tx, DB): address = addr(tx) adjust('amount', address, -tx['amount'] - custom.fee, DB) adjust('count', address, 1, DB) post = { 'reputation': tx['amount'], 'msg': tx['msg'], 'parent': tx['parent'], 'children': [] } id_ = postid(post) DB['posts'].append(id_) blockchain.db_put(id_, post, DB)
def adjust(key, pubkey, amount, DB): acc=blockchain.db_get(pubkey, DB) acc[key]+=amount blockchain.db_put(pubkey, acc, DB)
import consensus, listener, threading, custom, leveldb, gui, networking, time, sys, blockchain db = leveldb.LevelDB(custom.database_name) DB = { 'db': db, 'recentHash': 0, 'length': -1, 'sigLength': -1, 'txs': [], 'suggested_blocks': [], 'suggested_txs': [], 'posts': [], 'diffLength': '0' } blockchain.db_put('root', { 'msg': 'root', 'parent': 'root', 'children': [], 'reputation': 0 }, DB) todo = [ #keeps track of blockchain database, checks on peers for new #blocks and transactions. [consensus.miner, (custom.pubkey, custom.hashes_per_check, DB), True], [consensus.mainloop, (custom.peers, DB), True], #listens for peers. Peers might ask us for our blocks and our pool of recent #transactions, or peers could suggest blocks and transactions to us. [listener.server, (DB, ), True], [gui.main, (custom.gui_port, custom.brainwallet, DB), True] ] networking.kill_processes_using_ports( [str(custom.gui_port), str(custom.listen_port)]) for i in todo:
def adjust(key, pubkey, amount, DB, sign=1): acc = blockchain.db_get(pubkey, DB) if not DB['add_block']: sign = -1 acc[key] += amount * sign blockchain.db_put(pubkey, acc, DB)
def adjust(key, pubkey, amount, DB, sign=1): acc = blockchain.db_get(pubkey, DB) if not DB['add_block']: sign=-1 acc[key] += amount*sign blockchain.db_put(pubkey, acc, DB)
def adjust(key, pubkey, amount, DB): acc = blockchain.db_get(pubkey, DB) acc[key] += amount blockchain.db_put(pubkey, acc, DB)
import consensus, listener, threading, custom, leveldb, gui, networking, time, sys, blockchain db=leveldb.LevelDB(custom.database_name) DB={'db':db, 'recentHash':0, 'length':-1, 'sigLength':-1, 'txs':[], 'suggested_blocks':[], 'suggested_txs':[], 'posts':[], 'diffLength':'0'} blockchain.db_put('root', {'msg':'root', 'parent':'root', 'children':[], 'reputation':0}, DB) todo=[ #keeps track of blockchain database, checks on peers for new #blocks and transactions. [consensus.miner, (custom.pubkey, custom.hashes_per_check, DB), True], [consensus.mainloop, (custom.peers, DB), True], #listens for peers. Peers might ask us for our blocks and our pool of recent #transactions, or peers could suggest blocks and transactions to us. [listener.server, (DB, ), True], [gui.main, (custom.gui_port, custom.brainwallet, DB), True]] networking.kill_processes_using_ports([str(custom.gui_port), str(custom.listen_port)]) for i in todo: t = threading.Thread(target=i[0], args = i[1]) t.setDaemon(i[2]) t.start() while True: