2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-26 05:26:50 +00:00
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
This module works with information relating to blocks stored on the node
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
from etc import onionrvalues
|
|
|
|
from . import expiredblocks, updateblockinfo, add
|
|
|
|
from .. import dbfiles
|
|
|
|
"""
|
2019-06-26 05:26:50 +00:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-10-29 05:36:56 +00:00
|
|
|
|
2019-07-20 21:21:03 +00:00
|
|
|
update_block_info = updateblockinfo.update_block_info
|
2019-07-24 17:22:19 +00:00
|
|
|
add_to_block_DB = add.add_to_block_DB
|
2020-01-07 11:44:53 +00:00
|
|
|
|
|
|
|
|
2019-07-17 16:25:29 +00:00
|
|
|
def get_block_list(dateRec = None, unsaved = False):
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
Get list of our blocks
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
if dateRec == None:
|
|
|
|
dateRec = 0
|
|
|
|
|
2019-10-29 05:36:56 +00:00
|
|
|
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
|
2019-06-22 21:16:12 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
execute = 'SELECT hash FROM hashes WHERE dateReceived >= ? ORDER BY dateReceived ASC;'
|
|
|
|
args = (dateRec,)
|
|
|
|
rows = list()
|
|
|
|
for row in c.execute(execute, args):
|
|
|
|
for i in row:
|
|
|
|
rows.append(i)
|
|
|
|
conn.close()
|
|
|
|
return rows
|
|
|
|
|
2020-01-07 11:44:53 +00:00
|
|
|
|
2019-07-17 16:25:29 +00:00
|
|
|
def get_block_date(blockHash):
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
Returns the date a block was received
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
|
2019-10-29 05:36:56 +00:00
|
|
|
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
|
2019-06-22 21:16:12 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
execute = 'SELECT dateReceived FROM hashes WHERE hash=?;'
|
|
|
|
args = (blockHash,)
|
|
|
|
for row in c.execute(execute, args):
|
|
|
|
for i in row:
|
|
|
|
return int(i)
|
|
|
|
conn.close()
|
|
|
|
return None
|
|
|
|
|
2020-01-07 11:44:53 +00:00
|
|
|
|
2019-07-17 16:25:29 +00:00
|
|
|
def get_blocks_by_type(blockType, orderDate=True):
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
Returns a list of blocks by the type
|
2020-01-07 11:44:53 +00:00
|
|
|
"""
|
2019-06-22 21:16:12 +00:00
|
|
|
|
2019-10-29 05:36:56 +00:00
|
|
|
conn = sqlite3.connect(dbfiles.block_meta_db, timeout=onionrvalues.DATABASE_LOCK_TIMEOUT)
|
2019-06-22 21:16:12 +00:00
|
|
|
c = conn.cursor()
|
|
|
|
|
|
|
|
if orderDate:
|
|
|
|
execute = 'SELECT hash FROM hashes WHERE dataType=? ORDER BY dateReceived;'
|
|
|
|
else:
|
|
|
|
execute = 'SELECT hash FROM hashes WHERE dataType=?;'
|
|
|
|
|
|
|
|
args = (blockType,)
|
|
|
|
rows = list()
|
|
|
|
|
|
|
|
for row in c.execute(execute, args):
|
|
|
|
for i in row:
|
|
|
|
rows.append(i)
|
|
|
|
conn.close()
|
2020-01-07 11:44:53 +00:00
|
|
|
return rows
|
|
|
|
|