Merge pull request #1851 from input-output-hk/fix_check_reference_txin_scripts
Fix db-sync checks of scripts in reference txin
Fix db-sync checks of scripts in reference txin
return hashes_db
def _get_script_data_hash(cluster_obj: clusterlib.ClusterLib, script_data: dict) -> str:
"""Get hash of the script data."""
script_file = Path(f"{helpers.get_timestamped_rand_str()}.script")
with open(script_file, "w", encoding="utf-8") as outfile:
json.dump(script_data, outfile)
return cluster_obj.g_transaction.get_policyid(script_file=script_file)
def _db_redeemer_hashes(
records: List[dbsync_types.RedeemerRecord],
) -> Dict[str, List[dbsync_types.RedeemerRecord]]:
response: dbsync_types.TxRecord,
) -> None:
"""Check that scripts in Tx read-only reference inputs match the data from db-sync."""
tx_hashes_txin = set()
for r in tx_raw_output.script_txins:
if r.reference_txin and r.reference_txin.reference_script:
script_file = Path(f"{helpers.get_timestamped_rand_str()}.script")
with open(script_file, "w", encoding="utf-8") as outfile:
json.dump(r.reference_txin.reference_script["script"], outfile)
tx_hashes_txin = {
_get_script_data_hash(
cluster_obj=cluster_obj, script_data=rt.reference_txin.reference_script["script"]
)
for rt in tx_raw_output.script_txins
if (rt.reference_txin and rt.reference_txin.reference_script)
}
tx_hashes_txin.add(cluster_obj.g_transaction.get_policyid(script_file=script_file))
db_hashes_txin = {
_get_script_data_hash(cluster_obj=cluster_obj, script_data=rd.reference_script)
for rd in response.reference_inputs
if rd.reference_script
}
# A script is added to `script` table only the first time it is seen, so the record
# can be empty for the current transaction.
db_reference_scripts = {r.hash for r in response.reference_scripts if r.hash}
if db_reference_scripts:
assert db_reference_scripts.issubset(
tx_hashes_txin
), f"Reference scripts txins don't match ({tx_hashes_txin} != {db_reference_scripts})"
assert (
tx_hashes_txin == db_hashes_txin
), f"Reference scripts txins don't match ({tx_hashes_txin} != {db_hashes_txin})"
def check_tx_required_signers(
address: str
value: decimal.Decimal
tx_hash: memoryview
reference_script_json: Optional[dict]
ma_tx_out_id: Optional[int]
ma_tx_out_policy: Optional[memoryview]
ma_tx_out_name: Optional[memoryview]
address: str
value: decimal.Decimal
tx_hash: memoryview
reference_script_json: Optional[dict]
class CollateralTxOutDBRow(NamedTuple):
"SELECT"
" tx_out.id, tx_out.index, tx_out.address, tx_out.value,"
" (SELECT hash FROM tx WHERE id = tx_out.tx_id) AS tx_hash,"
" (SELECT json FROM script WHERE id = tx_out.reference_script_id) AS reference_script_json,"
" ma_tx_out.id, join_ma_out.policy, join_ma_out.name, ma_tx_out.quantity "
"FROM tx_in "
"LEFT JOIN tx_out "
query = (
"SELECT"
" tx_out.id, tx_out.index, tx_out.address, tx_out.value,"
" (SELECT hash FROM tx WHERE id = tx_out.tx_id) AS tx_hash "
" (SELECT hash FROM tx WHERE id = tx_out.tx_id) AS tx_hash,"
" (SELECT json FROM script WHERE id = tx_out.reference_script_id) AS reference_script_json "
"FROM collateral_tx_in "
"LEFT JOIN tx_out "
"ON (tx_out.tx_id = collateral_tx_in.tx_out_id AND"
query = (
"SELECT "
" tx_out.id, tx_out.index, tx_out.address, tx_out.value,"
" (SELECT hash FROM tx WHERE id = tx_out.tx_id) AS tx_hash "
" (SELECT hash FROM tx WHERE id = tx_out.tx_id) AS tx_hash,"
" (SELECT json FROM script WHERE id = tx_out.reference_script_id) AS reference_script_json "
"FROM reference_tx_in "
"LEFT JOIN tx_out "
"ON (tx_out.tx_id = reference_tx_in.tx_out_id AND"
collateral_outputs: List[clusterlib.UTXOData]
reference_inputs: List[clusterlib.UTXOData]
scripts: List[ScriptRecord]
reference_scripts: List[ScriptRecord]
redeemers: List[RedeemerRecord]
metadata: List[MetadataRecord]
reserve: List[ADAStashRecord]
utxo_ix=int(txins_row.utxo_ix),
amount=int(txins_row.value),
address=str(txins_row.address),
reference_script=txins_row.reference_script_json,
)
)
amount=int(txins_row.ma_tx_out_quantity or 0),
address=str(txins_row.address),
coin=coin,
reference_script=txins_row.reference_script_json,
)
)
utxo_ix=int(r.utxo_ix),
amount=int(r.value),
address=str(r.address),
reference_script=r.reference_script_json,
)
for r in dbsync_queries.query_collateral_tx_ins(txhash=txhash)
]
utxo_ix=int(r.utxo_ix),
amount=int(r.value),
address=str(r.address),
reference_script=r.reference_script_json,
)
for r in dbsync_queries.query_reference_tx_ins(txhash=txhash)
]
for r in dbsync_queries.query_scripts(txhash=txhash)
]
# TODO: FIXME: this is not correct, this includes all scripts present in the TX that created
# the reference input, not just the ones IN the reference input
reference_scripts = []
if reference_inputs:
for reference_input in reference_inputs:
reference_scripts.extend(
[
dbsync_types.ScriptRecord(
hash=r.hash.hex(),
type=str(r.type),
serialised_size=int(r.serialised_size) if r.serialised_size else 0,
)
for r in dbsync_queries.query_scripts(txhash=reference_input.utxo_hash)
]
)
redeemers = []
if txdata.last_row.redeemer_count:
redeemers = [
collateral_outputs=collateral_outputs,
reference_inputs=reference_inputs,
scripts=scripts,
reference_scripts=reference_scripts,
redeemers=redeemers,
metadata=metadata,
reserve=reserve,
Maybe not needed anymore, but this honors the comment just above in project.nix which was put in place to fix static muslc builds.
plutus: 1.7 -> 1.9 Drop BundledProtocolParameters and ProtocolParameters in favour of PParams LedgerEra
Implement `tcTranslationContextL` for Shelley
# [0.10.0](https://github.com/input-output-hk/atala-prism-mediator/compare/prism-mediator-v0.9.2...prism-mediator-v0.10.0) (2023-09-21) ### Bug Fixes * Added DidSubject to report problem when not enrolled ([#111](https://github.com/input-output-hk/atala-prism-mediator/issues/111)) ([40c5d06](https://github.com/input-output-hk/atala-prism-mediator/commit/40c5d066840d2e0ae119fccee10d03bb10d7a5e9)) * Annotate Headers & Update zio-http to version 3.0.0-RC2 ([#106](https://github.com/input-output-hk/atala-prism-mediator/issues/106)) ([aa19f0a](https://github.com/input-output-hk/atala-prism-mediator/commit/aa19f0a1b9a547a562139b7c91373c1d84ddfa39)) * Encoder for VerificationMethodReferenced as String ([#110](https://github.com/input-output-hk/atala-prism-mediator/issues/110)) ([761d422](https://github.com/input-output-hk/atala-prism-mediator/commit/761d4227b8eef486fa12510814bb4c075f0b9c87)) * sign ProblemReport when TO is unspecified ([#105](https://github.com/input-output-hk/atala-prism-mediator/issues/105)) ([586dd9f](https://github.com/input-output-hk/atala-prism-mediator/commit/586dd9f1cce1763fd4cf5f1db93cf53f94740816)) * Update local docker-compose configuration by adding the SERVICE_ENDPOINT port ([#128](https://github.com/input-output-hk/atala-prism-mediator/issues/128)) ([2adc6aa](https://github.com/input-output-hk/atala-prism-mediator/commit/2adc6aac26593e0f868dfee2e81afae7c4337b32)) ### Features * add MediatorBuildInfo & /did and /version endpoints ([#120](https://github.com/input-output-hk/atala-prism-mediator/issues/120)) ([4445e1f](https://github.com/input-output-hk/atala-prism-mediator/commit/4445e1f3db5011264e2831cf12d1ed183406447d)) * add tag latest to the mediator docker image ([#118](https://github.com/input-output-hk/atala-prism-mediator/issues/118)) ([020f2cd](https://github.com/input-output-hk/atala-prism-mediator/commit/020f2cdff5e8e32ac8f880b7a87f0e0239c5ce34)) * Added test for executor and problem reports ([#117](https://github.com/input-output-hk/atala-prism-mediator/issues/117)) ([ce05d5a](https://github.com/input-output-hk/atala-prism-mediator/commit/ce05d5a0894ae0cee1eaba89bd5834182800e9ef))
Add new tx-view key name