Onionr/onionr/onionrstorage/removeblock.py
2019-07-28 00:33:26 -05:00

23 lines
756 B
Python

import sys, sqlite3
import onionrexceptions, onionrstorage
from onionrutils import stringvalidators
from coredb import dbfiles
import storagecounter
def remove_block(block):
'''
remove a block from this node (does not automatically blacklist)
**You may want blacklist.addToDB(blockHash)
'''
if stringvalidators.validate_hash(block):
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
c = conn.cursor()
t = (block,)
c.execute('Delete from hashes where hash=?;', t)
conn.commit()
conn.close()
dataSize = sys.getsizeof(onionrstorage.getData(block))
storagecounter.StorageCounter().removeBytes(dataSize)
else:
raise onionrexceptions.InvalidHexHash