Skip to content

Commit bbae01d

Browse files
committed
Add warning when network type is passed to BlockFrostChainContext
The Cardano ledger specification only includes two network types: testnet and mainnet, which are utilized for address encoding. However, the BlockFrostChainContext should not rely on this network type as there are additional testnets, such as preview and preprod. To enhance the flexibility, the network parameter is being deprecated and replaced by directly passing the base_url for the network to the BlockFrostChainContext constructor.
1 parent 62898ce commit bbae01d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pycardano/backend/blockfrost.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import tempfile
33
import time
4+
import warnings
45
from typing import Dict, List, Optional, Union
56

67
import cbor2
@@ -40,6 +41,7 @@ class BlockFrostChainContext(ChainContext):
4041
Args:
4142
project_id (str): A BlockFrost project ID obtained from https://blockfrost.io.
4243
network (Network): Network to use.
44+
base_url (str): Base URL for the BlockFrost API. Defaults to the preprod url.
4345
"""
4446

4547
api: BlockFrostApi
@@ -49,9 +51,19 @@ class BlockFrostChainContext(ChainContext):
4951
_protocol_param: Optional[ProtocolParameters] = None
5052

5153
def __init__(
52-
self, project_id: str, network: Network = Network.TESTNET, base_url: str = ""
54+
self,
55+
project_id: str,
56+
network: Optional[Network] = None,
57+
base_url: str = ApiUrls.preprod.value,
5358
):
54-
self._network = network
59+
if network is not None:
60+
warnings.warn(
61+
"`network` argument will be deprecated in the future. Directly passing `base_url` is recommended."
62+
)
63+
self._network = network
64+
else:
65+
self._network = Network.TESTNET
66+
5567
self._project_id = project_id
5668
self._base_url = (
5769
base_url

0 commit comments

Comments
 (0)