blockapi 2.13.1__tar.gz → 2.14.1__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.13.1 → blockapi-2.14.1}/PKG-INFO +1 -1
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_haskoin.py +74 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/debank_maps.py +3 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/haskoin.py +32 -13
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/models.py +1 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi.egg-info/PKG-INFO +1 -1
- {blockapi-2.13.1 → blockapi-2.14.1}/setup.py +1 -1
- {blockapi-2.13.1 → blockapi-2.14.1}/LICENSE.md +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/README.md +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/services.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/test_blockapi.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/test_num.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/test_random_user_agent.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/conftest.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/covalenth/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/covalenth/test_ethereum.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/fake_sleep_provider.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/nft/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/nft/test_magic_eden.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/nft/test_opensea.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/nft/test_simple_hash.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/nft/test_unisat.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_bitaps_ltc.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockchain_info.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockchainos.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockchair_btc.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockchair_doge.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockchair_ltc.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_blockonomics.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_chainso.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_cosmos.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_ethplorer.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_litecoinspace.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_multisources.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_optimistic_etherscan.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_solana.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_subscan_polkadot.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_sui.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_terra.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_trezor_btc.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/api/test_trezor_zec.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_base.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_blockchain_api.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_blockchain_mapping.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_data.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_enumerate_classes.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_generic.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test/v2/test_models.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/test_data.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/utils/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/utils/address.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/utils/datetime.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/utils/num.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/utils/user_agent.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/bitaps.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/blockchain_info.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/blockchainos.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/blockchair.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/blockonomics.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/chainso.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/cosmos.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/arbitrum.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/astar.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/avalanche.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/axie.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/base.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/binance_smart_chain.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/ethereum.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/fantom.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/heco.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/iotex.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/klaytn.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/moonbeam.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/palm.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/polygon.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/covalenth/rsk.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/debank.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/ethplorer.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/litecoinspace.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/nft/__init__.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/nft/magic_eden.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/nft/opensea.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/nft/simple_hash.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/nft/unisat.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/optimistic_etherscan.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/solana.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/subscan.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/sui.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/terra.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/api/trezor.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/base.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/blockchain_mapping.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/coin_mapping.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi/v2/coins.py +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi.egg-info/SOURCES.txt +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi.egg-info/dependency_links.txt +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi.egg-info/requires.txt +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/blockapi.egg-info/top_level.txt +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/pyproject.toml +0 -0
- {blockapi-2.13.1 → blockapi-2.14.1}/setup.cfg +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from decimal import Decimal
|
|
2
|
+
from unittest.mock import Mock
|
|
2
3
|
|
|
3
4
|
import pytest
|
|
4
5
|
|
|
@@ -42,6 +43,79 @@ def test_fetch_balances_xpub(requests_mock, haskoin_xpub_response):
|
|
|
42
43
|
assert balances[0].balance == Decimal('0.12706308')
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
@pytest.mark.parametrize('follow_up_status', [200, 400])
|
|
47
|
+
def test_xpub_follows_segwit_hint_once(requests_mock, follow_up_status):
|
|
48
|
+
url = 'https://api.haskoin.com/btc/xpub/xpubSynthetic'
|
|
49
|
+
hint = {'error': 'user-error', 'message': 'ask with derive=segwit.'}
|
|
50
|
+
requests_mock.get(url, complete_qs=True, status_code=400, json=hint)
|
|
51
|
+
follow_up = f'{url}?derive=segwit'
|
|
52
|
+
payload = {'balance': {'confirmed': 42}} if follow_up_status == 200 else hint
|
|
53
|
+
requests_mock.get(
|
|
54
|
+
follow_up, complete_qs=True, status_code=follow_up_status, json=payload
|
|
55
|
+
)
|
|
56
|
+
sleep_provider = Mock()
|
|
57
|
+
api = HaskoinApi(sleep_provider=sleep_provider)
|
|
58
|
+
|
|
59
|
+
result = api.fetch_balances('xpubSynthetic')
|
|
60
|
+
|
|
61
|
+
assert result.status_code == follow_up_status
|
|
62
|
+
if follow_up_status == 200:
|
|
63
|
+
assert result.data == payload
|
|
64
|
+
else:
|
|
65
|
+
assert 'ask with derive=segwit.' in result.errors[0]
|
|
66
|
+
assert [request.url for request in requests_mock.request_history] == [
|
|
67
|
+
url,
|
|
68
|
+
follow_up,
|
|
69
|
+
]
|
|
70
|
+
sleep_provider.sleep.assert_called_once_with(
|
|
71
|
+
api.base_url, api.api_options.rate_limit
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_explicit_derivation_ignores_hint(requests_mock):
|
|
76
|
+
url = 'https://api.haskoin.com/btc/xpub/xpubSynthetic?derive=legacy'
|
|
77
|
+
requests_mock.get(
|
|
78
|
+
url,
|
|
79
|
+
complete_qs=True,
|
|
80
|
+
status_code=400,
|
|
81
|
+
json={'message': 'ask with derive=segwit.'},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
result = HaskoinApi().fetch_balances('xpubSynthetic', derive='legacy')
|
|
85
|
+
|
|
86
|
+
assert result.status_code == 400
|
|
87
|
+
assert [request.url for request in requests_mock.request_history] == [url]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.mark.parametrize('derive', ['legacy', 'compat', 'segwit'])
|
|
91
|
+
def test_xpub_explicit_derivation(requests_mock, haskoin_xpub_response, derive):
|
|
92
|
+
url = f'https://api.haskoin.com/btc/xpub/{xpub_test_address}?derive={derive}'
|
|
93
|
+
requests_mock.get(url, complete_qs=True, text=haskoin_xpub_response)
|
|
94
|
+
|
|
95
|
+
result = HaskoinApi().fetch_balances(xpub_test_address, derive=derive)
|
|
96
|
+
|
|
97
|
+
assert result.status_code == 200
|
|
98
|
+
assert result.data['balance']['confirmed'] == 12706308
|
|
99
|
+
assert requests_mock.call_count == 1
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def test_cannot_override_zpub_derivation(requests_mock):
|
|
103
|
+
result = HaskoinApi().fetch_balances(zpub_test_address, derive='legacy')
|
|
104
|
+
|
|
105
|
+
assert result.errors
|
|
106
|
+
assert requests_mock.call_count == 0
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_xpub_preserves_unrelated_bad_request(requests_mock):
|
|
110
|
+
url = f'https://api.haskoin.com/btc/xpub/{xpub_test_address}'
|
|
111
|
+
requests_mock.get(url, status_code=400, reason='Bad Request')
|
|
112
|
+
|
|
113
|
+
result = HaskoinApi().fetch_balances(xpub_test_address)
|
|
114
|
+
|
|
115
|
+
assert result.errors == ['Bad Request']
|
|
116
|
+
assert requests_mock.call_count == 1
|
|
117
|
+
|
|
118
|
+
|
|
45
119
|
def test_fetch_only(requests_mock, haskoin_balance_response):
|
|
46
120
|
requests_mock.get(
|
|
47
121
|
f'https://api.haskoin.com/btc/address/{btc_test_address}/balance',
|
|
@@ -97,6 +97,9 @@ COINGECKO_IDS_BY_CONTRACTS: list[CoingeckoMapping] = [
|
|
|
97
97
|
CoingeckoMapping(symbol='FTM', coingecko_id=CoingeckoId.FANTOM, contracts={'ftm'}),
|
|
98
98
|
CoingeckoMapping(symbol='FUSE', coingecko_id=CoingeckoId.FUSE, contracts={'fuse'}),
|
|
99
99
|
CoingeckoMapping(symbol='ONE', coingecko_id=CoingeckoId.HARMONY, contracts={'hmy'}),
|
|
100
|
+
CoingeckoMapping(
|
|
101
|
+
symbol='HYPE', coingecko_id=CoingeckoId.HYPERLIQUID, contracts={'elysium'}
|
|
102
|
+
),
|
|
100
103
|
CoingeckoMapping(
|
|
101
104
|
symbol='IOTX', coingecko_id=CoingeckoId.IOTEX, contracts={'iotex'}
|
|
102
105
|
),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from typing import Literal, Optional
|
|
2
|
+
|
|
1
3
|
import base58
|
|
2
4
|
|
|
3
5
|
from blockapi.v2.base import BalanceMixin, BlockchainApi
|
|
@@ -11,6 +13,8 @@ from blockapi.v2.models import (
|
|
|
11
13
|
ParseResult,
|
|
12
14
|
)
|
|
13
15
|
|
|
16
|
+
Derivation = Literal['legacy', 'compat', 'segwit']
|
|
17
|
+
|
|
14
18
|
# Version bytes for extended public keys (BIP32)
|
|
15
19
|
_XPUB_VERSION = bytes.fromhex('0488B21E')
|
|
16
20
|
_YPUB_VERSION = bytes.fromhex('049D7CB2')
|
|
@@ -51,22 +55,37 @@ class HaskoinApi(BlockchainApi, BalanceMixin):
|
|
|
51
55
|
'get_balance_xpub': 'xpub/{address}',
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
def fetch_balances(
|
|
58
|
+
def fetch_balances(
|
|
59
|
+
self, address: str, *, derive: Optional[Derivation] = None
|
|
60
|
+
) -> FetchResult:
|
|
61
|
+
"""Follow Haskoin's SegWit hint once for a plain xpub without a derive override."""
|
|
55
62
|
prefix = address[:4]
|
|
56
|
-
derive
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'get_balance_xpub',
|
|
62
|
-
params={'derive': derive},
|
|
63
|
-
address=xpub,
|
|
63
|
+
if derive is not None and (
|
|
64
|
+
prefix != 'xpub' or derive not in ('legacy', 'compat', 'segwit')
|
|
65
|
+
):
|
|
66
|
+
return FetchResult(
|
|
67
|
+
errors=['derive requires an xpub and legacy, compat, or segwit']
|
|
64
68
|
)
|
|
65
69
|
|
|
66
|
-
if prefix
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
if prefix in _DERIVE_TYPES:
|
|
71
|
+
derive = _DERIVE_TYPES[prefix]
|
|
72
|
+
address = _to_xpub(address)
|
|
73
|
+
elif prefix != 'xpub':
|
|
74
|
+
return self.get_data('get_balance', address=address)
|
|
75
|
+
|
|
76
|
+
if derive is None:
|
|
77
|
+
result = self.get_data('get_balance_xpub', address=address)
|
|
78
|
+
if result.status_code != 400 or not any(
|
|
79
|
+
'ask with derive=segwit.' in error for error in result.errors or []
|
|
80
|
+
):
|
|
81
|
+
return result
|
|
82
|
+
if self.sleep_provider:
|
|
83
|
+
self.sleep_provider.sleep(self.base_url, self.api_options.rate_limit)
|
|
84
|
+
derive = 'segwit'
|
|
85
|
+
|
|
86
|
+
return self.get_data(
|
|
87
|
+
'get_balance_xpub', params={'derive': derive}, address=address
|
|
88
|
+
)
|
|
70
89
|
|
|
71
90
|
def parse_balances(self, fetch_result: FetchResult) -> ParseResult:
|
|
72
91
|
if not fetch_result.data:
|
|
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
|
|
File without changes
|
|
File without changes
|