Skip to content

Commit

Permalink
Add path to Ogmios v6 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
theeldermillenial committed Nov 16, 2024
1 parent b9829ee commit 9938b37
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pycardano/backend/ogmios_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self,
host: str = "localhost",
port: int = 1337,
path: str = "",
secure: bool = False,
refetch_chain_tip_interval: Optional[float] = None,
utxo_cache_size: int = 10000,
Expand All @@ -67,6 +68,7 @@ def __init__(
):
self.host = host
self.port = port
self.path = path

Check warning on line 71 in pycardano/backend/ogmios_v6.py

View check run for this annotation

Codecov / codecov/patch

pycardano/backend/ogmios_v6.py#L71

Added line #L71 was not covered by tests
self.secure = secure
self._network = network
self._service_name = "ogmios"
Expand All @@ -86,26 +88,26 @@ def __init__(
self._datum_cache = LRUCache(maxsize=datum_cache_size)

def _query_current_era(self) -> OgmiosEra:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
return get_current_era(client)

def _query_current_epoch(self) -> int:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
epoch, _ = client.query_epoch.execute()
return epoch

def _query_chain_tip(self) -> OgmiosTip:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
tip, _ = client.query_network_tip.execute()
return tip

def _query_utxos_by_address(self, address: Address) -> List[OgmiosUtxo]:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
utxos, _ = client.query_utxo.execute([address])
return utxos

def _query_utxos_by_tx_id(self, tx_id: str, index: int) -> List[OgmiosUtxo]:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
utxos, _ = client.query_utxo.execute(
[OgmiosTxOutputReference(tx_id, index)]
)
Expand Down Expand Up @@ -135,7 +137,7 @@ def protocol_param(self) -> ProtocolParameters:
return self._protocol_param

def _fetch_protocol_param(self) -> ProtocolParameters:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
protocol_parameters, _ = client.query_protocol_parameters.execute()
pyc_protocol_params = ProtocolParameters(
min_fee_constant=protocol_parameters.min_fee_constant.lovelace,
Expand Down Expand Up @@ -205,7 +207,7 @@ def genesis_param(self) -> GenesisParameters:
return self._genesis_param # type: ignore[return-value]

def _fetch_genesis_param(self) -> OgmiosGenesisParameters:
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
return OgmiosGenesisParameters(client, self._query_current_era())

@property
Expand Down Expand Up @@ -263,7 +265,7 @@ def _utxo_from_ogmios_result(self, utxo: OgmiosUtxo) -> UTxO:
# TODO: Need to test with native scripts
if script["language"] == "plutus:v3":
script = PlutusV3Script(bytes.fromhex(script["cbor"]))
elif script["language"] == "plutus:v2":
if script["language"] == "plutus:v2":
script = PlutusV2Script(bytes.fromhex(script["cbor"]))
elif script["language"] == "plutus:v1":
script = PlutusV1Script(bytes.fromhex(script["cbor"]))
Expand Down Expand Up @@ -311,13 +313,13 @@ def utxo_by_tx_id(self, tx_id: str, index: int) -> Optional[UTxO]:
def submit_tx_cbor(self, cbor: Union[bytes, str]):
if isinstance(cbor, bytes):
cbor = cbor.hex()
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
client.submit_transaction.execute(cbor)

def evaluate_tx_cbor(self, cbor: Union[bytes, str]) -> Dict[str, ExecutionUnits]:
if isinstance(cbor, bytes):
cbor = cbor.hex()
with OgmiosClient(self.host, self.port, self.secure) as client:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
result, _ = client.evaluate_transaction.execute(cbor)
result_dict = {}
for res in result:
Expand Down

0 comments on commit 9938b37

Please sign in to comment.