-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
803 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
CREATE TABLE IF NOT EXISTS grest.asset_cache_control AS ( | ||
SELECT policy, name FROM multi_asset LIMIT 0 | ||
SELECT policy FROM multi_asset LIMIT 0 | ||
); | ||
|
||
ALTER TABLE | ||
|
||
CREATE TABLE IF NOT EXISTS grest.asset_tx_out_cache AS ( | ||
SELECT id AS ma_id, id AS txo_id, quantity FROM ma_tx_out LIMIT 0 | ||
); | ||
CREATE INDEX IF NOT EXISTS idx_atoc_txoid ON grest.asset_tx_out_cache USING btree (txo_id); | ||
|
||
INSERT INTO grest.asset_cache_control VALUES (DECODE('13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f','hex'),DECODE('4d494e53574150','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('92292852e3820cfbe99874b284fdf2befbddb38e070cf3512009a60a','hex'),DECODE('436f6c6f72506561726c','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6','hex'),DECODE('4d494e','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('de9b756719341e79785aa13c164e7fe68c189ed04d61c9876b2fe53f','hex'),DECODE('4d7565736c69537761705f414d4d','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535','hex'),DECODE('41474958','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235','hex'),DECODE('484f534b59','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63','hex'),DECODE('4e45574d','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('af2e27f580f7f08e93190a81f72462f153026d06450924726645891b','hex'),DECODE('44524950','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b6','hex'),DECODE('4745524f','hex')); | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e','hex'),DECODE('776f726c646d6f62696c65746f6b656e','hex')); | ||
CREATE INDEX IF NOT EXISTS idx_atoc_txoid ON grest.asset_tx_out_cache USING btree (txo_id) DESC; | ||
CREATE INDEX IF NOT EXISTS idx_atoc_maid ON grest.asset_tx_out_cache USING btree (ma_id) INCLUDE (txo_id, quantity); | ||
|
||
INSERT INTO grest.asset_cache_control VALUES (DECODE('a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235','hex')); -- HOSKY | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('af2e27f580f7f08e93190a81f72462f153026d06450924726645891b','hex')); -- DRIP | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6','hex')); -- MIN | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77','hex')); -- SUNDAE | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('13aa2accf2e1561723aa26871e071fdf32c867cff7e7d50ad470d62f','hex')); -- MINSWAP | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('c0ee29a85b13209423b10447d3c2e6a50641a15c57770e27cb9d5073','hex')); -- WINGRIDERS | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e','hex')); -- worldmobiletoken | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('682fe60c9918842b3323c43b5144bc3d52a23bd2fb81345560d73f63','hex')); -- NEWM | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d10','hex')); -- MELD | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('884892bcdc360bcef87d6b3f806e7f9cd5ac30d999d49970e7a903ae','hex')); -- PAVIA | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f','hex')); -- SNEK | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535','hex')); -- AGIX | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('92292852e3820cfbe99874b284fdf2befbddb38e070cf3512009a60a','hex')); -- *Pearl | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('de9b756719341e79785aa13c164e7fe68c189ed04d61c9876b2fe53f','hex')); -- MuesliSwap_AMM | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b6','hex')); -- GERO | ||
INSERT INTO grest.asset_cache_control VALUES (DECODE('750900e4999ebe0d58f19b634768ba25e525aaf12403bfe8fe130501', 'hex')); -- BOOK | ||
-- INSERT INTO grest.asset_cache_control VALUES (DECODE('','hex')); -- |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.genesis() | ||
RETURNS TABLE ( | ||
networkmagic varchar, | ||
networkid varchar, | ||
activeslotcoeff varchar, | ||
updatequorum varchar, | ||
maxlovelacesupply varchar, | ||
epochlength varchar, | ||
systemstart integer, | ||
slotsperkesperiod varchar, | ||
slotlength varchar, | ||
maxkesrevolutions varchar, | ||
securityparam varchar, | ||
alonzogenesis varchar | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.genesis(); | ||
END; | ||
$$; |
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,16 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.param_updates() | ||
RETURNS TABLE ( | ||
tx_hash text, | ||
block_height word31type, | ||
block_time integer, | ||
epoch_no word31type, | ||
data jsonb | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * | ||
FROM grest.param_updates(); | ||
END; | ||
$$; |
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,17 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.tip() | ||
RETURNS TABLE ( | ||
hash text, | ||
epoch_no word31type, | ||
abs_slot word63type, | ||
epoch_slot word31type, | ||
block_no word31type, | ||
block_time integer | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * | ||
FROM grest.tip(); | ||
END; | ||
$$; |
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,16 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.totals(_epoch_no numeric DEFAULT NULL) | ||
RETURNS TABLE ( | ||
epoch_no word31type, | ||
circulation text, | ||
treasury text, | ||
reward text, | ||
supply text, | ||
reserves text | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.totals(_epoch_no); | ||
END; | ||
$$; |
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,12 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.account_addresses(_stake_addresses text [], _first_only boolean DEFAULT FALSE, _empty boolean DEFAULT FALSE) | ||
RETURNS TABLE ( | ||
stake_address varchar, | ||
addresses jsonb | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.account_addresses(_stake_addresses,_first_only,_empty); | ||
END; | ||
$$; |
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,59 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.account_assets(_stake_addresses text []) | ||
RETURNS TABLE ( | ||
stake_address varchar, | ||
asset_list jsonb | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
sa_id_list integer[]; | ||
BEGIN | ||
SELECT INTO sa_id_list | ||
ARRAY_AGG(stake_address.id) | ||
FROM | ||
stake_address | ||
WHERE | ||
stake_address.view = ANY(_stake_addresses); | ||
RETURN QUERY | ||
WITH _all_assets AS ( | ||
SELECT | ||
sa.view, | ||
ma.policy, | ||
ma.name, | ||
ma.fingerprint, | ||
COALESCE(aic.decimals, 0) AS decimals, | ||
SUM(mtx.quantity) AS quantity | ||
FROM | ||
ma_tx_out AS mtx | ||
INNER JOIN multi_asset AS ma ON ma.id = mtx.ident | ||
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 | ||
LEFT JOIN grest.asset_info_cache AS aic ON aic.asset_id = ma.id | ||
WHERE sa.id = ANY(sa_id_list) | ||
AND txo.consumed_by_tx_in_id IS NULL | ||
GROUP BY | ||
sa.view, ma.policy, ma.name, ma.fingerprint, aic.decimals | ||
) | ||
|
||
SELECT | ||
assets_grouped.view AS stake_address, | ||
assets_grouped.assets | ||
FROM ( | ||
SELECT | ||
aa.view, | ||
JSONB_AGG( | ||
JSONB_BUILD_OBJECT( | ||
'policy_id', ENCODE(aa.policy, 'hex'), | ||
'asset_name', ENCODE(aa.name, 'hex'), | ||
'fingerprint', aa.fingerprint, | ||
'decimals', COALESCE(aa.decimals, 0), | ||
'quantity', aa.quantity::text | ||
) | ||
) AS assets | ||
FROM | ||
_all_assets AS aa | ||
GROUP BY | ||
aa.view | ||
) AS assets_grouped; | ||
END; | ||
$$; |
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,12 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.account_history(_stake_addresses text [], _epoch_no integer DEFAULT NULL) | ||
RETURNS TABLE ( | ||
stake_address varchar, | ||
history jsonb | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.account_history(_stake_addresses, _epoch_no); | ||
END; | ||
$$; |
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,20 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.account_info(_stake_addresses text []) | ||
RETURNS TABLE ( | ||
stake_address varchar, | ||
status text, | ||
delegated_pool varchar, | ||
total_balance text, | ||
utxo text, | ||
rewards text, | ||
withdrawals text, | ||
rewards_available text, | ||
reserves text, | ||
treasury text | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.account_info(_stake_addresses); | ||
END; | ||
$$; |
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,20 @@ | ||
CREATE OR REPLACE FUNCTION grestv0.account_info_cached(_stake_addresses text []) | ||
RETURNS TABLE ( | ||
stake_address varchar, | ||
status text, | ||
delegated_pool varchar, | ||
total_balance text, | ||
utxo text, | ||
rewards text, | ||
withdrawals text, | ||
rewards_available text, | ||
reserves text, | ||
treasury text | ||
) | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * FROM grest.account_info_cached(_stake_addresses); | ||
END; | ||
$$; |
Oops, something went wrong.