Skip to content

Commit 92975df

Browse files
authored
Fix parsing of multiple asset that has an empty asset name in Ogmios (#238)
1 parent ec8722f commit 92975df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pycardano/backend/ogmios.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,15 @@ def _check_utxo_unspent(self, tx_id: str, index: int) -> bool:
403403
return len(results) > 0
404404

405405
def _extract_asset_info(self, asset_hash: str) -> Tuple[str, ScriptHash, AssetName]:
406-
policy_hex, asset_name_hex = asset_hash.split(".")
406+
split_result = asset_hash.split(".")
407+
408+
if len(split_result) == 1:
409+
policy_hex, asset_name_hex = split_result[0], ""
410+
elif len(split_result) == 2:
411+
policy_hex, asset_name_hex = split_result
412+
else:
413+
raise ValueError(f"Unable to parse asset hash: {asset_hash}")
414+
407415
policy = ScriptHash.from_primitive(policy_hex)
408416
asset_name = AssetName.from_primitive(asset_name_hex)
409417

test/pycardano/backend/test_ogmios.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"126b8676446c84a5cd6e3259223b16a2314c5676b88ae1c1f8579a8f.744d494e": 762462,
7777
"57fca08abbaddee36da742a839f7d83a7e1d2419f1507fcbf3916522.43484f43": 9945000,
7878
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3.53484942": 1419813131821,
79+
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3": 1234,
7980
},
8081
},
8182
"datum": None,
@@ -194,7 +195,8 @@ def test_utxo(self, chain_context):
194195
"43484f43": 9945000
195196
},
196197
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3": {
197-
"53484942": 1419813131821
198+
"53484942": 1419813131821,
199+
b"": 1234,
198200
},
199201
}
200202
)

0 commit comments

Comments
 (0)