Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block_info RPC, minor changes to blocks RPC #1086

Merged
merged 4 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/Build/grestsvcs.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,42 @@
}
}
},
"/rpc/block_info": {
"post": {
"tags": [
"Block Queries"
],
"summary": "Get detailed information about a specific block",
"produces": [
"application/json",
"application/vnd.pgrst.object+json"
],
"parameters": [
{
"required": true,
"schema": {
"required": [
"_block_hash"
],
"type": "object",
"properties": {
"_block_hash": {
"format": "text",
"type": "string"
}
}
},
"in": "body",
"name": "args"
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/rpc/account_addresses": {
"post": {
"tags": [
Expand Down
56 changes: 56 additions & 0 deletions files/grest/rpc/blocks/block_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
DROP FUNCTION IF EXISTS grest.block_info (_block_hash text);

CREATE FUNCTION grest.block_info (_block_hash text)
RETURNS TABLE (
HASH text,
EPOCH uinteger,
ABS_SLOT uinteger,
EPOCH_SLOT uinteger,
HEIGHT uinteger,
BLOCK_TIME timestamp,
TX_COUNT bigint,
VRF_KEY varchar,
OP_CERT_COUNTER word63type,
POOL varchar,
PARENT_HASH text,
CHILD_HASH text)
LANGUAGE PLPGSQL
AS $$
BEGIN
RETURN QUERY
SELECT
_block_hash AS HASH,
b.EPOCH_NO AS EPOCH,
b.SLOT_NO AS ABS_SLOT,
b.EPOCH_SLOT_NO AS EPOCH_SLOT,
b.BLOCK_NO AS HEIGHT,
b.TIME AS BLOCK_TIME,
b.TX_COUNT,
b.VRF_KEY,
b.OP_CERT_COUNTER,
ph.VIEW AS POOL,
(
SELECT
ENCODE(tB.HASH::bytea, 'hex')
FROM
block tB
WHERE
id = b.id - 1) AS PARENT_HASH,
(
SELECT
ENCODE(tB.HASH::bytea, 'hex')
FROM
block tB
WHERE
id = b.id + 1) AS CHILD_HASH
FROM
BLOCK B
LEFT JOIN SLOT_LEADER SL ON SL.ID = B.SLOT_LEADER_ID
LEFT JOIN POOL_HASH PH ON PH.ID = SL.POOL_HASH_ID
WHERE
ENCODE(B.HASH::bytea, 'hex') = _block_hash;
END;
$$;

COMMENT ON FUNCTION grest.block_info IS 'Get detailed information about a specific block';

39 changes: 17 additions & 22 deletions files/grest/rpc/blocks/blocks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@ DROP FUNCTION IF EXISTS grest.blocks ();

CREATE FUNCTION grest.blocks ()
RETURNS TABLE (
hash text,
epoch uinteger,
abs_slot uinteger,
epoch_slot uinteger,
block_no uinteger,
block_time timestamp,
tx_count bigint,
vrf_key varchar,
op_cert_counter word63type,
pool varchar,
parent_hash text)
HASH text,
EPOCH uinteger,
ABS_SLOT uinteger,
EPOCH_SLOT uinteger,
HEIGHT uinteger,
BLOCK_TIME timestamp,
TX_COUNT bigint,
VRF_KEY varchar,
OP_CERT_COUNTER word63type,
POOL varchar,
PARENT_HASH text)
LANGUAGE PLPGSQL
AS $$
BEGIN
RETURN QUERY
SELECT
ENCODE(B.HASH::bytea, 'hex') AS BLOCK_HASH,
ENCODE(B.HASH::bytea, 'hex') AS HASH,
b.EPOCH_NO AS EPOCH,
b.SLOT_NO AS ABS_SLOT,
b.EPOCH_SLOT_NO AS EPOCH_SLOT,
b.BLOCK_NO,
b.TIME,
b.BLOCK_NO AS HEIGHT,
b.TIME AS BLOCK_TIME,
b.TX_COUNT,
b.VRF_KEY,
b.OP_CERT_COUNTER,
ph.VIEW,
(
SELECT
ENCODE(tB.HASH::bytea, 'hex')
FROM
block tB
WHERE
id = b.id - 1) AS parent_hash
ph.VIEW AS POOL,
LAG(ENCODE(b.HASH::bytea, 'hex')) OVER (ORDER BY b.ID) AS PARENT_HASH
FROM
BLOCK B
LEFT JOIN SLOT_LEADER SL ON SL.ID = B.SLOT_LEADER_ID
Expand All @@ -45,3 +39,4 @@ END;
$$;

COMMENT ON FUNCTION grest.blocks IS 'Get detailed information about all blocks (paginated - latest first)';