Skip to content

Commit

Permalink
Replace consumed_by_tx_in_id by consumed_by_tx_id
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Jan 17, 2024
1 parent 3ccdb2b commit e3ae0c0
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 67 deletions.
4 changes: 2 additions & 2 deletions files/grest/rpc/01_cached_tables/asset_txo_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ BEGIN
mf.quantity
FROM ma_filtered AS mf
LEFT JOIN tx_out AS txo ON mf.tx_out_id = txo.id
WHERE txo.consumed_by_tx_in_id IS NULL AND txo.id < (SELECT MAX(id) from tx_out)
WHERE txo.consumed_by_tx_id IS NULL AND txo.id < (SELECT MAX(id) from tx_out)
;

DELETE FROM grest.asset_tx_out_cache WHERE txo_id IN
(SELECT atoc.txo_id
FROM grest.asset_tx_out_cache AS atoc
LEFT JOIN tx_out AS txo ON atoc.txo_id = txo.id
WHERE txo.consumed_by_tx_in_id IS NOT NULL
WHERE txo.consumed_by_tx_id IS NOT NULL
OR txo.id IS NULL);

END;
Expand Down
13 changes: 4 additions & 9 deletions files/grest/rpc/01_cached_tables/stake_distribution_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,18 @@ BEGIN
account_delta_tx_ins AS (
SELECT
awdp.stake_address_id,
tx_in.tx_out_id AS txoid,
tx_in.tx_out_index AS txoidx
FROM tx_in
LEFT JOIN tx_out ON tx_in.tx_out_id = tx_out.tx_id
AND tx_in.tx_out_index::smallint = tx_out.index::smallint
tx_out.id AS txoid
FROM tx_out
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = tx_out.stake_address_id
WHERE tx_in.tx_in_id > _last_account_tx_id
WHERE tx_out.consumed_by_tx_id > _last_account_tx_id
),

account_delta_input AS (
SELECT
tx_out.stake_address_id,
COALESCE(SUM(tx_out.value), 0) AS amount
FROM account_delta_tx_ins
LEFT JOIN tx_out
ON account_delta_tx_ins.txoid=tx_out.tx_id
AND account_delta_tx_ins.txoidx = tx_out.index
LEFT JOIN tx_out ON account_delta_tx_ins.txoid=tx_out.id
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = tx_out.stake_address_id
GROUP BY tx_out.stake_address_id
),
Expand Down
26 changes: 11 additions & 15 deletions files/grest/rpc/01_cached_tables/stake_snapshot_cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,18 @@ BEGIN
account_delta_tx_ins AS (
SELECT
awdp.stake_address_id,
tx_in.tx_out_id AS txoid,
tx_in.tx_out_index AS txoidx
FROM tx_in
LEFT JOIN tx_out ON tx_in.tx_out_id = tx_out.tx_id
AND tx_in.tx_out_index::smallint = tx_out.index::smallint
tx_out.id AS txoid
FROM tx_out
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = tx_out.stake_address_id
WHERE tx_in.tx_in_id > _lower_bound_account_tx_id
AND tx_in.tx_in_id <= _upper_bound_account_tx_id
WHERE tx_out.consumed_by_tx_id > _lower_bound_account_tx_id
AND tx_out.consumed_by_tx_id <= _upper_bound_account_tx_id
),
account_delta_input AS (
SELECT
tx_out.stake_address_id,
COALESCE(SUM(tx_out.value), 0) AS amount
FROM account_delta_tx_ins
LEFT JOIN tx_out ON account_delta_tx_ins.txoid=tx_out.tx_id AND account_delta_tx_ins.txoidx = tx_out.index
LEFT JOIN tx_out ON account_delta_tx_ins.txoid=tx_out.id
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = tx_out.stake_address_id
GROUP BY tx_out.stake_address_id
),
Expand Down Expand Up @@ -312,12 +309,11 @@ BEGIN
WITH
account_delta_tx_ins AS (
SELECT
tx_out.stake_address_id,
tx_in.tx_out_id AS txoid,
tx_in.tx_out_index AS txoidx
FROM tx_in
LEFT JOIN tx_out ON tx_in.tx_out_id = tx_out.tx_id AND tx_in.tx_out_index::smallint = tx_out.index::smallint
WHERE tx_in.tx_in_id <= _upper_bound_account_tx_id
awdp.stake_address_id,
tx_out.id AS txoid
FROM tx_out
INNER JOIN accounts_with_delegated_pools AS awdp ON awdp.stake_address_id = tx_out.stake_address_id
WHERE tx_out.consumed_by_tx_id <= _upper_bound_account_tx_id
AND tx_out.stake_address_id = ANY(_newly_registered_account_ids)
),

