Esempio n. 1
0
 def _call_rpc(self, method, **kwargs):
     caller_func_name = inspect.stack()[1][3]
     port = self.port if \
         caller_func_name in ['get_info', 'getblockcount'] \
         else self.wallet_port
     self.url = self.part_url + port + '/json_rpc'
     try:
         for _ in range(self.max_call_amount):
             res = requests.post(self.url,
                                 data=json.dumps({
                                     'method': method,
                                     **kwargs
                                 }),
                                 auth=HTTPDigestAuth(
                                     self.user, self.password),
                                 timeout=self.timeout)
             if not res.json().get('error'):
                 break
             else:
                 time.sleep(1)
     except requests.ConnectTimeout:
         raise JSONRPCException('Timeout, Cryptonight wallet might be down')
     if res.status_code != 200:
         raise JSONRPCException('Bad status code: {}'.format(res))
     try:
         return res.json()['result']
     except KeyError:
         return res.json()
Esempio n. 2
0
    def __call__(self, *args):
        AuthServiceProxy.__id_count += 1

        postdata = json.dumps(
            {
                'version': '1.1',
                'method': self.__service_name,
                'params': args,
                'id': AuthServiceProxy.__id_count
            },
            default=EncodeDecimal)
        self.__conn.request(
            'POST', self.__url.path, postdata, {
                'Host': self.__url.hostname,
                'User-Agent': USER_AGENT,
                'Authorization': self.__auth_header,
                'Content-type': 'application/json'
            })

        response = self._get_response()
        if response['error'] is not None:
            raise JSONRPCException(response['error'])
        elif 'result' not in response:
            raise JSONRPCException({
                'code': -343,
                'message': 'missing JSON-RPC result'
            })
        else:
            return response['result']
 def __init__(self, parent_exception):
     JSONRPCException.__init__(self, parent_exception.error)
     self.message = self.message + \
                    '\n\nMake sure the dash daemon you are connecting to has the following options enabled in ' \
                    'its dash.conf:\n\n' + \
                    'addressindex=1\n' + \
                    'spentindex=1\n' + \
                    'timestampindex=1\n' + \
                    'txindex=1\n\n' + \
                    'Changing these parameters requires to execute dashd with "-reindex" option (linux: ./dashd -reindex)'
Esempio n. 4
0
 def _call_rpc(self, action, **kwargs):
     try:
         res = requests.post(self.url,
                             data=json.dumps({
                                 'action': action,
                                 **kwargs
                             }),
                             timeout=self.timeout)
     except requests.ConnectTimeout:
         raise JSONRPCException('Timeout, Blake2 wallet might be down')
     if res.status_code != 200:
         raise JSONRPCException('Bad status code: {}'.format(res))
     return res.json()
Esempio n. 5
0
 def _call_rpc(self, method, **kwargs):
     try:
         res = requests.post(self.url,
                             data=json.dumps({
                                 'method': method,
                                 **kwargs
                             }),
                             timeout=self.timeout)
     except requests.ConnectTimeout:
         raise JSONRPCException('Timeout, Ripple wallet might be down')
     if res.status_code != 200:
         raise JSONRPCException('Bad status code: {}'.format(res))
     try:
         return res.json()['result']
     except KeyError:
         return res.json()
Esempio n. 6
0
 def create_address(self):
     kwargs = {'params': {'account_index': 0}}
     address = self._call_rpc('create_address', **kwargs).get('address')
     if not address:
         raise JSONRPCException('Account is None.')
     else:
         return address
Esempio n. 7
0
 def account_create(self, wallet):
     kwargs = {'wallet': wallet}
     res = self._call_rpc('account_create', **kwargs)
     account = res.get('account')
     if not account:
         raise JSONRPCException('Account is None. Response:{}'.format(res))
     return account
Esempio n. 8
0
 def account_balance(self, account):
     kwargs = {'account': account}
     res = self._call_rpc('account_balance', **kwargs)
     if 'balance' not in res:
         raise JSONRPCException(
             'Bad account balance response: {}'.format(res))
     return res
Esempio n. 9
0
    def rpc_command(self, *params):
        payload = {'id': 1, 'method': params[0], 'rpc': '1.0'}
        if len(params) > 1:
            payload['params'] = params[1:]

        try:
            r = requests.post(
                "http://{0}:{1}@{2}:{3}".format(*self.creds), data=json.dumps(payload))
            response = json.loads(r.text)
            if response['error'] is not None:
                raise JSONRPCException(response['error'])
            elif 'result' not in response:
                raise JSONRPCException({
                    'code': -343, 'message': 'missing JSON-RPC result'})
            return response['result']
        except:
            raise Exception
Esempio n. 10
0
 def account_list(self, wallet):
     kwargs = {'wallet': wallet}
     res = self._call_rpc('account_list', **kwargs)
     accounts = res.get('accounts')
     if not accounts:
         raise JSONRPCException(
             'Bad list accounts response. Response:{}'.format(res))
     return accounts
Esempio n. 11
0
 def send(self, wallet, source, destination, amount):
     kwargs = {
         "wallet": wallet,
         "source": source,
         "destination": destination,
         "amount": amount
     }
     res = self._call_rpc('send', **kwargs)
     block = res.get('block')
     if not block:
         raise JSONRPCException('No block in response: {}'.format(res))
     return block
Esempio n. 12
0
    def _get_response(self):
        http_response = self.__conn.getresponse()
        if http_response is None:
            raise JSONRPCException({
                'code':
                -342,
                'message':
                'missing HTTP response from server'
            })

        return json.loads(http_response.read().decode('utf8'),
                          parse_float=decimal.Decimal)