2019-06-26 05:26:50 +00:00
|
|
|
'''
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
Update block information in the metadata database by a field name
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
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/>.
|
|
|
|
'''
|
2019-06-22 21:16:12 +00:00
|
|
|
import sqlite3
|
2019-07-17 16:58:40 +00:00
|
|
|
from .. import dbfiles
|
2019-10-29 05:36:56 +00:00
|
|
|
from etc import onionrvalues
|
2019-07-17 16:58:40 +00:00
|
|
|
def update_block_info(hash, key, data):
|
|
|
|
'''
|
|
|
|
sets info associated with a block
|
|
|
|
|
|
|
|
hash - the hash of a block
|
|
|
|
dateReceived - the date the block was recieved, not necessarily when it was created
|
|
|
|
decrypted - if we can successfully decrypt the block (does not describe its current state)
|
|
|
|
dataType - data type of the block
|
|
|
|
dataFound - if the data has been found for the block
|
|
|
|
dataSaved - if the data has been saved for the block
|
|
|
|
sig - optional signature by the author (not optional if author is specified)
|
|
|
|
author - multi-round partial sha3-256 hash of authors public key
|
|
|
|
dateClaimed - timestamp claimed inside the block, only as trustworthy as the block author is
|
|
|
|
expire - expire date for a block
|
|
|
|
'''
|
2020-02-24 10:45:29 +00:00
|
|
|
if key not in ('dateReceived', 'decrypted', 'dataType', 'dataFound',
|
2019-09-09 00:21:36 +00:00
|
|
|
'dataSaved', 'sig', 'author', 'dateClaimed', 'expire'):
|
|
|
|
raise ValueError('Key must be in the allowed list')
|
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()
|
|
|
|
args = (data, hash)
|
2020-02-24 10:45:29 +00:00
|
|
|
# Unfortunately, not really possible to prepare this statement
|
2019-06-22 21:16:12 +00:00
|
|
|
c.execute("UPDATE hashes SET " + key + " = ? where hash = ?;", args)
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
|
|
|
|
|
|
|
return True
|