Skip to content

Commit

Permalink
Make get_active_stake independent of ID
Browse files Browse the repository at this point in the history
  • Loading branch information
rdlrt committed Jun 8, 2021
1 parent dd6773b commit a2675e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions files/dbsync/queries/pool_active_stake.json
Expand Up @@ -31,10 +31,9 @@
"print": true,
"data": [
{
"type": "query_result",
"queryName": "Pool Updates",
"arg": "_pool_hash_id",
"payload": ".[0].hash_id"
"type": "query_variable",
"arg": "_pool_bech32",
"payload": "pool_id_bech32"
},
{
"type": "query_variable",
Expand All @@ -46,4 +45,4 @@
}
],
"script": []
}
}
14 changes: 7 additions & 7 deletions files/dbsync/rpc/get_active_stake.json
@@ -1,10 +1,10 @@
{
"function": "get_active_stake(_pool_hash_id, _epoch_no)",
"function": "get_active_stake(_pool_bech32, _epoch_no)",
"description": "Get the pools active stake in lovelace for specified epoch, current epoch if empty",
"parameters": [
{
"name": "_pool_hash_id",
"description": "[optional] hash_id from get_pool_update() function. Total stake for epoch if omitted."
"name": "_pool_bech32",
"description": "pool id in bech32 format. Total stake for epoch if omitted."
},
{
"name": "_epoch_no",
Expand All @@ -14,17 +14,17 @@
"example": [
{
"type": "rest",
"command": "curl -d _pool_hash_id=127 -d _epoch_no=122 -s http://localhost:8050/rpc/get_active_stake"
"command": "curl -d _pool_bech32=pool1z2ry6kxywgvdxv26g06mdywynvs7jj3uemnxv273mr5esukljsr -d _epoch_no=122 -s http://localhost:8050/rpc/get_active_stake"
}
],
"sql": [
"CREATE OR REPLACE FUNCTION get_active_stake(_pool_hash_id numeric default null, _epoch_no numeric default null)",
"CREATE OR REPLACE FUNCTION get_active_stake(_pool_bech32 text default null, _epoch_no numeric default null)",
"RETURNS JSON STABLE LANGUAGE PLPGSQL AS $$",
"BEGIN",
"IF _epoch_no IS NULL THEN",
"SELECT epoch.no INTO _epoch_no FROM epoch ORDER BY epoch.no DESC LIMIT 1;",
"END IF;",
"IF _pool_hash_id IS NULL THEN",
"IF _pool_bech32 IS NULL THEN",
"RETURN ( SELECT json_build_object(",
"'active_stake_sum', SUM (es.amount)",
")",
Expand All @@ -37,7 +37,7 @@
")",
"FROM epoch_stake AS es",
"WHERE es.epoch_no = _epoch_no",
"AND es.pool_id = _pool_hash_id",
"AND es.pool_id = (SELECT id from pool_hash where view=_pool_hash_id)",
");",
"END IF;",
"END; $$;"
Expand Down

0 comments on commit a2675e5

Please sign in to comment.