async def get_update_info(self): # note: Use long timeout here as it is not critical that we get a response fast, # and it's bad not to get an update notification just because we did not wait enough. async with make_aiohttp_session(proxy=self.network.proxy, timeout=120) as session: async with session.get(UpdateCheck.url) as result: signed_version_dict = await result.json(content_type=None) # example signed_version_dict: # { # "version": "3.9.9", # "signatures": { # "MRkEwoPcvSPaC5WNtQMa7NGPy2tBKbp3Bm": "H84UFTdaBswxTrNty0gLlWiQEQhJA2Se5xVdhR9zFirKYg966IXEkC7km6phIJq+2CT3KwvKuj8YKaSCy1fErwg=" # } # } version_num = signed_version_dict['version'] sigs = signed_version_dict['signatures'] for address, sig in sigs.items(): if address not in UpdateCheck.VERSION_ANNOUNCEMENT_SIGNING_KEYS: continue sig = base64.b64decode(sig) msg = version_num.encode('utf-8') if ecc.verify_message_with_address(address=address, sig65=sig, message=msg, net=constants.BitcoinMainnet): self.logger.info(f"valid sig for version announcement '{version_num}' from address '{address}'") break else: raise Exception('no valid signature for version announcement') return LooseVersion(version_num.strip())
async def do_get(self, url="/labels"): url = 'https://' + self.target_host + url network = Network.get_instance() proxy = network.proxy if network else None async with make_aiohttp_session(proxy) as session: async with session.get(url) as result: return await result.json()
async def do_post(self, url = "/labels", data=None): url = 'https://' + self.target_host + url network = Network.get_instance() proxy = network.proxy if network else None async with make_aiohttp_session(proxy) as session: async with session.post(url, json=data) as result: try: return await result.json() except Exception as e: raise Exception('Could not decode: ' + await result.text()) from e