Пример #1
0
 def send_request(self, method, relative_url, data=None):
     network = Network.get_instance()
     if not network:
         raise ErrorConnectingServer('You are offline.')
     url = urljoin(self.base_url, relative_url)
     if self.debug:
         self.print_error(f'<-- {method} {url} {data}')
     headers = {}
     if self.user_agent:
         headers['user-agent'] = self.user_agent
     try:
         if method == 'get':
             response = Network.send_http_on_proxy(method, url, params=data, headers=headers, on_finish=self.handle_response)
         elif method == 'post':
             response = Network.send_http_on_proxy(method, url, json=data, headers=headers, on_finish=self.handle_response)
         else:
             assert False
     except TrustedCoinException:
         raise
     except Exception as e:
         raise ErrorConnectingServer(e)
     else:
         if self.debug:
             self.print_error(f'--> {response}')
         return response
Пример #2
0
 def send_request(self, method, relative_url, data=None):
     network = Network.get_instance()
     if not network:
         raise ErrorConnectingServer('You are offline.')
     url = urljoin(self.base_url, relative_url)
     if self.debug:
         self.print_error(f'<-- {method} {url} {data}')
     headers = {}
     if self.user_agent:
         headers['user-agent'] = self.user_agent
     try:
         if method == 'get':
             response = Network.send_http_on_proxy(
                 method,
                 url,
                 params=data,
                 headers=headers,
                 on_finish=self.handle_response)
         elif method == 'post':
             response = Network.send_http_on_proxy(
                 method,
                 url,
                 json=data,
                 headers=headers,
                 on_finish=self.handle_response)
         else:
             assert False
     except TrustedCoinException:
         raise
     except Exception as e:
         raise ErrorConnectingServer(e)
     else:
         if self.debug:
             self.print_error(f'--> {response}')
         return response
Пример #3
0
def _http_request(params):
    # Use the first non-onion url
    url = [url for url in params['urls'] if not url.endswith('.onion')][0]
    method = params['method'].lower()
    json_payload = params.get('data')
    json_response = Network.send_http_on_proxy(method, url, json=json_payload)
    return {'body': json.loads(json_response)}
Пример #4
0
    def do_verify(self, d):
        tx = d.tx
        wallet = d.wallet
        window = d.main_window

        if wallet.is_watching_only():
            d.show_critical(
                _('This feature is not available for watch-only wallets.'))
            return

        # 1. get the password and sign the verification request
        password = None
        if wallet.has_keystore_encryption():
            msg = _('GreenAddress requires your signature \n'
                    'to verify that transaction is instant.\n'
                    'Please enter your password to sign a\n'
                    'verification request.')
            password = window.password_dialog(msg, parent=d)
            if not password:
                return
        try:
            d.verify_button.setText(_('Verifying...'))
            QApplication.processEvents()  # update the button label

            addr = self.get_my_addr(d)
            message = "Please verify if %s is GreenAddress instant confirmed" % tx.txid(
            )
            sig = wallet.sign_message(addr, message, password)
            sig = base64.b64encode(sig).decode('ascii')

            # 2. send the request
            async def handle_request(resp: 'ClientResponse'):
                resp.raise_for_status()
                return await resp.json()

            url = "https://greenaddress.it/verify/?signature=%s&txhash=%s" % (
                urllib.parse.quote(sig), tx.txid())
            response = Network.send_http_on_proxy(
                'get',
                url,
                headers={'User-Agent': 'Electrum'},
                on_finish=handle_request)

            # 3. display the result
            if response.get('verified'):
                d.show_message(
                    _('{} is covered by GreenAddress instant confirmation'
                      ).format(tx.txid()),
                    title=_('Verification successful!'))
            else:
                d.show_warning(
                    _('{} is not covered by GreenAddress instant confirmation'
                      ).format(tx.txid()),
                    title=_('Verification failed!'))
        except BaseException as e:
            import traceback
            traceback.print_exc(file=sys.stdout)
            d.show_error(str(e))
        finally:
            d.verify_button.setText(self.button_label)
Пример #5
0
 def comserver_post_notification(self, payload):
     assert self.is_mobile_paired(), "unexpected mobile pairing error"
     url = 'https://digitalbitbox.com/smartverification/index.php'
     key_s = base64.b64decode(self.digitalbitbox_config[ENCRYPTION_PRIVKEY_KEY])
     args = 'c=data&s=0&dt=0&uuid=%s&pl=%s' % (
         self.digitalbitbox_config[CHANNEL_ID_KEY],
         EncodeAES_base64(key_s, json.dumps(payload).encode('ascii')).decode('ascii'),
     )
     try:
         text = Network.send_http_on_proxy('post', url, body=args.encode('ascii'), headers={'content-type': 'application/x-www-form-urlencoded'})
         print_error('digitalbitbox reply from server', text)
     except Exception as e:
         self.handler.show_error(repr(e)) # repr because str(Exception()) == ''
 def comserver_post_notification(self, payload):
     assert self.is_mobile_paired(), "unexpected mobile pairing error"
     url = 'https://digitalbitbox.com/smartverification/index.php'
     key_s = base64.b64decode(self.digitalbitbox_config[ENCRYPTION_PRIVKEY_KEY])
     args = 'c=data&s=0&dt=0&uuid=%s&pl=%s' % (
         self.digitalbitbox_config[CHANNEL_ID_KEY],
         EncodeAES_base64(key_s, json.dumps(payload).encode('ascii')).decode('ascii'),
     )
     try:
         text = Network.send_http_on_proxy('post', url, body=args.encode('ascii'), headers={'content-type': 'application/x-www-form-urlencoded'})
         _logger.info(f'digitalbitbox reply from server {text}')
     except Exception as e:
         self.handler.show_error(repr(e)) # repr because str(Exception()) == ''
Пример #7
0
    def do_verify(self, d):
        tx = d.tx
        wallet = d.wallet
        window = d.main_window

        if wallet.is_watching_only():
            d.show_critical(_('This feature is not available for watch-only wallets.'))
            return

        # 1. get the password and sign the verification request
        password = None
        if wallet.has_keystore_encryption():
            msg = _('GreenAddress requires your signature \n'
                    'to verify that transaction is instant.\n'
                    'Please enter your password to sign a\n'
                    'verification request.')
            password = window.password_dialog(msg, parent=d)
            if not password:
                return
        try:
            d.verify_button.setText(_('Verifying...'))
            QApplication.processEvents()  # update the button label

            addr = self.get_my_addr(d)
            message = "Please verify if %s is GreenAddress instant confirmed" % tx.txid()
            sig = wallet.sign_message(addr, message, password)
            sig = base64.b64encode(sig).decode('ascii')

            # 2. send the request
            async def handle_request(resp: 'ClientResponse'):
                resp.raise_for_status()
                return await resp.json()
            url = "https://greenaddress.it/verify/?signature=%s&txhash=%s" % (urllib.parse.quote(sig), tx.txid())
            response = Network.send_http_on_proxy('get', url, headers = {'User-Agent': 'Electrum'}, on_finish=handle_request)

            # 3. display the result
            if response.get('verified'):
                d.show_message(_('{} is covered by GreenAddress instant confirmation').format(tx.txid()), title=_('Verification successful!'))
            else:
                d.show_warning(_('{} is not covered by GreenAddress instant confirmation').format(tx.txid()), title=_('Verification failed!'))
        except BaseException as e:
            import traceback
            traceback.print_exc(file=sys.stdout)
            d.show_error(str(e))
        finally:
            d.verify_button.setText(self.button_label)