Skip to content

Commit 236cd45

Browse files
author
Patrick Dowd
committed
Support authenticated ogmios
1 parent 2122c39 commit 236cd45

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ coverage.xml
1010
# IDE
1111
.idea
1212
.code
13+
.vscode/
1314
/integration-test/.env
1415
/integration-test/tmp_configs/*
1516
/integration-test/.coverage*

pycardano/backend/ogmios_v6.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
host: str = "localhost",
5959
port: int = 1337,
6060
path: str = "",
61+
additional_headers: Optional[dict] = None,
6162
secure: bool = False,
6263
refetch_chain_tip_interval: Optional[float] = None,
6364
utxo_cache_size: int = 10000,
@@ -68,6 +69,7 @@ def __init__(
6869
self.port = port
6970
self.path = path
7071
self.secure = secure
72+
self.additional_headers = additional_headers or {}
7173
self._network = network
7274
self._service_name = "ogmios"
7375
self._last_known_block_slot = 0
@@ -86,26 +88,26 @@ def __init__(
8688
self._datum_cache = LRUCache(maxsize=datum_cache_size)
8789

8890
def _query_current_era(self) -> OgmiosEra:
89-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
91+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
9092
return get_current_era(client)
9193

9294
def _query_current_epoch(self) -> int:
93-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
95+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
9496
epoch, _ = client.query_epoch.execute()
9597
return epoch
9698

9799
def _query_chain_tip(self) -> OgmiosTip:
98-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
100+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
99101
tip, _ = client.query_network_tip.execute()
100102
return tip
101103

102104
def _query_utxos_by_address(self, address: Address) -> List[OgmiosUtxo]:
103-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
105+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
104106
utxos, _ = client.query_utxo.execute([address])
105107
return utxos
106108

107109
def _query_utxos_by_tx_id(self, tx_id: str, index: int) -> List[OgmiosUtxo]:
108-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
110+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
109111
utxos, _ = client.query_utxo.execute(
110112
[OgmiosTxOutputReference(tx_id, index)]
111113
)
@@ -135,7 +137,7 @@ def protocol_param(self) -> ProtocolParameters:
135137
return self._protocol_param
136138

137139
def _fetch_protocol_param(self) -> ProtocolParameters:
138-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
140+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
139141
protocol_parameters, _ = client.query_protocol_parameters.execute()
140142
pyc_protocol_params = ProtocolParameters(
141143
min_fee_constant=protocol_parameters.min_fee_constant.lovelace,
@@ -205,7 +207,7 @@ def genesis_param(self) -> GenesisParameters:
205207
return self._genesis_param # type: ignore[return-value]
206208

207209
def _fetch_genesis_param(self) -> OgmiosGenesisParameters:
208-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
210+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
209211
return OgmiosGenesisParameters(client, self._query_current_era())
210212

211213
@property
@@ -310,7 +312,7 @@ def utxo_by_tx_id(self, tx_id: str, index: int) -> Optional[UTxO]:
310312
def query_account_reward_summaries(
311313
self, scripts: Optional[List[str]] = None, keys: Optional[List[str]] = None
312314
) -> List[dict]:
313-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
315+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
314316
summaries, _ = client.query_reward_account_summaries.execute(
315317
scripts=scripts, keys=keys
316318
)
@@ -319,13 +321,13 @@ def query_account_reward_summaries(
319321
def submit_tx_cbor(self, cbor: Union[bytes, str]):
320322
if isinstance(cbor, bytes):
321323
cbor = cbor.hex()
322-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
324+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
323325
client.submit_transaction.execute(cbor)
324326

325327
def evaluate_tx_cbor(self, cbor: Union[bytes, str]) -> Dict[str, ExecutionUnits]:
326328
if isinstance(cbor, bytes):
327329
cbor = cbor.hex()
328-
with OgmiosClient(self.host, self.port, self.path, self.secure) as client:
330+
with OgmiosClient(self.host, self.port, self.path, self.secure, self.additional_headers) as client:
329331
result, _ = client.evaluate_transaction.execute(cbor)
330332
result_dict = {}
331333
for res in result:

0 commit comments

Comments
 (0)