def delete_block(DB): """ Removes the most recent block from the blockchain. """ if DB['length'] < 0: return try: targets.pop(str(DB['length'])) except: pass try: times.pop(str(DB['length'])) except: pass block = tools.db_get(DB['length'], DB) orphans = copy.deepcopy(DB['txs']) DB['txs'] = [] for tx in block['txs']: orphans.append(tx) DB['add_block'] = False transactions.update[tx['type']](tx, DB) tools.db_delete(DB['length'], DB) DB['length'] -= 1 if DB['length'] == -1: DB['diffLength'] = '0' else: block = tools.db_get(DB['length'], DB) DB['diffLength'] = block['diffLength'] for orphan in sorted(orphans, key=lambda x: x['count']): add_tx(orphan, DB)
def delete_block(DB): """ Removes the most recent block from the blockchain. """ length=tools.db_get('length') if length < 0: return try: ts=tools.db_get('targets') ts.pop(str(length)) tools.db_put('targets', ts) except: pass try: ts=tools.db_get('times') ts.pop(str(length)) tools.db_put('times', ts) except: pass block = tools.db_get(length, DB) orphans = tools.db_get('txs') tools.db_put('txs', []) for tx in block['txs']: orphans.append(tx) tools.db_put('add_block', False) transactions.update[tx['type']](tx, DB, False) tools.db_delete(length, DB) length-=1 tools.db_put('length', length) if length == -1: tools.db_put('diffLength', '0') else: block = tools.db_get(length, DB) tools.db_put('diffLength', block['diffLength']) for orphan in sorted(orphans, key=lambda x: x['count']): add_tx(orphan, DB)
def delete_block(DB): """ Removes the most recent block from the blockchain. """ length = tools.db_get('length') if length < 0: return try: ts = tools.db_get('targets') ts.pop(str(length)) tools.db_put('targets', ts) except: pass try: ts = tools.db_get('times') ts.pop(str(length)) tools.db_put('times', ts) except: pass block = tools.db_get(length, DB) orphans = tools.db_get('txs') tools.db_put('txs', []) for tx in block['txs']: orphans.append(tx) tools.db_put('add_block', False) transactions.update[tx['type']](tx, DB, False) tools.db_delete(length, DB) length -= 1 tools.db_put('length', length) if length == -1: tools.db_put('diffLength', '0') else: block = tools.db_get(length, DB) tools.db_put('diffLength', block['diffLength']) for orphan in sorted(orphans, key=lambda x: x['count']): add_tx(orphan, DB)
def delete_block(DB): """ Removes the most recent block from the blockchain. """ length=tools.local_get('length') if length < 0: return try: ts=tools.local_get('targets') ts.pop(str(length)) tools.local_put('targets', ts) except: pass try: ts=tools.local_get('times') ts.pop(str(length)) tools.local_put('times', ts) except: pass block = tools.db_get(length, DB) orphans = tools.local_get('txs') orphans=filter(lambda t: t['type']!='mint', orphans) tools.local_put('txs', []) for tx in block['txs']: orphans.append(tx) tools.local_put('add_block', False) transactions.update[tx['type']](tx, DB, False) tools.db_delete(length, DB) length-=1 tools.local_put('length', length) if length>=0: block=tools.db_get(length) tools.local_put('height', filter(lambda t: t['type']=='mint', block['txs'])[0]['height']) else: tools.local_put('height', -1) for orphan in orphans: add_tx(orphan, DB)
def delete_block(DB): """ Removes the most recent block from the blockchain. """ if DB['length'] < 0: return try: targets.pop(str(DB['length'])) except: pass try: times.pop(str(DB['length'])) except: pass block = tools.db_get(DB['length'], DB) orphans = copy.deepcopy(DB['txs']) DB['txs'] = [] for tx in block['txs']: orphans.append(tx) DB['add_block']=False transactions.update[tx['type']](tx, DB) tools.db_delete(DB['length'], DB) DB['length'] -= 1 if DB['length'] == -1: DB['diffLength'] = '0' else: block = tools.db_get(DB['length'], DB) DB['diffLength'] = block['diffLength'] for orphan in sorted(orphans, key=lambda x: x['count']): add_tx(orphan, DB)
def symmetric_put(id_, dic, DB, add_block): if add_block: tools.db_put(id_, dic, DB) else: tools.db_delete(id_, DB)
def symmetric_put(id_, dic, DB): if DB['add_block']: tools.db_put(id_, dic, DB) else: tools.db_delete(id_, DB)