Onionr/onionr/onionrstorage/removeblock.py

23 lines
757 B
Python
Raw Permalink Normal View History

2019-06-22 22:54:41 +00:00
import sys, sqlite3
import onionrexceptions, onionrstorage
from onionrutils import stringvalidators
2019-07-19 19:49:56 +00:00
from coredb import dbfiles
import storagecounter
def remove_block(block):
2019-06-22 22:54:41 +00:00
'''
remove a block from this node (does not automatically blacklist)
**You may want blacklist.addToDB(blockHash)
'''
if stringvalidators.validate_hash(block):
2019-07-28 05:33:26 +00:00
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=30)
2019-06-22 22:54:41 +00:00
c = conn.cursor()
t = (block,)
c.execute('Delete from hashes where hash=?;', t)
conn.commit()
conn.close()
2019-07-19 19:49:56 +00:00
dataSize = sys.getsizeof(onionrstorage.getData(block))
storagecounter.StorageCounter().remove_bytes(dataSize)
2019-06-22 22:54:41 +00:00
else:
raise onionrexceptions.InvalidHexHash