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")
|
logger.warn("Peer " + i + " returned malformed hash")
|
||||||
blockList = blocks.split('\n')
|
blockList = blocks.split('\n')
|
||||||
for i in blockList:
|
for i in blockList:
|
||||||
|
logger.debug('Exchanged block (blockList): ' + i)
|
||||||
if not self._utils.validateHash(i):
|
if not self._utils.validateHash(i):
|
||||||
# skip hash if it isn't valid
|
# skip hash if it isn't valid
|
||||||
logger.warn('Hash ' + i + ' is not valid')
|
logger.warn('Hash ' + i + ' is not valid')
|
||||||
|
|
|
@ -130,15 +130,19 @@ class Core:
|
||||||
''')
|
''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
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)'''
|
'''add a hash value to the block db (should be in hex format)'''
|
||||||
if not os.path.exists(self.blockDB):
|
if not os.path.exists(self.blockDB):
|
||||||
raise Exception('Block db does not exist')
|
raise Exception('Block db does not exist')
|
||||||
conn = sqlite3.connect(self.blockDB)
|
conn = sqlite3.connect(self.blockDB)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
currentTime = math.floor(time.time())
|
currentTime = math.floor(time.time())
|
||||||
data = (newHash, currentTime, 0, 0)
|
if selfInsert:
|
||||||
c.execute('INSERT into hashes values(?, ?, ?, ?);', data)
|
selfInsert = 1
|
||||||
|
else:
|
||||||
|
selfInsert = 0
|
||||||
|
data = (newHash, currentTime, 0, 0, selfInsert)
|
||||||
|
c.execute('INSERT into hashes values(?, ?, ?, ?, ?);', data)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,8 @@ class Onionr:
|
||||||
messageToAdd = input('Broadcast message to network: ')
|
messageToAdd = input('Broadcast message to network: ')
|
||||||
if len(messageToAdd) >= 1:
|
if len(messageToAdd) >= 1:
|
||||||
break
|
break
|
||||||
self.onionrCore.setData(messageToAdd)
|
addedHash = self.onionrCore.setData(messageToAdd)
|
||||||
|
self.onionrCore.addToBlockDB(addedHash, selfInsert=True)
|
||||||
elif command == 'stats':
|
elif command == 'stats':
|
||||||
self.showStats()
|
self.showStats()
|
||||||
elif command == 'help' or command == '--help':
|
elif command == 'help' or command == '--help':
|
||||||
|
|
Loading…
Reference in New Issue