Skip to content

Fix parsing of multiple asset that has an empty asset name in Ogmios #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2023
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
10 changes: 9 additions & 1 deletion pycardano/backend/ogmios.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ def _check_utxo_unspent(self, tx_id: str, index: int) -> bool:
return len(results) > 0

def _extract_asset_info(self, asset_hash: str) -> Tuple[str, ScriptHash, AssetName]:
policy_hex, asset_name_hex = asset_hash.split(".")
split_result = asset_hash.split(".")

if len(split_result) == 1:
policy_hex, asset_name_hex = split_result[0], ""
elif len(split_result) == 2:
policy_hex, asset_name_hex = split_result
else:
raise ValueError(f"Unable to parse asset hash: {asset_hash}")

policy = ScriptHash.from_primitive(policy_hex)
asset_name = AssetName.from_primitive(asset_name_hex)

Expand Down
4 changes: 3 additions & 1 deletion test/pycardano/backend/test_ogmios.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"126b8676446c84a5cd6e3259223b16a2314c5676b88ae1c1f8579a8f.744d494e": 762462,
"57fca08abbaddee36da742a839f7d83a7e1d2419f1507fcbf3916522.43484f43": 9945000,
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3.53484942": 1419813131821,
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3": 1234,
},
},
"datum": None,
Expand Down Expand Up @@ -194,7 +195,8 @@ def test_utxo(self, chain_context):
"43484f43": 9945000
},
"fc3ef8db4a16c1959fbabfcbc3fb7669bf315967ffef260ececc47a3": {
"53484942": 1419813131821
"53484942": 1419813131821,
b"": 1234,
},
}
)
Expand Down