Пример #1
0
    def _get_dashboard(self, offset=0, limit=0):
        response = self.request(
            'get_dashboard',
            symbol=self.symbol,
            name=self.name,
            address_type=self.address_type,
            address=self.address,
            offset=offset,
            limit=limit
        )

        data = response.get('data')
        if not data:
            raise AddressNotExist()

        dashboard = list(data.values())[0]

        if self.address_type == 'address' and not dashboard['address']['type']:
            raise AddressNotExist()

        return dashboard
Пример #2
0
    def get_staking(self, offset=0, limit=20):
        body = json.dumps({'key': self.address, 'row': limit, 'page': offset})

        response = self.request('get_staking',
                                body=body,
                                headers=self._headers,
                                api_key=self.api_key)

        if response['code'] == 0:
            return safe_decimal(response['data']['account']['balance_lock'])
        elif response['code'] == 10004:
            raise AddressNotExist()
        else:
            raise APIError(response['message'])
Пример #3
0
    def get_txs(self, offset=0, limit=10, unconfirmed=False):
        body = json.dumps({
            'address': self.address,
            'page': offset,
            'row': limit
        })

        response = self.request('get_txs',
                                body=body,
                                headers=self._headers,
                                api_key=self.api_key)

        if response['code'] == 0:
            transfers = (self._parse_tx(t)
                         for t in response['data']['transfers'])
            return [t for t in transfers if unconfirmed or t['confirmed']]
        elif response['code'] == 10004:
            raise AddressNotExist()
        else:
            raise APIError(response['message'])
Пример #4
0
    def get_rewards(self, offset=0, limit=20):
        body = json.dumps({
            'address': self.address,
            'row': limit,
            'page': offset
        })

        response = self.request(
            'get_rewards',
            body=body,
            headers=self._headers,
            api_key=self.api_key
        )

        if response['code'] == 0:
            return [self._parse_reward(r) for r in
                    (response['data']['list'] if response['data']['list'] is not None else [])]
        elif response['code'] == 10004:
            raise AddressNotExist()
        else:
            raise APIError(response['message'])
Пример #5
0
    def get_balance(self):
        body = json.dumps({
            'key': self.address,
            'row': 1,
            'page': 0,
        })

        response = self.request(
            'get_balance',
            body=body,
            headers=self._headers,
            api_key=self.api_key
        )

        if response['code'] == 0:
            return [{
                'symbol': self.symbol,
                'amount': to_decimal(response['data']['account']['balance'])
            }]
        elif response['code'] == 10004:
            raise AddressNotExist()
        else:
            raise APIError(response['message'])
Пример #6
0
 def process_error_response(self, response):
     if 'decoding bech32 failed' in response.text:
         raise AddressNotExist()
     # else
     super().process_error_response(response)
Пример #7
0
 def process_error_response(self, response):
     if response.status_code == 422:
         raise AddressNotExist()
     # else
     super().process_error_response(response)
Пример #8
0
 def process_error_response(self, response):
     err = response.json().get('error')
     if 'is invalid' in err or err == 'Error: wallet not found':
         raise AddressNotExist()
     # else
     super().process_error_response(response)
Пример #9
0
 def _process_error(self, msg):
     if msg == 'Invalid Cardano address!':
         raise AddressNotExist()
     else:
         raise APIError(msg)
Пример #10
0
 def process_error_response(self, response):
     if response.text == 'Invalid Bitcoin Address':
         raise AddressNotExist()
     # else
     super().process_error_response(response)