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 get_messages_info(self): async with make_aiohttp_session(proxy=self.network.proxy, timeout=120) as session: async with session.get(self.url) as result: signed_version_dict = await result.json(content_type=None) # example signed_version_dict: # { # "version": "3.9.9", # "signatures": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } message = signed_version_dict['message'] sigs = signed_version_dict['signatures'] for address, sig in sigs.items(): if address not in VERSION_ANNOUNCEMENT_SIGNING_KEYS: raise Exception('Address not in annoucement keys') sig = base64.b64decode(sig) msg = message.encode('utf-8') if ecc.verify_message_with_address( address=address, sig65=sig, message=msg, net=constants.RavencoinMainnet): break else: raise Exception('No items') return message.split('{:}')
async def get_update_info(self): async with make_aiohttp_session( proxy=self.main_window.network.proxy) 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": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } 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.print_error( f"valid sig for version announcement '{version_num}' from address '{address}'" ) break else: raise Exception( 'no valid signature for version announcement') return StrictVersion(version_num.strip())
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": { # "1Lqm1HphuhxKZQEawzPse8gJtgjm9kUKT4": "IA+2QG3xPRn4HAIFdpu9eeaCYC7S5wS/sDxn54LJx6BdUTBpse3ibtfq8C43M7M1VfpGkD5tsdwl5C6IfpZD/gQ=" # } # } version_num = signed_version_dict['version'] sigs = signed_version_dict['signatures'] for address, sig in sigs.items(): if address not in 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.RavencoinMainnet): 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 StrictVersion(version_num.strip())
def get_json(cls, url): network = Network.get_instance() proxy = network.proxy if network else None with make_aiohttp_session(proxy) as session: with session.get(url) as response: response.raise_for_status() # set content_type to None to disable checking MIME type return response.json(content_type=None)
async def get_update_info(self): async with make_aiohttp_session( proxy=self.main_window.network.proxy) as session: async with session.get(UpdateCheck.url) as result: version_dict = await result.json(content_type=None) version_num = version_dict.get("tag_name", '') if version_num.startswith('v'): version_num = version_num[1:] return StrictVersion(version_num.strip())
async def do_post(self, url = "/labels", data=None): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.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
async def do_post(self, url="/labels", data=None): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.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
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.main_window.network.proxy, timeout=120) as session: async with session.get(UpdateCheck.url) as result: version_dict = await result.json(content_type=None) version_num = version_dict.get("tag_name", '') if version_num.startswith('v') : version_num = version_num[1:] return StrictVersion(version_num.strip())
async def do_post(self, url="/labels", data=None): url = 'http://' + 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
async def _send_request(self, method, relative_url, data): url = urljoin(self.base_url, relative_url) if self.debug: print('%s %s %s' % (method, url, data)) headers = {} if self.user_agent: headers['user-agent'] = self.user_agent try: proxy = Network.get_instance().proxy async with make_aiohttp_session(proxy) as session: if method == 'get': async with session.get(url, params=data, headers=headers) as resp: return await self.handle_response(resp) elif method == 'post': async with session.post(url, json=data, headers=headers) as resp: return await self.handle_response(resp) else: assert False except TrustedCoinException: raise except Exception as e: raise ErrorConnectingServer(e)
async def do_post(self, url="/labels", data=None): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.proxy) as session: async with session.post(url, json=data) as result: return await result.json()
async def do_get(self, url="/labels"): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.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 async with make_aiohttp_session(self.proxy) as session: async with session.post(url, json=data) as result: return await result.json()
async def do_get(self, url = "/labels"): url = 'https://' + self.target_host + url async with make_aiohttp_session(self.proxy) as session: async with session.get(url) as result: return await result.json()