def view(key): if Config.getBoolValue('TIME_IT_ENABLED'): message = "{0} => {1}s".format(key, TimeIt.timings[key]) if Config.getBoolValue('TIME_IT_CONSOLE'): print(message) if Config.getBoolValue('TIME_IT_FILE'): Log.debug(message)
def onSuccess(self, callback = None): isMiningSupported = Config.getBoolValue("MINING_SUPPORTED") if isMiningSupported: account = Accounts.getAccountByAddress(self.address) if account != None: if not self.chain.exitsMiningWorker(account): self.chain.addMiningWorker(account, self.enabled) callback( JSONRPC.createResultObject('added mining worker', self.id) ) else: if self.enabled: callback( JSONRPC.createResultObject('worker is mining', self.id) ) else: self.chain.stopMiningWorker(account) callback( JSONRPC.createResultObject('worker is stopped mining', self.id) ) else: callback( JSONRPC.createErrorObject(-32005, 'not found', 'account not found', self.id) ) else: callback( JSONRPC.createErrorObject(-32006, 'not supported', 'node does not support mining', self.id) )
def getNewBlockBits(chainHeadBlock, chainHeadBlockHeight): newBlockBits = chainHeadBlock.bits if chainHeadBlockHeight > 0: blockRetargeting = getBlockRetargeting() if chainHeadBlockHeight % blockRetargeting == 0: retargetingStartBlock = chainHeadBlock retargeting = None index = 0 while index < blockRetargeting: retargetingBlockTarget = getTargetFromBits( retargetingStartBlock.bits) if retargeting == None: retargeting = retargetingBlockTarget if Config.getBoolValue('DGW3_ENABLED'): if index > 0: retargeting = (retargeting * index + retargetingBlockTarget) // (index + 1) retargetingStartBlock = Chain.getChain().getBlockByHash( retargetingStartBlock.previousHash) index += 1 blockIntervalTime = chainHeadBlock.timestamp - retargetingStartBlock.timestamp blockIntervalTime = math.ceil(blockIntervalTime) adjustedTarget = adjustTarget(retargeting, blockIntervalTime) if adjustedTarget > getTargetFromBits( Config.getIntValue('GENESIS_BLOCK_DIFFICULTY_BITS', 16)): adjustedTarget = getTargetFromBits( Config.getIntValue('GENESIS_BLOCK_DIFFICULTY_BITS', 16)) newBlockBits = getBitsFromTarget(adjustedTarget) return newBlockBits
def hasAuthorization(self): if Config.getBoolValue("HTTP_RPC_AUTHENTICATION_ENABLE"): authorizationHeader = self.headers.get('Authorization') if authorizationHeader == None: return False elif authorizationHeader != Http.getBasicAuth(): return False return True
def server_bind(self): self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if Config.getBoolValue("HTTP_SSL_ENABLE"): self.socket = ssl.wrap_socket( self.socket, certfile=Config.getValue("HTTP_SSL_CERTIFICATE"), server_side=True) self.socket.bind(self.server_address)
def adjustTarget(retargeting, blockIntervalTime): targetTime = getBlockRetargeting() * getBlockTime() if Config.getBoolValue('DGW3_ENABLED'): if blockIntervalTime < targetTime // 3: blockIntervalTime = targetTime // 3 if blockIntervalTime > targetTime * 3: blockIntervalTime = targetTime * 3 adjustedTarget = retargeting * blockIntervalTime adjustedTarget = adjustedTarget // targetTime return adjustedTarget
def getHostname(includePort=True): try: if Config.getBoolValue("REQUIRE_HOSTNAME"): hostname = socket.gethostname() else: hostname = getIpAddress(False) if includePort: hostname += "{0}{1}".format(':', getSocketPort()) return hostname except IOError: Log.error('Unable to get hostname') return None
class Peers: db = Config.getValue("PEERS_DB") subDb = Config.getValue("PEERS_SUB_DB") peers = Storage(db, subDb) hostname = Network.getHostname() ipAddress = Network.getIpAddress() if Config.getBoolValue('PEERS_ENABLE_SEEDS'): with open(Config.getValue('SEEDS_DIR')) as seeds: hosts = json.load(seeds) for host in hosts: if host != hostname and host != ipAddress: hostBytes = DataType.serialize(host) if peers.get(hostBytes) == None: peer = Peer() peer.host = host peer.lastUpdate = DataType.asTime() peers.set(hostBytes, peer.serialize())
def handleArguments(arguments): httpPort = Http.getHttpPort() socketPort = Network.getSocketPort() if arguments.service_port: httpPort = arguments.service_port Http.setHttpPort(httpPort) if arguments.node_port: socketPort = arguments.node_port Network.setSocketPort(socketPort) if Config.getBoolValue("ENABLE_HTTP_SERVICE"): httpNode = HttpNode(httpPort) httpNode.start() UPnP.addPortMapping(socketPort) socketNode = SocketNode(socketPort) socketNode.sync() socketNode.start()
def debug(message): if Config.getBoolValue('DEBUG_LOG_ENABLED'): Log.debugLogger.debug(message)
def getBlockRetargeting(): if Config.getBoolValue('DGW3_ENABLED'): return Config.getIntValue('DGW3_BLOCK_RETARGETING') else: return Config.getIntValue('BLOCK_RETARGETING')
def getBlockTime(): if Config.getBoolValue('DGW3_ENABLED'): return Config.getIntValue('DGW3_BLOCK_TIME') else: return Config.getIntValue('BLOCK_TIME')