Skip to content

Commit ac95e68

Browse files
REFACTOR. provide all required values for ProtocolParameters in the instantiation step
1 parent 142369d commit ac95e68

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pycardano/backend/ogmios.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _fetch_protocol_param(self) -> ProtocolParameters:
151151
extra_entropy=result.get("extraEntropy", ""),
152152
protocol_major_version=result["protocolVersion"]["major"],
153153
protocol_minor_version=result["protocolVersion"]["minor"],
154+
min_utxo=self._get_min_utxo(),
154155
min_pool_cost=result["minPoolCost"],
155156
price_mem=self._fraction_parser(result["prices"]["memory"]),
156157
price_step=self._fraction_parser(result["prices"]["steps"]),
@@ -165,17 +166,24 @@ def _fetch_protocol_param(self) -> ProtocolParameters:
165166
"coinsPerUtxoWord", ALONZO_COINS_PER_UTXO_WORD
166167
),
167168
coins_per_utxo_byte=result.get("coinsPerUtxoByte", 0),
168-
cost_models=result.get("costModels", {}),
169+
cost_models=self._parse_cost_models(result),
169170
)
170171

171-
if "plutus:v1" in param.cost_models:
172-
param.cost_models["PlutusV1"] = param.cost_models.pop("plutus:v1")
173-
if "plutus:v2" in param.cost_models:
174-
param.cost_models["PlutusV2"] = param.cost_models.pop("plutus:v2")
172+
return param
175173

174+
def _get_min_utxo(self) -> int:
176175
result = self._query_genesis_config()
177-
param.min_utxo = result["protocolParameters"]["minUtxoValue"]
178-
return param
176+
return result["protocolParameters"]["minUtxoValue"]
177+
178+
def _parse_cost_models(self, ogmios_result: JSON) -> Dict[str, Dict[str, int]]:
179+
ogmios_cost_models = ogmios_result.get("costModels", {})
180+
181+
cost_models = {}
182+
if "plutus:v1" in ogmios_cost_models:
183+
cost_models["PlutusV1"] = ogmios_cost_models["plutus:v1"].copy()
184+
if "plutus:v2" in ogmios_cost_models:
185+
cost_models["PlutusV2"] = ogmios_cost_models["plutus:v2"].copy()
186+
return cost_models
179187

180188
@property
181189
def genesis_param(self) -> GenesisParameters:

0 commit comments

Comments
 (0)