From 3edfae500527825a423eeebd4f1e9e07a3761a19 Mon Sep 17 00:00:00 2001 From: rdlrt <3169068+rdlrt@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:28:17 +1100 Subject: [PATCH] [WIP - payment_creds & indexes pending] Update address references from tx_out to it's own table --- files/grest/rpc/account/account_addresses.sql | 6 ++++-- files/grest/rpc/account/account_utxos.sql | 3 ++- files/grest/rpc/address/address_assets.sql | 7 ++++--- files/grest/rpc/address/address_info.sql | 10 ++++++---- files/grest/rpc/address/address_txs.sql | 3 ++- files/grest/rpc/address/address_utxos.sql | 8 +++++--- files/grest/rpc/address/credential_utxos.sql | 3 ++- files/grest/rpc/assets/asset_addresses.sql | 6 ++++-- files/grest/rpc/assets/asset_nft_address.sql | 6 ++++-- files/grest/rpc/assets/asset_summary.sql | 3 ++- files/grest/rpc/assets/asset_utxos.sql | 3 ++- files/grest/rpc/assets/policy_asset_addresses.sql | 8 +++++--- files/grest/rpc/script/script_utxos.sql | 3 ++- files/grest/rpc/transactions/tx_info.sql | 15 ++++++++++----- files/grest/rpc/transactions/tx_utxos.sql | 6 ++++-- files/grest/rpc/transactions/utxo_info.sql | 3 ++- 16 files changed, 60 insertions(+), 33 deletions(-) diff --git a/files/grest/rpc/account/account_addresses.sql b/files/grest/rpc/account/account_addresses.sql index acffa3cb..512a2ffb 100644 --- a/files/grest/rpc/account/account_addresses.sql +++ b/files/grest/rpc/account/account_addresses.sql @@ -27,10 +27,11 @@ BEGIN FROM ( SELECT - txo.address, + a.address, txo.stake_address_id, txo.id FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = txo.address_id WHERE txo.stake_address_id = ANY(sa_id_list) AND txo.consumed_by_tx_id IS NULL ) AS x @@ -53,10 +54,11 @@ BEGIN FROM ( SELECT - txo.address, + a.address, txo.stake_address_id, txo.id FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = txo.address_id WHERE txo.stake_address_id = ANY(sa_id_list) LIMIT (CASE WHEN _first_only IS TRUE THEN 1 ELSE NULL END) ) AS x diff --git a/files/grest/rpc/account/account_utxos.sql b/files/grest/rpc/account/account_utxos.sql index e86f39f0..3d48755d 100644 --- a/files/grest/rpc/account/account_utxos.sql +++ b/files/grest/rpc/account/account_utxos.sql @@ -54,7 +54,7 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -89,6 +89,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id diff --git a/files/grest/rpc/address/address_assets.sql b/files/grest/rpc/address/address_assets.sql index fe990662..5079aa14 100644 --- a/files/grest/rpc/address/address_assets.sql +++ b/files/grest/rpc/address/address_assets.sql @@ -14,7 +14,7 @@ BEGIN WITH _all_assets AS ( SELECT - txo.address, + a.address, ma.policy, ma.name, ma.fingerprint, @@ -24,10 +24,11 @@ BEGIN INNER JOIN multi_asset AS ma ON ma.id = mtx.ident LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id INNER JOIN tx_out AS txo ON txo.id = mtx.tx_out_id - WHERE txo.address = ANY(_addresses) + INNER JOIN address AS a ON a.id = tx_out.address_id + WHERE a.address = ANY(_addresses) AND txo.consumed_by_tx_id IS NULL GROUP BY - txo.address, ma.policy, ma.name, ma.fingerprint, aic.decimals + a.address, ma.policy, ma.name, ma.fingerprint, aic.decimals ) SELECT diff --git a/files/grest/rpc/address/address_info.sql b/files/grest/rpc/address/address_info.sql index c5c9bb2f..47d9fd85 100644 --- a/files/grest/rpc/address/address_info.sql +++ b/files/grest/rpc/address/address_info.sql @@ -13,12 +13,13 @@ DECLARE BEGIN CREATE TEMPORARY TABLE _known_addresses AS SELECT - DISTINCT ON (tx_out.address) tx_out.address, + DISTINCT ON (tx_out.address_id) a.address, sa.hash_raw AS stake_address_raw, COALESCE(tx_out.address_has_script, 'false') AS script_address FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON sa.id = tx_out.stake_address_id - WHERE tx_out.address = ANY(_addresses); + WHERE a.address = ANY(_addresses); RETURN QUERY WITH _all_utxos AS ( @@ -26,7 +27,7 @@ BEGIN tx.id, tx.hash, tx_out.id AS txo_id, - tx_out.address, + a.address, tx_out.value, tx_out.index, tx.block_id, @@ -34,9 +35,10 @@ BEGIN tx_out.inline_datum_id, tx_out.reference_script_id FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN tx ON tx.id = tx_out.tx_id WHERE tx_out.consumed_by_tx_id IS NULL - AND tx_out.address = ANY(_addresses) + AND a.address = ANY(_addresses) ) SELECT diff --git a/files/grest/rpc/address/address_txs.sql b/files/grest/rpc/address/address_txs.sql index c8ccb464..ceaf59de 100644 --- a/files/grest/rpc/address/address_txs.sql +++ b/files/grest/rpc/address/address_txs.sql @@ -28,8 +28,9 @@ BEGIN -- SELECT consumed_by_tx_id FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id WHERE tx_out.consumed_by_tx_id IS NOT NULL - AND tx_out.address = ANY(_addresses) + AND a.address = ANY(_addresses) AND tx_out.consumed_by_tx_id >= _tx_id_min ) AS tmp; diff --git a/files/grest/rpc/address/address_utxos.sql b/files/grest/rpc/address/address_utxos.sql index 5cbc4363..91836141 100644 --- a/files/grest/rpc/address/address_utxos.sql +++ b/files/grest/rpc/address/address_utxos.sql @@ -35,17 +35,18 @@ BEGIN ) END) as assets FROM tx_out AS txo + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN ma_tx_out AS mto ON mto.tx_out_id = txo.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id - WHERE txo.address = ANY(_addresses) + WHERE a.address = ANY(_addresses) AND txo.consumed_by_tx_id IS NULL GROUP BY txo.id ) SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -79,13 +80,14 @@ BEGIN ELSE true END) AS is_spent FROM tx_out + INNER JOIN address AS a ON a.id = tx_out.address_id INNER JOIN tx ON tx_out.tx_id = tx.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id LEFT JOIN script ON script.id = tx_out.reference_script_id LEFT JOIN _assets ON tx_out.id = _assets.id - WHERE tx_out.address = ANY(_addresses) + WHERE a.address = ANY(_addresses) AND tx_out.consumed_by_tx_id IS NULL ; END; diff --git a/files/grest/rpc/address/credential_utxos.sql b/files/grest/rpc/address/credential_utxos.sql index 57bfe179..3df988ee 100644 --- a/files/grest/rpc/address/credential_utxos.sql +++ b/files/grest/rpc/address/credential_utxos.sql @@ -51,7 +51,7 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -86,6 +86,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + INNER JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id diff --git a/files/grest/rpc/assets/asset_addresses.sql b/files/grest/rpc/assets/asset_addresses.sql index 466bdc48..d707119d 100644 --- a/files/grest/rpc/assets/asset_addresses.sql +++ b/files/grest/rpc/assets/asset_addresses.sql @@ -33,11 +33,12 @@ BEGIN FROM ( SELECT - txo.address, + a.address, sa.hash_raw AS stake_address_raw, atoc.quantity FROM grest.asset_tx_out_cache AS atoc LEFT JOIN tx_out AS txo ON atoc.txo_id = txo.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE atoc.ma_id = _asset_id AND txo.consumed_by_tx_id IS NULL @@ -52,11 +53,12 @@ BEGIN FROM ( SELECT - txo.address, + a.address, sa.hash_raw AS stake_address_raw, mto.quantity FROM ma_tx_out AS mto LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE mto.ident = _asset_id AND txo.consumed_by_tx_id IS NULL diff --git a/files/grest/rpc/assets/asset_nft_address.sql b/files/grest/rpc/assets/asset_nft_address.sql index 2c5ca3f5..cd5949ad 100644 --- a/files/grest/rpc/assets/asset_nft_address.sql +++ b/files/grest/rpc/assets/asset_nft_address.sql @@ -27,9 +27,10 @@ BEGIN IF EXISTS (SELECT * FROM ma_tx_mint WHERE ident = _asset_id and quantity < 0 LIMIT 1) THEN RETURN QUERY SELECT - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE txo.id = ( SELECT MAX(tx_out_id) @@ -39,9 +40,10 @@ BEGIN ELSE RETURN QUERY SELECT - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address FROM tx_out AS txo + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN ma_tx_out mto ON mto.tx_out_id = txo.id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE mto.ident = _asset_id diff --git a/files/grest/rpc/assets/asset_summary.sql b/files/grest/rpc/assets/asset_summary.sql index 4c77e222..5f3016ba 100644 --- a/files/grest/rpc/assets/asset_summary.sql +++ b/files/grest/rpc/assets/asset_summary.sql @@ -32,10 +32,11 @@ BEGIN txo.tx_id AS tx_id, txo.id AS tx_out_id, txo.index AS tx_out_idx, - txo.address AS address, + a.address AS address, txo.stake_address_id AS sa_id FROM ma_tx_out AS mto INNER JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id WHERE mto.ident = _asset_id AND txo.consumed_by_tx_id IS NULL) diff --git a/files/grest/rpc/assets/asset_utxos.sql b/files/grest/rpc/assets/asset_utxos.sql index 25d5df08..005af3b2 100644 --- a/files/grest/rpc/assets/asset_utxos.sql +++ b/files/grest/rpc/assets/asset_utxos.sql @@ -64,7 +64,7 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw)::text as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -99,6 +99,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN _assets ON tx_out.id = _assets.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id diff --git a/files/grest/rpc/assets/policy_asset_addresses.sql b/files/grest/rpc/assets/policy_asset_addresses.sql index 6dc0f3ab..bfbc43ea 100644 --- a/files/grest/rpc/assets/policy_asset_addresses.sql +++ b/files/grest/rpc/assets/policy_asset_addresses.sql @@ -27,12 +27,13 @@ BEGIN ( SELECT atoc.ma_id, - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address, atoc.quantity FROM grest.asset_tx_out_cache AS atoc LEFT JOIN multi_asset AS ma ON ma.id = atoc.ma_id LEFT JOIN tx_out AS txo ON txo.id = atoc.txo_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE ma.policy = DECODE(_asset_policy, 'hex') AND txo.consumed_by_tx_id IS NULL @@ -46,18 +47,19 @@ BEGIN RETURN QUERY SELECT ENCODE(ma.name, 'hex') AS asset_name, - txo.address, + a.address, grest.cip5_hex_to_stake_addr(sa.hash_raw)::varchar AS stake_address, SUM(mto.quantity)::text FROM multi_asset AS ma LEFT JOIN ma_tx_out AS mto ON mto.ident = ma.id LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id WHERE ma.policy = DECODE(_asset_policy, 'hex') AND txo.consumed_by_tx_id IS NULL GROUP BY ma.name, - txo.address, + a.address, sa.hash_raw; END IF; END; diff --git a/files/grest/rpc/script/script_utxos.sql b/files/grest/rpc/script/script_utxos.sql index d5120bb3..573c4277 100644 --- a/files/grest/rpc/script/script_utxos.sql +++ b/files/grest/rpc/script/script_utxos.sql @@ -46,7 +46,7 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -81,6 +81,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id INNER JOIN script ON script.tx_id = tx.id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id diff --git a/files/grest/rpc/transactions/tx_info.sql b/files/grest/rpc/transactions/tx_info.sql index 7b5707f7..6797a9e7 100644 --- a/files/grest/rpc/transactions/tx_info.sql +++ b/files/grest/rpc/transactions/tx_info.sql @@ -88,7 +88,7 @@ BEGIN _all_collateral_inputs AS ( SELECT collateral_tx_in.tx_in_id AS tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -129,6 +129,7 @@ BEGIN INNER JOIN tx_out ON tx_out.tx_id = collateral_tx_in.tx_out_id AND tx_out.index = collateral_tx_in.tx_out_index INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -143,7 +144,7 @@ BEGIN _all_reference_inputs AS ( SELECT reference_tx_in.tx_in_id AS tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -184,6 +185,7 @@ BEGIN INNER JOIN tx_out ON tx_out.tx_id = reference_tx_in.tx_out_id AND tx_out.index = reference_tx_in.tx_out_index INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -198,7 +200,7 @@ BEGIN _all_inputs AS ( SELECT tx_out.consumed_by_tx_id AS tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -237,6 +239,7 @@ BEGIN ) AS reference_script FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident @@ -250,7 +253,7 @@ BEGIN _all_collateral_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -280,6 +283,7 @@ BEGIN FROM collateral_tx_out AS tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id 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 @@ -290,7 +294,7 @@ BEGIN _all_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -329,6 +333,7 @@ BEGIN ) AS reference_script FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON _assets IS TRUE AND mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON _assets IS TRUE AND ma.id = mto.ident diff --git a/files/grest/rpc/transactions/tx_utxos.sql b/files/grest/rpc/transactions/tx_utxos.sql index 6ac76a61..999302cc 100644 --- a/files/grest/rpc/transactions/tx_utxos.sql +++ b/files/grest/rpc/transactions/tx_utxos.sql @@ -39,7 +39,7 @@ BEGIN _all_inputs AS ( SELECT tx_out.consumed_by_tx_id AS tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -58,6 +58,7 @@ BEGIN ) AS asset_list FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident @@ -68,7 +69,7 @@ BEGIN _all_outputs AS ( SELECT tx_out.tx_id, - tx_out.address AS payment_addr_bech32, + a.address AS payment_addr_bech32, ENCODE(tx_out.payment_cred, 'hex') AS payment_addr_cred, grest.cip5_hex_to_stake_addr(sa.hash_raw) AS stake_addr, ENCODE(tx.hash, 'hex') AS tx_hash, @@ -87,6 +88,7 @@ BEGIN ) AS asset_list FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN ma_tx_out AS mto ON mto.tx_out_id = tx_out.id LEFT JOIN multi_asset AS ma ON ma.id = mto.ident diff --git a/files/grest/rpc/transactions/utxo_info.sql b/files/grest/rpc/transactions/utxo_info.sql index b1129cc1..2fb8b6ef 100644 --- a/files/grest/rpc/transactions/utxo_info.sql +++ b/files/grest/rpc/transactions/utxo_info.sql @@ -64,7 +64,7 @@ BEGIN SELECT ENCODE(tx.hash, 'hex')::text AS tx_hash, tx_out.index::smallint, - tx_out.address::text, + a.address::text, tx_out.value::text, grest.cip5_hex_to_stake_addr(sa.hash_raw) as stake_address, ENCODE(tx_out.payment_cred, 'hex') AS payment_cred, @@ -99,6 +99,7 @@ BEGIN END) AS is_spent FROM tx_out INNER JOIN tx ON tx_out.tx_id = tx.id + LEFT JOIN address AS a ON a.id = tx_out.address_id LEFT JOIN stake_address AS sa ON tx_out.stake_address_id = sa.id LEFT JOIN block AS b ON b.id = tx.block_id LEFT JOIN datum ON datum.id = tx_out.inline_datum_id