blockapi 2.12.0__tar.gz → 2.13.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {blockapi-2.12.0 → blockapi-2.13.0}/PKG-INFO +1 -1
- blockapi-2.13.0/blockapi/test/v2/api/test_blockonomics.py +106 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_terra.py +66 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/__init__.py +1 -0
- blockapi-2.13.0/blockapi/v2/api/blockonomics.py +89 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/cosmos.py +2 -2
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi.egg-info/PKG-INFO +1 -1
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi.egg-info/SOURCES.txt +2 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/setup.py +1 -1
- {blockapi-2.12.0 → blockapi-2.13.0}/LICENSE.md +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/README.md +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/services.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/test_blockapi.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/test_num.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/test_random_user_agent.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/conftest.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/covalenth/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/covalenth/test_ethereum.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/fake_sleep_provider.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/nft/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/nft/test_magic_eden.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/nft/test_opensea.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/nft/test_simple_hash.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/nft/test_unisat.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_bitaps_ltc.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_blockchain_info.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_blockchainos.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_blockchair_btc.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_blockchair_doge.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_blockchair_ltc.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_chainso.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_cosmos.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_ethplorer.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_haskoin.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_litecoinspace.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_multisources.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_optimistic_etherscan.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_solana.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_subscan_polkadot.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_sui.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_trezor_btc.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/api/test_trezor_zec.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_base.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_blockchain_api.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_blockchain_mapping.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_data.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_enumerate_classes.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_generic.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test/v2/test_models.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/test_data.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/utils/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/utils/address.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/utils/datetime.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/utils/num.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/utils/user_agent.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/bitaps.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/blockchain_info.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/blockchainos.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/blockchair.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/chainso.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/arbitrum.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/astar.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/avalanche.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/axie.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/base.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/binance_smart_chain.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/ethereum.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/fantom.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/heco.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/iotex.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/klaytn.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/moonbeam.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/palm.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/polygon.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/covalenth/rsk.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/debank.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/debank_maps.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/ethplorer.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/haskoin.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/litecoinspace.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/nft/__init__.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/nft/magic_eden.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/nft/opensea.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/nft/simple_hash.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/nft/unisat.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/optimistic_etherscan.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/solana.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/subscan.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/sui.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/terra.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/api/trezor.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/base.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/blockchain_mapping.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/coin_mapping.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/coins.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi/v2/models.py +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi.egg-info/dependency_links.txt +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi.egg-info/requires.txt +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/blockapi.egg-info/top_level.txt +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/pyproject.toml +0 -0
- {blockapi-2.12.0 → blockapi-2.13.0}/setup.cfg +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from decimal import Decimal
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from requests.exceptions import ConnectionError, ReadTimeout
|
|
5
|
+
|
|
6
|
+
from blockapi.v2.api import BlockonomicsApi
|
|
7
|
+
from blockapi.v2.base import ApiException
|
|
8
|
+
from blockapi.v2.models import FetchResult
|
|
9
|
+
|
|
10
|
+
# Deliberately synthetic identifiers: these tests never access a live wallet.
|
|
11
|
+
KEY = 'synthetic-api-key'
|
|
12
|
+
URL = 'https://www.blockonomics.co/api/balance'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def row(address='synthetic-derived-address', confirmed=123456789, unconfirmed=0):
|
|
16
|
+
return dict(addr=address, confirmed=confirmed, unconfirmed=unconfirmed)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.parametrize(
|
|
20
|
+
'address', ['synthetic-address', 'xpubSynthetic', 'ypubSynthetic', 'zpubSynthetic']
|
|
21
|
+
)
|
|
22
|
+
def test_fetch_and_aggregate(requests_mock, address):
|
|
23
|
+
payload = {
|
|
24
|
+
'response': [
|
|
25
|
+
row(confirmed=123456789, unconfirmed=999),
|
|
26
|
+
row('synthetic-change-address', 1, -10),
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
requests_mock.get(URL, json=payload)
|
|
30
|
+
balances = BlockonomicsApi(api_key=KEY).get_balance(address)
|
|
31
|
+
assert len(balances) == 1
|
|
32
|
+
assert balances[0].balance == Decimal('1.23456790')
|
|
33
|
+
assert balances[0].raw == payload
|
|
34
|
+
request = requests_mock.last_request
|
|
35
|
+
assert request.headers['Authorization'] == 'Bearer ' + KEY
|
|
36
|
+
assert request.qs == {'addr': [address.lower()]}
|
|
37
|
+
assert KEY not in request.url
|
|
38
|
+
assert request.timeout == (5, 30)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_zero_excludes_unconfirmed(requests_mock):
|
|
42
|
+
requests_mock.get(URL, json={'response': [row(confirmed=0, unconfirmed=100)]})
|
|
43
|
+
assert BlockonomicsApi(api_key=KEY).get_balance('synthetic-address') == []
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_missing_key_does_not_request(requests_mock):
|
|
47
|
+
with pytest.raises(ApiException, match='API key'):
|
|
48
|
+
BlockonomicsApi().get_balance('synthetic-address')
|
|
49
|
+
assert requests_mock.call_count == 0
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.mark.parametrize('address', ['', 'first second', 'first\nsecond'])
|
|
53
|
+
def test_reject_batch_input(requests_mock, address):
|
|
54
|
+
with pytest.raises(ApiException, match='Expected one'):
|
|
55
|
+
BlockonomicsApi(api_key=KEY).get_balance(address)
|
|
56
|
+
assert requests_mock.call_count == 0
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.parametrize('status', [401, 403, 429, 500, 502])
|
|
60
|
+
def test_http_error_not_zero(requests_mock, status):
|
|
61
|
+
requests_mock.get(URL, status_code=status, json={'message': 'unavailable'})
|
|
62
|
+
with pytest.raises(ApiException):
|
|
63
|
+
BlockonomicsApi(api_key=KEY).get_balance('synthetic-address')
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize(
|
|
67
|
+
'error', [ConnectionError('disconnected'), ReadTimeout('timeout')]
|
|
68
|
+
)
|
|
69
|
+
def test_transport_error_not_zero(requests_mock, error):
|
|
70
|
+
requests_mock.get(URL, exc=error)
|
|
71
|
+
with pytest.raises(ApiException):
|
|
72
|
+
BlockonomicsApi(api_key=KEY).get_balance('synthetic-address')
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_invalid_json(requests_mock):
|
|
76
|
+
requests_mock.get(URL, text='<html>error</html>')
|
|
77
|
+
with pytest.raises(ApiException, match='Invalid JSON'):
|
|
78
|
+
BlockonomicsApi(api_key=KEY).get_balance('synthetic-address')
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.mark.parametrize(
|
|
82
|
+
'data',
|
|
83
|
+
[
|
|
84
|
+
None,
|
|
85
|
+
{},
|
|
86
|
+
[],
|
|
87
|
+
{'response': []},
|
|
88
|
+
{'response': {}},
|
|
89
|
+
{'response': [None]},
|
|
90
|
+
{'response': [{}]},
|
|
91
|
+
{'response': [row(confirmed=True)]},
|
|
92
|
+
{'response': [row(confirmed=-1)]},
|
|
93
|
+
{'response': [row(confirmed='1')]},
|
|
94
|
+
{'response': [row(confirmed=1.5)]},
|
|
95
|
+
{'response': [row(address=None)]},
|
|
96
|
+
{'response': [row(), row()]},
|
|
97
|
+
],
|
|
98
|
+
)
|
|
99
|
+
def test_invalid_response_not_zero(data):
|
|
100
|
+
with pytest.raises(ApiException):
|
|
101
|
+
BlockonomicsApi().parse_balances(FetchResult(data=data))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_direct_parse_preserves_error():
|
|
105
|
+
with pytest.raises(ApiException, match='unavailable'):
|
|
106
|
+
BlockonomicsApi().parse_balances(FetchResult(errors=['unavailable']))
|
|
@@ -176,6 +176,72 @@ def test_get_staking_balances(
|
|
|
176
176
|
assert luna_reward.balance == Decimal('5')
|
|
177
177
|
|
|
178
178
|
|
|
179
|
+
@pytest.mark.parametrize(
|
|
180
|
+
'has_delegations, has_unbonding, expected_staked',
|
|
181
|
+
[
|
|
182
|
+
(False, False, '0'),
|
|
183
|
+
(False, True, '25'),
|
|
184
|
+
(True, False, '100'),
|
|
185
|
+
],
|
|
186
|
+
)
|
|
187
|
+
def test_get_balance_with_null_staking_responses(
|
|
188
|
+
terra_api,
|
|
189
|
+
balances_response,
|
|
190
|
+
staking_response,
|
|
191
|
+
rewards_response,
|
|
192
|
+
requests_mock,
|
|
193
|
+
has_delegations,
|
|
194
|
+
has_unbonding,
|
|
195
|
+
expected_staked,
|
|
196
|
+
):
|
|
197
|
+
requests_mock.get(
|
|
198
|
+
f'{BASE_URL}/cosmos/bank/v1beta1/balances/{ADDRESS}',
|
|
199
|
+
json=balances_response,
|
|
200
|
+
)
|
|
201
|
+
requests_mock.get(
|
|
202
|
+
f'{BASE_URL}/cosmos/staking/v1beta1/delegations/{ADDRESS}',
|
|
203
|
+
json={
|
|
204
|
+
'delegation_responses': (
|
|
205
|
+
staking_response['delegation_responses'] if has_delegations else None
|
|
206
|
+
),
|
|
207
|
+
'pagination': {'next_key': None, 'total': str(int(has_delegations))},
|
|
208
|
+
},
|
|
209
|
+
)
|
|
210
|
+
requests_mock.get(
|
|
211
|
+
f'{BASE_URL}/cosmos/staking/v1beta1/delegators/{ADDRESS}/unbonding_delegations',
|
|
212
|
+
json={
|
|
213
|
+
'unbonding_responses': (
|
|
214
|
+
[{'entries': [{'balance': '25000000'}]}] if has_unbonding else None
|
|
215
|
+
),
|
|
216
|
+
'pagination': {'next_key': None, 'total': str(int(has_unbonding))},
|
|
217
|
+
},
|
|
218
|
+
)
|
|
219
|
+
requests_mock.get(
|
|
220
|
+
f'{BASE_URL}/cosmos/distribution/v1beta1/delegators/{ADDRESS}/rewards',
|
|
221
|
+
json=rewards_response,
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
balances = terra_api.get_balance(ADDRESS)
|
|
225
|
+
|
|
226
|
+
available = {
|
|
227
|
+
b.coin.address: b.balance
|
|
228
|
+
for b in balances
|
|
229
|
+
if b.asset_type == AssetType.AVAILABLE
|
|
230
|
+
}
|
|
231
|
+
assert available == {
|
|
232
|
+
'uluna': Decimal('23068.009633'),
|
|
233
|
+
'uusd': Decimal('85.997844'),
|
|
234
|
+
}
|
|
235
|
+
staked = [b for b in balances if b.asset_type == AssetType.STAKED]
|
|
236
|
+
assert [b.balance for b in staked] == (
|
|
237
|
+
[Decimal(expected_staked)] if Decimal(expected_staked) else []
|
|
238
|
+
)
|
|
239
|
+
rewards = {
|
|
240
|
+
b.coin.address: b.balance for b in balances if b.asset_type == AssetType.REWARDS
|
|
241
|
+
}
|
|
242
|
+
assert rewards == {'uluna': Decimal('5'), 'uusd': Decimal('1')}
|
|
243
|
+
|
|
244
|
+
|
|
179
245
|
def test_resolve_ibc_denom(terra_api, ibc_denom_trace_response, requests_mock):
|
|
180
246
|
ibc_hash = '0A866A7A214C42CEF84430C8A4C7210C8C7A980548A9B9BE64316D1610A87C6C'
|
|
181
247
|
ibc_denom = f'ibc/{ibc_hash}'
|
|
@@ -7,6 +7,7 @@ from blockapi.v2.api.blockchair import (
|
|
|
7
7
|
BlockchairDogecoinApi,
|
|
8
8
|
BlockchairLitecoinApi,
|
|
9
9
|
)
|
|
10
|
+
from blockapi.v2.api.blockonomics import BlockonomicsApi
|
|
10
11
|
from blockapi.v2.api.chainso import ChainSoLitecoinApi
|
|
11
12
|
from blockapi.v2.api.debank import DebankApi, DebankApp, DebankPrediction
|
|
12
13
|
from blockapi.v2.api.ethplorer import EthplorerApi
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from blockapi.v2.base import ApiException, BalanceMixin, BlockchainApi
|
|
2
|
+
from blockapi.v2.coins import COIN_BTC
|
|
3
|
+
from blockapi.v2.models import (
|
|
4
|
+
ApiOptions,
|
|
5
|
+
AssetType,
|
|
6
|
+
BalanceItem,
|
|
7
|
+
Blockchain,
|
|
8
|
+
FetchResult,
|
|
9
|
+
ParseResult,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BlockonomicsApi(BlockchainApi, BalanceMixin):
|
|
14
|
+
"""BTC balances for addresses and xpub/ypub/zpub extended public keys.
|
|
15
|
+
|
|
16
|
+
Requires a Blockonomics API key. Only provider-confirmed balances are
|
|
17
|
+
included: Blockonomics classifies fewer than two confirmations as
|
|
18
|
+
unconfirmed. Extended-key discovery follows the provider's gap policy.
|
|
19
|
+
Docs: https://developers.blockonomics.co/docs/search/getbalance
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
coin = COIN_BTC
|
|
23
|
+
api_options = ApiOptions(
|
|
24
|
+
blockchain=Blockchain.BITCOIN,
|
|
25
|
+
base_url='https://www.blockonomics.co/api/',
|
|
26
|
+
rate_limit=1,
|
|
27
|
+
)
|
|
28
|
+
supported_requests = {'get_balance': 'balance'}
|
|
29
|
+
request_timeout = (5, 30)
|
|
30
|
+
|
|
31
|
+
def _get_response(self, request_method, headers, params, req_args):
|
|
32
|
+
return self._session.get(
|
|
33
|
+
self._build_request_url(request_method, **req_args),
|
|
34
|
+
headers=headers,
|
|
35
|
+
params=params,
|
|
36
|
+
timeout=self.request_timeout,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def fetch_balances(self, address: str) -> FetchResult:
|
|
40
|
+
if not self.api_key:
|
|
41
|
+
return FetchResult(errors=['Blockonomics API key is required'])
|
|
42
|
+
# One wallet per request; whitespace is the provider's batch separator.
|
|
43
|
+
if not address or any(char.isspace() for char in address):
|
|
44
|
+
return FetchResult(errors=['Expected one Bitcoin address or extended key'])
|
|
45
|
+
try:
|
|
46
|
+
return self.get_data(
|
|
47
|
+
'get_balance',
|
|
48
|
+
headers={'Authorization': f'Bearer {self.api_key}'},
|
|
49
|
+
params={'addr': address},
|
|
50
|
+
)
|
|
51
|
+
except ValueError:
|
|
52
|
+
return FetchResult(errors=['Invalid JSON in Blockonomics response'])
|
|
53
|
+
|
|
54
|
+
def parse_balances(self, fetch_result: FetchResult) -> ParseResult:
|
|
55
|
+
if fetch_result.errors:
|
|
56
|
+
raise ApiException(fetch_result.errors[0])
|
|
57
|
+
data = fetch_result.data
|
|
58
|
+
rows = data.get('response') if isinstance(data, dict) else None
|
|
59
|
+
if not isinstance(rows, list) or not rows:
|
|
60
|
+
raise ApiException('Invalid Blockonomics response: missing balance rows')
|
|
61
|
+
addresses = set()
|
|
62
|
+
balance_raw = 0
|
|
63
|
+
for row in rows:
|
|
64
|
+
if not isinstance(row, dict):
|
|
65
|
+
raise ApiException('Invalid Blockonomics balance row')
|
|
66
|
+
address = row.get('addr')
|
|
67
|
+
confirmed = row.get('confirmed')
|
|
68
|
+
if (
|
|
69
|
+
not isinstance(address, str)
|
|
70
|
+
or not address
|
|
71
|
+
or address in addresses
|
|
72
|
+
or type(confirmed) is not int
|
|
73
|
+
or confirmed < 0
|
|
74
|
+
):
|
|
75
|
+
raise ApiException('Invalid Blockonomics balance row')
|
|
76
|
+
addresses.add(address)
|
|
77
|
+
balance_raw += confirmed
|
|
78
|
+
if not balance_raw:
|
|
79
|
+
return ParseResult()
|
|
80
|
+
return ParseResult(
|
|
81
|
+
data=[
|
|
82
|
+
BalanceItem.from_api(
|
|
83
|
+
balance_raw=balance_raw,
|
|
84
|
+
coin=self.coin,
|
|
85
|
+
asset_type=AssetType.AVAILABLE,
|
|
86
|
+
raw=data,
|
|
87
|
+
)
|
|
88
|
+
]
|
|
89
|
+
)
|
|
@@ -177,13 +177,13 @@ class CosmosApiBase(BlockchainApi, IBalance, metaclass=ABCMeta):
|
|
|
177
177
|
staked_response = self._get('get_staked_balance', address=address)
|
|
178
178
|
staked_balance = sum(
|
|
179
179
|
to_decimal(d['balance']['amount'])
|
|
180
|
-
for d in staked_response['delegation_responses']
|
|
180
|
+
for d in (staked_response['delegation_responses'] or [])
|
|
181
181
|
)
|
|
182
182
|
|
|
183
183
|
unbonding_response = self._get('get_unbonding_balance', address=address)
|
|
184
184
|
unbonding_balance = sum(
|
|
185
185
|
to_decimal(unbonding_entry['balance'])
|
|
186
|
-
for unbonding in unbonding_response['unbonding_responses']
|
|
186
|
+
for unbonding in (unbonding_response['unbonding_responses'] or [])
|
|
187
187
|
for unbonding_entry in unbonding['entries']
|
|
188
188
|
)
|
|
189
189
|
|
|
@@ -32,6 +32,7 @@ blockapi/test/v2/api/test_blockchainos.py
|
|
|
32
32
|
blockapi/test/v2/api/test_blockchair_btc.py
|
|
33
33
|
blockapi/test/v2/api/test_blockchair_doge.py
|
|
34
34
|
blockapi/test/v2/api/test_blockchair_ltc.py
|
|
35
|
+
blockapi/test/v2/api/test_blockonomics.py
|
|
35
36
|
blockapi/test/v2/api/test_chainso.py
|
|
36
37
|
blockapi/test/v2/api/test_cosmos.py
|
|
37
38
|
blockapi/test/v2/api/test_ethplorer.py
|
|
@@ -68,6 +69,7 @@ blockapi/v2/api/bitaps.py
|
|
|
68
69
|
blockapi/v2/api/blockchain_info.py
|
|
69
70
|
blockapi/v2/api/blockchainos.py
|
|
70
71
|
blockapi/v2/api/blockchair.py
|
|
72
|
+
blockapi/v2/api/blockonomics.py
|
|
71
73
|
blockapi/v2/api/chainso.py
|
|
72
74
|
blockapi/v2/api/cosmos.py
|
|
73
75
|
blockapi/v2/api/debank.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|