Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ coverage.xml
# IDE
.idea
.code
.vscode/
/integration-test/.env
/integration-test/tmp_configs/*
/integration-test/.coverage*
44 changes: 34 additions & 10 deletions pycardano/backend/ogmios_v6.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ def __init__(
utxo_cache_size: int = 10000,
datum_cache_size: int = 10000,
network: Network = Network.TESTNET,
additional_headers: Optional[dict] = None,
):
self.host = host
self.port = port
self.path = path
self.secure = secure
self.additional_headers = additional_headers or {}
self._network = network
self._service_name = "ogmios"
self._last_known_block_slot = 0
Expand All @@ -86,26 +88,36 @@ def __init__(
self._datum_cache = LRUCache(maxsize=datum_cache_size)

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

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

def _query_chain_tip(self) -> OgmiosTip:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) 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.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) 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.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) as client:
utxos, _ = client.query_utxo.execute(
[OgmiosTxOutputReference(tx_id, index)]
)
Expand Down Expand Up @@ -135,7 +147,9 @@ def protocol_param(self) -> ProtocolParameters:
return self._protocol_param

def _fetch_protocol_param(self) -> ProtocolParameters:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) 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 +219,9 @@ 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.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) as client:
return OgmiosGenesisParameters(client, self._query_current_era())

@property
Expand Down Expand Up @@ -310,7 +326,9 @@ def utxo_by_tx_id(self, tx_id: str, index: int) -> Optional[UTxO]:
def query_account_reward_summaries(
self, scripts: Optional[List[str]] = None, keys: Optional[List[str]] = None
) -> List[dict]:
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) as client:
summaries, _ = client.query_reward_account_summaries.execute(
scripts=scripts, keys=keys
)
Expand All @@ -319,13 +337,17 @@ def query_account_reward_summaries(
def submit_tx_cbor(self, cbor: Union[bytes, str]):
if isinstance(cbor, bytes):
cbor = cbor.hex()
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) 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.path, self.secure) as client:
with OgmiosClient(
self.host, self.port, self.path, self.secure, self.additional_headers
) as client:
result, _ = client.evaluate_transaction.execute(cbor)
result_dict = {}
for res in result:
Expand Down Expand Up @@ -380,6 +402,7 @@ def KupoOgmiosV6ChainContext(
utxo_cache_size: int = 10000,
datum_cache_size: int = 10000,
network: Network = Network.TESTNET,
additional_headers: Optional[dict] = None,
kupo_url: Optional[str] = None,
) -> KupoChainContextExtension:
return KupoChainContextExtension(
Expand All @@ -392,6 +415,7 @@ def KupoOgmiosV6ChainContext(
utxo_cache_size,
datum_cache_size,
network,
additional_headers,
),
kupo_url,
)
Loading