fixed addToBlockDB and added selfInsert flag, addmessage command

This commit is contained in:
Kevin Froman 2018-01-27 20:18:38 -06:00
parent da6729adc9
commit 963fab821b
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 10 additions and 4 deletions

View File

@ -106,6 +106,7 @@ class OnionrCommunicate:
logger.warn("Peer " + i + " returned malformed hash")
blockList = blocks.split('\n')
for i in blockList:
logger.debug('Exchanged block (blockList): ' + i)
if not self._utils.validateHash(i):
# skip hash if it isn't valid
logger.warn('Hash ' + i + ' is not valid')

View File

@ -130,15 +130,19 @@ class Core:
''')
conn.commit()
conn.close()
def addToBlockDB(self, newHash):
def addToBlockDB(self, newHash, selfInsert=False):
'''add a hash value to the block db (should be in hex format)'''
if not os.path.exists(self.blockDB):
raise Exception('Block db does not exist')
conn = sqlite3.connect(self.blockDB)
c = conn.cursor()
currentTime = math.floor(time.time())
data = (newHash, currentTime, 0, 0)
c.execute('INSERT into hashes values(?, ?, ?, ?);', data)
if selfInsert:
selfInsert = 1
else:
selfInsert = 0
data = (newHash, currentTime, 0, 0, selfInsert)
c.execute('INSERT into hashes values(?, ?, ?, ?, ?);', data)
conn.commit()
conn.close()

View File

@ -114,7 +114,8 @@ class Onionr:
messageToAdd = input('Broadcast message to network: ')
if len(messageToAdd) >= 1:
break
self.onionrCore.setData(messageToAdd)
addedHash = self.onionrCore.setData(messageToAdd)
self.onionrCore.addToBlockDB(addedHash, selfInsert=True)
elif command == 'stats':
self.showStats()
elif command == 'help' or command == '--help':