fixed addToBlockDB and added selfInsert flag, addmessage command
parent
da6729adc9
commit
963fab821b
|
@ -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')
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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':
|
||||
|
|
Loading…
Reference in New Issue