Skip to content

Commit 345f62d

Browse files
REFACTOR. renaming JSON type to JsonDict to infer JSON object is represented
1 parent 7373fd1 commit 345f62d

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

pycardano/backend/blockfrost.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
UTxO,
3030
Value,
3131
)
32-
from pycardano.types import JSON
32+
from pycardano.types import JsonDict
3333

3434
__all__ = ["BlockFrostChainContext"]
3535

@@ -148,9 +148,9 @@ def _get_script(
148148
cbor2.loads(bytes.fromhex(self.api.script_cbor(script_hash).cbor))
149149
)
150150
else:
151-
script_json: JSON = self.api.script_json(script_hash, return_type="json")[
152-
"json"
153-
]
151+
script_json: JsonDict = self.api.script_json(
152+
script_hash, return_type="json"
153+
)["json"]
154154
return NativeScript.from_dict(script_json)
155155

156156
def utxos(self, address: str) -> List[UTxO]:

pycardano/backend/ogmios.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
UTxO,
3030
Value,
3131
)
32-
from pycardano.types import JSON
32+
from pycardano.types import JsonDict
3333

3434
__all__ = ["OgmiosChainContext"]
3535

@@ -64,7 +64,7 @@ def __init__(
6464
self._genesis_param = None
6565
self._protocol_param = None
6666

67-
def _request(self, method: OgmiosQueryType, args: JSON) -> Any:
67+
def _request(self, method: OgmiosQueryType, args: JsonDict) -> Any:
6868
ws = websocket.WebSocket()
6969
ws.connect(self._ws_url)
7070
request = json.dumps(
@@ -86,27 +86,27 @@ def _request(self, method: OgmiosQueryType, args: JSON) -> Any:
8686
)
8787
return json.loads(response)["result"]
8888

89-
def _query_current_protocol_params(self) -> JSON:
89+
def _query_current_protocol_params(self) -> JsonDict:
9090
args = {"query": "currentProtocolParameters"}
9191
return self._request(OgmiosQueryType.Query, args)
9292

93-
def _query_genesis_config(self) -> JSON:
93+
def _query_genesis_config(self) -> JsonDict:
9494
args = {"query": "genesisConfig"}
9595
return self._request(OgmiosQueryType.Query, args)
9696

9797
def _query_current_epoch(self) -> int:
9898
args = {"query": "currentEpoch"}
9999
return self._request(OgmiosQueryType.Query, args)
100100

101-
def _query_chain_tip(self) -> JSON:
101+
def _query_chain_tip(self) -> JsonDict:
102102
args = {"query": "chainTip"}
103103
return self._request(OgmiosQueryType.Query, args)
104104

105-
def _query_utxos_by_address(self, address: str) -> List[List[JSON]]:
105+
def _query_utxos_by_address(self, address: str) -> List[List[JsonDict]]:
106106
args = {"query": {"utxo": [address]}}
107107
return self._request(OgmiosQueryType.Query, args)
108108

109-
def _query_utxos_by_tx_id(self, tx_id: str, index: int) -> List[List[JSON]]:
109+
def _query_utxos_by_tx_id(self, tx_id: str, index: int) -> List[List[JsonDict]]:
110110
args = {"query": {"utxo": [{"txId": tx_id, "index": index}]}}
111111
return self._request(OgmiosQueryType.Query, args)
112112

@@ -173,7 +173,7 @@ def _get_min_utxo(self) -> int:
173173
result = self._query_genesis_config()
174174
return result["protocolParameters"]["minUtxoValue"]
175175

176-
def _parse_cost_models(self, ogmios_result: JSON) -> Dict[str, Dict[str, int]]:
176+
def _parse_cost_models(self, ogmios_result: JsonDict) -> Dict[str, Dict[str, int]]:
177177
ogmios_cost_models = ogmios_result.get("costModels", {})
178178

179179
cost_models = {}

pycardano/nativescript.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pycardano.exception import DeserializeException
1212
from pycardano.hash import SCRIPT_HASH_SIZE, ScriptHash, VerificationKeyHash
1313
from pycardano.serialization import ArrayCBORSerializable, Primitive, list_hook
14-
from pycardano.types import JSON
14+
from pycardano.types import JsonDict
1515

1616
__all__ = [
1717
"NativeScript",
@@ -58,7 +58,7 @@ def hash(self) -> ScriptHash:
5858

5959
@classmethod
6060
def from_dict(
61-
cls: Type[NativeScript], script_json: JSON
61+
cls: Type[NativeScript], script_json: JsonDict
6262
) -> Union[
6363
ScriptPubkey, ScriptAll, ScriptAny, ScriptNofK, InvalidBefore, InvalidHereAfter
6464
]:
@@ -82,7 +82,7 @@ def from_dict(
8282

8383
@classmethod
8484
def _script_json_to_primitive(
85-
cls: Type[NativeScript], script_json: JSON
85+
cls: Type[NativeScript], script_json: JsonDict
8686
) -> List[Primitive]:
8787
"""Serialize a standard JSON native script into a primitive array"""
8888

@@ -112,7 +112,7 @@ def _script_json_to_primitive(
112112

113113
@classmethod
114114
def _script_jsons_to_primitive(
115-
cls: Type[NativeScript], script_jsons: List[JSON]
115+
cls: Type[NativeScript], script_jsons: List[JsonDict]
116116
) -> List[List[Primitive]]:
117117
"""Parse a list of JSON scripts into a list of primitive arrays"""
118118
native_script = [cls._script_json_to_primitive(i) for i in script_jsons]

pycardano/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from typing import Any, Dict
22

3-
JSON = Dict[str, Any]
3+
# https://github.com/python/typing/issues/182#issuecomment-199532520
4+
JsonDict = Dict[str, Any]

0 commit comments

Comments
 (0)