@@ -104,6 +104,14 @@ def _query_chain_tip(self) -> JSON:
104
104
args = {"query" : "chainTip" }
105
105
return self ._request (OgmiosQueryType .Query , args )
106
106
107
+ def _query_utxos_by_address (self , address : str ) -> List [List [JSON ]]:
108
+ args = {"query" : {"utxo" : [address ]}}
109
+ return self ._request (OgmiosQueryType .Query , args )
110
+
111
+ def _query_utxos_by_tx_id (self , tx_id : str , index : int ) -> List [List [JSON ]]:
112
+ args = {"query" : {"utxo" : [{"txId" : tx_id , "index" : index }]}}
113
+ return self ._request (OgmiosQueryType .Query , args )
114
+
107
115
def _check_chain_tip_and_update (self ):
108
116
slot = self .last_block_slot
109
117
if self ._last_known_block_slot != slot :
@@ -211,28 +219,21 @@ def last_block_slot(self) -> int:
211
219
result = self ._query_chain_tip ()
212
220
return result ["slot" ]
213
221
214
- def _extract_asset_info (self , asset_hash : str ) -> Tuple [str , ScriptHash , AssetName ]:
215
- policy_hex , asset_name_hex = asset_hash .split ("." )
216
- policy = ScriptHash .from_primitive (policy_hex )
217
- asset_name = AssetName .from_primitive (asset_name_hex )
218
-
219
- return policy_hex , policy , asset_name
220
-
221
- def _check_utxo_unspent (self , tx_id : str , index : int ) -> bool :
222
- """Check whether an UTxO is unspent with Ogmios.
222
+ def utxos (self , address : str ) -> List [UTxO ]:
223
+ """Get all UTxOs associated with an address.
223
224
224
225
Args:
225
- tx_id (str): transaction id.
226
- index (int): transaction index.
227
- """
228
-
229
- args = {"query" : {"utxo" : [{"txId" : tx_id , "index" : index }]}}
230
- results = self ._request (OgmiosQueryType .Query , args )
226
+ address (str): An address encoded with bech32.
231
227
232
- if results :
233
- return True
228
+ Returns:
229
+ List[UTxO]: A list of UTxOs.
230
+ """
231
+ if self ._kupo_url :
232
+ utxos = self ._utxos_kupo (address )
234
233
else :
235
- return False
234
+ utxos = self ._utxos_ogmios (address )
235
+
236
+ return utxos
236
237
237
238
def _utxos_kupo (self , address : str ) -> List [UTxO ]:
238
239
"""Get all UTxOs associated with an address with Kupo.
@@ -302,6 +303,23 @@ def _utxos_kupo(self, address: str) -> List[UTxO]:
302
303
303
304
return utxos
304
305
306
+ def _check_utxo_unspent (self , tx_id : str , index : int ) -> bool :
307
+ """Check whether an UTxO is unspent with Ogmios.
308
+
309
+ Args:
310
+ tx_id (str): transaction id.
311
+ index (int): transaction index.
312
+ """
313
+ results = self ._query_utxos_by_tx_id (tx_id , index )
314
+ return len (results ) > 0
315
+
316
+ def _extract_asset_info (self , asset_hash : str ) -> Tuple [str , ScriptHash , AssetName ]:
317
+ policy_hex , asset_name_hex = asset_hash .split ("." )
318
+ policy = ScriptHash .from_primitive (policy_hex )
319
+ asset_name = AssetName .from_primitive (asset_name_hex )
320
+
321
+ return policy_hex , policy , asset_name
322
+
305
323
def _utxos_ogmios (self , address : str ) -> List [UTxO ]:
306
324
"""Get all UTxOs associated with an address with Ogmios.
307
325
@@ -311,12 +329,9 @@ def _utxos_ogmios(self, address: str) -> List[UTxO]:
311
329
Returns:
312
330
List[UTxO]: A list of UTxOs.
313
331
"""
314
-
315
- args = {"query" : {"utxo" : [address ]}}
316
- results = self ._request (OgmiosQueryType .Query , args )
332
+ results = self ._query_utxos_by_address (address )
317
333
318
334
utxos = []
319
-
320
335
for result in results :
321
336
in_ref = result [0 ]
322
337
output = result [1 ]
@@ -374,22 +389,6 @@ def _utxos_ogmios(self, address: str) -> List[UTxO]:
374
389
375
390
return utxos
376
391
377
- def utxos (self , address : str ) -> List [UTxO ]:
378
- """Get all UTxOs associated with an address.
379
-
380
- Args:
381
- address (str): An address encoded with bech32.
382
-
383
- Returns:
384
- List[UTxO]: A list of UTxOs.
385
- """
386
- if self ._kupo_url :
387
- utxos = self ._utxos_kupo (address )
388
- else :
389
- utxos = self ._utxos_ogmios (address )
390
-
391
- return utxos
392
-
393
392
def submit_tx (self , cbor : Union [bytes , str ]):
394
393
"""Submit a transaction to the blockchain.
395
394
0 commit comments