diff --git a/.gitignore b/.gitignore index c3dbfbd6..f9baeacd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ coverage.xml # IDE .idea .code +.vscode/ /integration-test/.env /integration-test/tmp_configs/* /integration-test/.coverage* \ No newline at end of file diff --git a/pycardano/backend/ogmios_v6.py b/pycardano/backend/ogmios_v6.py index 2fca989e..b0ff21cc 100644 --- a/pycardano/backend/ogmios_v6.py +++ b/pycardano/backend/ogmios_v6.py @@ -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 @@ -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)] ) @@ -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, @@ -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 @@ -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 ) @@ -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: @@ -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( @@ -392,6 +415,7 @@ def KupoOgmiosV6ChainContext( utxo_cache_size, datum_cache_size, network, + additional_headers, ), kupo_url, )