Skip to content

Commit

Permalink
For #307 - removed some _script=true conditions; utilizing bytecode f…
Browse files Browse the repository at this point in the history
…lag value in more spots
  • Loading branch information
Greg B authored and rdlrt committed Nov 19, 2024
1 parent 9c6d76e commit 9e6517d
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions files/grest/rpc/transactions/tx_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ BEGIN
(CASE WHEN tx_out.inline_datum_id IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
'bytes', ENCODE(datum.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(datum.bytes, 'hex') ELSE NULL END,
'value', datum.value
)
END
Expand All @@ -118,7 +118,7 @@ BEGIN
ELSE
JSONB_BUILD_OBJECT(
'hash', ENCODE(script.hash, 'hex'),
'bytes', ENCODE(script.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(script.bytes, 'hex') ELSE NULL END,
'value', script.json,
'type', script.type::text,
'size', script.serialised_size
Expand All @@ -137,7 +137,7 @@ BEGIN
LEFT JOIN datum ON _scripts IS TRUE AND datum.id = tx_out.inline_datum_id
LEFT JOIN script ON _scripts IS TRUE AND script.id = tx_out.reference_script_id
WHERE
(_inputs IS TRUE AND _scripts IS TRUE)
(_inputs IS TRUE)
AND collateral_tx_in.tx_in_id = ANY(_tx_id_list)
),

Expand Down Expand Up @@ -165,7 +165,7 @@ BEGIN
(CASE WHEN tx_out.inline_datum_id IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
'bytes', ENCODE(datum.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(datum.bytes, 'hex') ELSE NULL END,
'value', datum.value
)
END
Expand All @@ -174,7 +174,7 @@ BEGIN
ELSE
JSONB_BUILD_OBJECT(
'hash', ENCODE(script.hash, 'hex'),
'bytes', ENCODE(script.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(script.bytes, 'hex') ELSE NULL END,
'value', script.json,
'type', script.type::text,
'size', script.serialised_size
Expand All @@ -193,7 +193,7 @@ BEGIN
LEFT JOIN datum ON _scripts IS TRUE AND datum.id = tx_out.inline_datum_id
LEFT JOIN script ON _scripts IS TRUE AND script.id = tx_out.reference_script_id
WHERE
(_inputs IS TRUE AND _scripts IS TRUE)
(_inputs IS TRUE)
AND reference_tx_in.tx_in_id = ANY(_tx_id_list)
),

Expand Down Expand Up @@ -221,7 +221,7 @@ BEGIN
(CASE WHEN tx_out.inline_datum_id IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
'bytes', ENCODE(datum.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(datum.bytes, 'hex') ELSE NULL END,
'value', datum.value
)
END
Expand All @@ -230,7 +230,7 @@ BEGIN
ELSE
JSONB_BUILD_OBJECT(
'hash', ENCODE(script.hash, 'hex'),
'bytes', ENCODE(script.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(script.bytes, 'hex') ELSE NULL END,
'value', script.json,
'type', script.type::text,
'size', script.serialised_size
Expand Down Expand Up @@ -263,7 +263,7 @@ BEGIN
(CASE WHEN tx_out.inline_datum_id IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
'bytes', ENCODE(datum.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(datum.bytes, 'hex') ELSE NULL END,
'value', datum.value
)
END
Expand All @@ -272,7 +272,7 @@ BEGIN
ELSE
JSONB_BUILD_OBJECT(
'hash', ENCODE(script.hash, 'hex'),
'bytes', ENCODE(script.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(script.bytes, 'hex') ELSE NULL END,
'value', script.json,
'type', script.type::text,
'size', script.serialised_size
Expand All @@ -287,8 +287,7 @@ BEGIN
LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id
LEFT JOIN datum ON _scripts IS TRUE AND datum.id = tx_out.inline_datum_id
LEFT JOIN script ON _scripts IS TRUE AND script.id = tx_out.reference_script_id
WHERE _scripts IS TRUE
AND tx_out.tx_id = ANY(_tx_id_list)
WHERE tx_out.tx_id = ANY(_tx_id_list)
),

_all_outputs AS (
Expand All @@ -315,7 +314,7 @@ BEGIN
(CASE WHEN tx_out.inline_datum_id IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
'bytes', ENCODE(datum.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(datum.bytes, 'hex') ELSE NULL END,
'value', datum.value
)
END
Expand All @@ -324,7 +323,7 @@ BEGIN
ELSE
JSONB_BUILD_OBJECT(
'hash', ENCODE(script.hash, 'hex'),
'bytes', ENCODE(script.bytes, 'hex'),
'bytes', CASE WHEN _bytecode IS TRUE THEN ENCODE(script.bytes, 'hex') ELSE NULL END,
'value', script.json,
'type', script.type::text,
'size', script.serialised_size
Expand Down Expand Up @@ -949,7 +948,7 @@ BEGIN
'asset_list', COALESCE(JSONB_AGG(asset_list) FILTER (WHERE asset_list IS NOT NULL), JSONB_BUILD_ARRAY())
) AS tx_collateral_inputs
FROM _all_collateral_inputs AS aci
WHERE (_inputs IS TRUE AND _scripts IS TRUE) AND aci.tx_id = atx.id
WHERE (_inputs IS TRUE) AND aci.tx_id = atx.id
GROUP BY payment_addr_bech32, payment_addr_cred, stake_addr, aci.tx_hash, tx_index, value, datum_hash, inline_datum, reference_script
) AS tmp
), JSONB_BUILD_ARRAY()),
Expand All @@ -970,7 +969,7 @@ BEGIN
'asset_list', asset_descr
) AS tx_collateral_outputs
FROM _all_collateral_outputs AS aco
WHERE _scripts IS TRUE AND aco.tx_id = atx.id
WHERE aco.tx_id = atx.id
GROUP BY payment_addr_bech32, payment_addr_cred, stake_addr, aco.tx_hash, tx_index, value, datum_hash, inline_datum, reference_script, asset_descr
LIMIT 1 -- there can only be one collateral output
),
Expand All @@ -993,7 +992,7 @@ BEGIN
'asset_list', COALESCE(JSONB_AGG(asset_list) FILTER (WHERE asset_list IS NOT NULL), JSONB_BUILD_ARRAY())
) AS tx_reference_inputs
FROM _all_reference_inputs AS ari
WHERE (_inputs IS TRUE AND _scripts IS TRUE) AND ari.tx_id = atx.id
WHERE (_inputs IS TRUE) AND ari.tx_id = atx.id
GROUP BY payment_addr_bech32, payment_addr_cred, stake_addr, ari.tx_hash, tx_index, value, datum_hash, inline_datum, reference_script
) AS tmp
), JSONB_BUILD_ARRAY()),
Expand Down

0 comments on commit 9e6517d

Please sign in to comment.