Skip to content
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

tx_info: new logic for spend contracts mapping to inputs #278

Merged
merged 2 commits into from
Apr 25, 2024
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
44 changes: 38 additions & 6 deletions files/grest/rpc/transactions/tx_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ BEGIN
ENCODE(tx.hash, 'hex') AS tx_hash,
tx_out.index AS tx_index,
tx_out.value::text AS value,
ENCODE(tx_out.data_hash, 'hex') AS datum_hash,
tx_out.data_hash AS datum_hash,
(CASE WHEN ma.policy IS NULL THEN NULL
ELSE
JSONB_BUILD_OBJECT(
Expand Down Expand Up @@ -652,17 +652,37 @@ BEGIN
WHERE redeemer.tx_id = ANY(_tx_id_list)
),

_all_inputs_sorted AS (
SELECT
ROW_NUMBER () OVER (
PARTITION BY ai.tx_id
ORDER BY ai.tx_hash, ai.tx_index
) - 1 AS sorted_index,
ai.*
FROM (
SELECT DISTINCT ON (_ai.tx_hash, _ai.tx_index)
_ai.tx_id,
_ai.tx_hash,
_ai.tx_index,
_ai.payment_addr_bech32 as address,
_ai.datum_hash
from _all_inputs as _ai
) as ai
),

spend_redeemers AS (
SELECT DISTINCT ON (redeemer.id)
redeemer.id,
inutxo.address,
ais.address,
ais.tx_hash,
ais.tx_index,
ind.hash AS ind_hash,
ind.value AS ind_value
FROM redeemer
INNER JOIN tx_out AS inutxo ON inutxo.consumed_by_tx_id = redeemer.tx_id
INNER JOIN script ON redeemer.script_hash = inutxo.payment_cred
INNER JOIN datum AS ind ON ind.hash = inutxo.data_hash
INNER JOIN _all_inputs_sorted AS ais ON ais.tx_id = redeemer.tx_id AND ais.sorted_index = redeemer.index
INNER JOIN datum AS ind ON ind.hash = ais.datum_hash
WHERE redeemer.tx_id = ANY(_tx_id_list)
AND redeemer.purpose = 'spend'
)

SELECT
Expand All @@ -673,6 +693,18 @@ BEGIN
WHEN ar.purpose = 'spend' THEN
(SELECT address FROM spend_redeemers AS sr WHERE sr.id = ar.id)
END,
'spends_input',
CASE
WHEN ar.purpose = 'spend' THEN
(
SELECT JSONB_BUILD_OBJECT(
'tx_hash', sr.tx_hash,
'tx_index', sr.tx_index
)
FROM spend_redeemers AS sr
WHERE sr.id = ar.id
)
END,
'script_hash', ENCODE(ar.script_hash, 'hex'),
'bytecode', ENCODE(ar.script_bytes, 'hex'),
'size', ar.script_serialised_size,
Expand Down Expand Up @@ -800,7 +832,7 @@ BEGIN
'tx_hash', ai.tx_hash,
'tx_index', tx_index,
'value', value,
'datum_hash', datum_hash,
'datum_hash', ENCODE(datum_hash, 'hex'),
'inline_datum', inline_datum,
'reference_script', reference_script,
'asset_list', COALESCE(JSONB_AGG(asset_list) FILTER (WHERE asset_list IS NOT NULL), JSONB_BUILD_ARRAY())
Expand Down
10 changes: 10 additions & 0 deletions specs/results/koiosapi-guild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,16 @@ components:
- 'null'
description: Plutus script address
example: addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
spends_input:
type:
- object
- 'null'
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
tx_index:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_index"
description: Input utxo this contract spends
script_hash:
$ref: "#/components/schemas/script_info/items/properties/script_hash"
bytecode:
Expand Down
10 changes: 10 additions & 0 deletions specs/results/koiosapi-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,16 @@ components:
- 'null'
description: Plutus script address
example: addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
spends_input:
type:
- object
- 'null'
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
tx_index:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_index"
description: Input utxo this contract spends
script_hash:
$ref: "#/components/schemas/script_info/items/properties/script_hash"
bytecode:
Expand Down
10 changes: 10 additions & 0 deletions specs/results/koiosapi-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,16 @@ components:
- 'null'
description: Plutus script address
example: addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
spends_input:
type:
- object
- 'null'
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
tx_index:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_index"
description: Input utxo this contract spends
script_hash:
$ref: "#/components/schemas/script_info/items/properties/script_hash"
bytecode:
Expand Down
10 changes: 10 additions & 0 deletions specs/results/koiosapi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4021,6 +4021,16 @@ components:
- 'null'
description: Plutus script address
example: addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
spends_input:
type:
- object
- 'null'
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
tx_index:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_index"
description: Input utxo this contract spends
script_hash:
$ref: "#/components/schemas/script_info/items/properties/script_hash"
bytecode:
Expand Down
10 changes: 10 additions & 0 deletions specs/templates/4-api-schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,16 @@ schemas:
- 'null'
description: Plutus script address
example: addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
spends_input:
type:
- object
- 'null'
properties:
tx_hash:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_hash"
tx_index:
$ref: "#/components/schemas/utxo_infos/items/properties/tx_index"
description: Input utxo this contract spends
script_hash:
$ref: "#/components/schemas/script_info/items/properties/script_hash"
bytecode:
Expand Down
Loading