Expand All @@ -326,7 +322,7 @@ BEGIN
tx_out.stake_address_id,
COALESCE(SUM(tx_out.value), 0) AS amount
FROM account_delta_tx_ins
LEFT JOIN tx_out ON account_delta_tx_ins.txoid=tx_out.tx_id AND account_delta_tx_ins.txoidx = tx_out.index
LEFT JOIN tx_out ON account_delta_tx_ins.txoid=tx_out.id
WHERE tx_out.stake_address_id = ANY(_newly_registered_account_ids)
GROUP BY tx_out.stake_address_id
),
Expand Down
1 change: 0 additions & 1 deletion files/grest/rpc/02_indexes/13_1_00.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS unique_stake_deregistration ON public.stake_de
CREATE UNIQUE INDEX IF NOT EXISTS unique_stake_registration ON public.stake_registration USING btree (tx_id, cert_index);
CREATE UNIQUE INDEX IF NOT EXISTS unique_treasury ON public.treasury USING btree (addr_id, tx_id, cert_index);
CREATE UNIQUE INDEX IF NOT EXISTS unique_tx_metadata ON public.tx_metadata USING btree (key, tx_id);
CREATE UNIQUE INDEX IF NOT EXISTS unique_txin ON tx_in USING btree (tx_out_id, tx_out_index);
CREATE UNIQUE INDEX IF NOT EXISTS unique_withdrawal ON public.withdrawal USING btree (addr_id, tx_id);
CREATE INDEX IF NOT EXISTS idx_ma_tx_out_ident ON ma_tx_out (ident) INCLUDE (tx_out_id, quantity);
CREATE INDEX IF NOT EXISTS idx_collateral_tx_in_tx_in_id ON collateral_tx_in (tx_in_id);
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/account/account_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BEGIN
txo.id
FROM tx_out AS txo
WHERE txo.stake_address_id = ANY(sa_id_list)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
) AS x
)

Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/account/account_assets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BEGIN
INNER JOIN tx_out AS txo ON txo.id = mtx.tx_out_id
INNER JOIN stake_address AS sa ON sa.id = txo.stake_address_id
WHERE sa.view = ANY(_stake_addresses)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY
sa.view, ma.policy, ma.name, ma.fingerprint, aic.decimals
)
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/account/account_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ BEGIN
COALESCE(SUM(VALUE), 0) AS utxo
FROM tx_out
WHERE tx_out.stake_address_id = ANY(sa_id_list)
AND tx_out.consumed_by_tx_in_id IS NULL
AND tx_out.consumed_by_tx_id IS NULL
GROUP BY tx_out.stake_address_id
) AS utxo_t ON utxo_t.stake_address_id = status_t.id
LEFT JOIN (
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/account/account_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ BEGIN
--
UNION
--
SELECT consumed_by_tx_in_id AS tx_id
SELECT consumed_by_tx_id AS tx_id
FROM tx_out
WHERE
tx_out.consumed_by_tx_in_id IS NULL
tx_out.consumed_by_tx_id IS NOT NULL
AND tx_out.stake_address_id = ANY(SELECT id FROM stake_address WHERE view = _stake_address)
AND tx_out.consumed_by_tx_in_id >= _tx_id_min
AND tx_out.consumed_by_tx_id >= _tx_id_min
) AS tmp;

RETURN QUERY
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/account/account_utxos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BEGIN
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.stake_address_id IN (SELECT sa.id FROM stake_address AS sa WHERE sa.view = ANY(_stake_addresses))
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY txo.id
)
SELECT
Expand Down Expand Up @@ -75,7 +75,7 @@ BEGIN
ELSE COALESCE(assets, JSONB_BUILD_ARRAY())
END AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand All @@ -86,7 +86,7 @@ BEGIN
LEFT JOIN script ON script.id = tx_out.reference_script_id
LEFT JOIN _assets ON tx_out.id = _assets.id
WHERE tx_out.stake_address_id IN (SELECT sa.id FROM stake_address AS sa WHERE sa.view = ANY(_stake_addresses))
AND tx_out.consumed_by_tx_in_id IS NULL
AND tx_out.consumed_by_tx_id IS NULL
;
END;
$$;
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/address/address_assets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ BEGIN
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)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY
txo.address, ma.policy, ma.name, ma.fingerprint, aic.decimals
)
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/address/address_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN
tx_out.reference_script_id
FROM tx_out
INNER JOIN tx ON tx.id = tx_out.tx_id
WHERE tx_out.consumed_by_tx_in_id IS NULL
WHERE tx_out.consumed_by_tx_id IS NULL
AND tx_out.address = ANY(_addresses)
)

Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/address/address_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ BEGIN
--
UNION
--
SELECT consumed_by_tx_in_id AS tx_id
SELECT consumed_by_tx_id AS tx_id
FROM tx_out
WHERE tx_out.consumed_by_tx_in_id IS NOT NULL
WHERE tx_out.consumed_by_tx_id IS NOT NULL
AND tx_out.address = ANY(_addresses)
AND tx_out.consumed_by_tx_in_id >= _tx_id_min
AND tx_out.consumed_by_tx_id >= _tx_id_min
) AS tmp;

RETURN QUERY
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/address/address_utxos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BEGIN
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)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY txo.id
)
SELECT
Expand Down Expand Up @@ -75,7 +75,7 @@ BEGIN
ELSE COALESCE(assets, JSONB_BUILD_ARRAY())
END AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand All @@ -86,7 +86,7 @@ BEGIN
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)
AND tx_out.consumed_by_tx_in_id IS NULL
AND tx_out.consumed_by_tx_id IS NULL
;
END;
$$;
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/address/credential_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ BEGIN
--
UNION
--
SELECT consumed_by_tx_in_id AS tx_id
SELECT consumed_by_tx_id AS tx_id
FROM tx_out
WHERE tx_out.consumed_by_tx_in_id IS NOT NULL
WHERE tx_out.consumed_by_tx_id IS NOT NULL
AND tx_out.payment_cred = ANY(_payment_cred_bytea)
AND tx_out.consumed_by_tx_in_id >= _tx_id_min
AND tx_out.consumed_by_tx_id >= _tx_id_min
) AS tmp;

RETURN QUERY
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/address/credential_utxos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BEGIN
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.payment_cred = ANY(_payment_cred_bytea)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY txo.id
)
SELECT
Expand Down Expand Up @@ -81,7 +81,7 @@ BEGIN
ELSE COALESCE(assets, JSONB_BUILD_ARRAY())
END AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand All @@ -92,7 +92,7 @@ BEGIN
LEFT JOIN script ON script.id = tx_out.reference_script_id
LEFT JOIN _assets ON tx_out.id = _assets.id
WHERE tx_out.payment_cred = ANY(_payment_cred_bytea)
AND tx_out.consumed_by_tx_in_id IS NULL
AND tx_out.consumed_by_tx_id IS NULL
;
END;
$$;
Expand Down
4 changes: 2 additions & 2 deletions files/grest/rpc/assets/asset_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BEGIN
LEFT JOIN tx_out AS txo ON atoc.txo_id = txo.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_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
) AS x
GROUP BY x.address, x.stake_address;
ELSE
Expand All @@ -72,7 +72,7 @@ BEGIN
LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_id
LEFT JOIN stake_address AS sa ON txo.stake_address_id = sa.id
WHERE mto.ident = _asset_id
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
) AS x
GROUP BY x.address;
END IF;
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/assets/asset_nft_address.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BEGIN
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
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
ORDER BY txo.id DESC
LIMIT 1;
END IF;
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/assets/asset_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ BEGIN
FROM ma_tx_out AS mto
INNER JOIN tx_out AS txo ON txo.id = mto.tx_out_id
WHERE mto.ident = _asset_id
AND txo.consumed_by_tx_in_id IS NULL)
AND txo.consumed_by_tx_id IS NULL)

SELECT
_asset_policy,
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/assets/asset_txs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ BEGIN
WHERE
mto.ident = _asset_id
AND block.block_no >= _after_block_height
AND (_history = TRUE OR txo.consumed_by_tx_in_id IS NULL)
AND (_history = TRUE OR txo.consumed_by_tx_id IS NULL)
GROUP BY
ident,
tx.hash,
Expand Down
6 changes: 3 additions & 3 deletions files/grest/rpc/assets/asset_utxos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ BEGIN
FROM tx_out AS txo
INNER JOIN ma_tx_out AS mto ON mto.tx_out_id = txo.id
WHERE mto.ident = ANY(_asset_id_list)
AND txo.consumed_by_tx_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
),
_assets AS (
SELECT
Expand Down Expand Up @@ -94,7 +94,7 @@ BEGIN
ELSE COALESCE(assets, JSONB_BUILD_ARRAY())
END AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand All @@ -104,7 +104,7 @@ BEGIN
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
WHERE tx_out.consumed_by_tx_in_id IS NULL
WHERE tx_out.consumed_by_tx_id IS NULL
;
END;
$$;
Expand Down
4 changes: 2 additions & 2 deletions files/grest/rpc/assets/policy_asset_addresses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BEGIN
LEFT JOIN tx_out AS txo ON txo.id = atoc.txo_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_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
) x
LEFT JOIN multi_asset AS ma ON ma.id = x.ma_id
GROUP BY
Expand All @@ -53,7 +53,7 @@ BEGIN
LEFT JOIN tx_out AS txo ON txo.id = mto.tx_out_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_in_id IS NULL
AND txo.consumed_by_tx_id IS NULL
GROUP BY
ma.name,
txo.address;
Expand Down
4 changes: 2 additions & 2 deletions files/grest/rpc/script/script_utxos.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ BEGIN
END
) AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand All @@ -74,7 +74,7 @@ BEGIN
LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id
LEFT JOIN datum ON datum.id = tx_out.inline_datum_id
WHERE script.hash = DECODE(_script_hash,'hex')
AND tx_out.consumed_by_tx_in_id IS NULL
AND tx_out.consumed_by_tx_id IS NULL
;
END;
$$;
Expand Down
2 changes: 1 addition & 1 deletion files/grest/rpc/transactions/utxo_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ BEGIN
ELSE COALESCE(assets, JSONB_BUILD_ARRAY())
END AS asset_list,
(CASE
WHEN tx_out.consumed_by_tx_in_id IS NULL THEN false
WHEN tx_out.consumed_by_tx_id IS NULL THEN false
ELSE true
END) AS is_spent
FROM tx_out
Expand Down
Loading

0 comments on commit e3ae0c0

Please sign in to comment.