Refactor code
parent
a5dbf73df4
commit
0dc6a0b6c5
|
@ -556,13 +556,11 @@ class Onionr:
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_hostname(self):
|
def get_hostname(self):
|
||||||
retVal = ''
|
|
||||||
try:
|
try:
|
||||||
with open('./data/hs/hostname', 'r') as hostname:
|
with open('./data/hs/hostname', 'r') as hostname:
|
||||||
retVal = hostname.read()
|
return hostname.read().strip()
|
||||||
except FileNotFoundError:
|
except Exception:
|
||||||
retVal = None
|
return None
|
||||||
return retVal
|
|
||||||
|
|
||||||
def addFile(self):
|
def addFile(self):
|
||||||
'''command to add a file to the onionr network'''
|
'''command to add a file to the onionr network'''
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger
|
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger
|
||||||
import btc
|
import btc
|
||||||
|
|
||||||
class POW:
|
class POW:
|
||||||
def pow(self, reporting = False):
|
def pow(self, reporting = False):
|
||||||
startTime = math.floor(time.time())
|
startTime = math.floor(time.time())
|
||||||
|
@ -77,7 +79,9 @@ class POW:
|
||||||
self.difficulty = newDiff
|
self.difficulty = newDiff
|
||||||
|
|
||||||
def getResult(self):
|
def getResult(self):
|
||||||
'''Returns the result then sets to false, useful to automatically clear the result'''
|
'''
|
||||||
|
Returns the result then sets to false, useful to automatically clear the result
|
||||||
|
'''
|
||||||
try:
|
try:
|
||||||
retVal = self.result
|
retVal = self.result
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
|
@ -120,14 +120,11 @@ class OnionrUtils:
|
||||||
|
|
||||||
def getMyAddress(self):
|
def getMyAddress(self):
|
||||||
try:
|
try:
|
||||||
myAddressFile = open("data/hs/hostname", 'r')
|
with open('./data/hs/hostname', 'r') as hostname:
|
||||||
myAddress = myAddressFile.read()
|
return hostname.read().strip()
|
||||||
myAddressFile.close()
|
|
||||||
|
|
||||||
return myAddress.strip()
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error('Failed to read my address.', error=error)
|
logger.error('Failed to read my address.', error=error)
|
||||||
return ''
|
return None
|
||||||
|
|
||||||
def localCommand(self, command, silent = True):
|
def localCommand(self, command, silent = True):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue