-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align *_txs to return consistent data
- Loading branch information
Showing
7 changed files
with
182 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
CREATE OR REPLACE FUNCTION grest.account_txs(_stake_address text, _after_block_height integer DEFAULT 0) | ||
RETURNS TABLE ( | ||
tx_hash text, | ||
epoch_no word31type, | ||
block_height word31type, | ||
block_time integer | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
_tx_id_min bigint; | ||
_tx_id_list bigint[]; | ||
BEGIN | ||
SELECT INTO _tx_id_min id | ||
FROM tx | ||
WHERE block_id >= (SELECT id FROM block WHERE block_no >= _after_block_height ORDER BY id limit 1) | ||
ORDER BY id limit 1; | ||
|
||
-- all tx_out & tx_in tx ids | ||
SELECT INTO _tx_id_list ARRAY_AGG(tx_id) | ||
FROM ( | ||
SELECT tx_id | ||
FROM tx_out | ||
WHERE stake_address_id = ANY(SELECT id FROM stake_address WHERE view = _stake_address) | ||
AND tx_id >= _tx_id_min | ||
-- | ||
UNION | ||
-- | ||
SELECT tx_in_id AS tx_id | ||
FROM tx_out | ||
LEFT JOIN tx_in ON tx_out.tx_id = tx_in.tx_out_id | ||
AND tx_out.index = tx_in.tx_out_index | ||
WHERE | ||
tx_in.tx_in_id IS NOT NULL | ||
AND tx_out.stake_address_id = ANY(SELECT id FROM stake_address WHERE view = _stake_address) | ||
AND tx_in.tx_in_id >= _tx_id_min | ||
) AS tmp; | ||
|
||
RETURN QUERY | ||
SELECT | ||
DISTINCT(ENCODE(tx.hash, 'hex')) AS tx_hash, | ||
b.epoch_no, | ||
b.block_no AS block_height, | ||
EXTRACT(EPOCH FROM b.time)::integer AS block_time | ||
FROM public.tx | ||
INNER JOIN public.block AS b ON b.id = tx.block_id | ||
WHERE tx.id = ANY(_tx_id_list) | ||
AND block.block_no >= _after_block_height | ||
ORDER BY block.block_no DESC; | ||
END; | ||
$$; | ||
|
||
COMMENT ON FUNCTION grest.account_txs IS 'Get transactions associated with a given stake address'; -- noqa: LT01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters