Skip to content
Snippets Groups Projects
Commit 7ca1fef6 authored by Michal Zander's avatar Michal Zander
Browse files

Add /version and /last-synced-block API to btracker

parent 0b1794e9
No related branches found
No related tags found
1 merge request!171Unify API returns to sql composite types, add pattern tests for REST API
...@@ -40,6 +40,11 @@ VALUES ...@@ -40,6 +40,11 @@ VALUES
(True, False) (True, False)
; ;
CREATE TABLE IF NOT EXISTS version(
git_hash TEXT
);
INSERT INTO version VALUES('unspecified (generate and apply set_version_in_sql.pgsql)');
--ACCOUNT BALANCES --ACCOUNT BALANCES
CREATE TABLE IF NOT EXISTS current_account_balances CREATE TABLE IF NOT EXISTS current_account_balances
......
...@@ -17,7 +17,8 @@ externalDocs: ...@@ -17,7 +17,8 @@ externalDocs:
tags: tags:
- name: Accounts - name: Accounts
description: Informations about account balances description: Informations about account balances
- name: Other
description: General API information
servers: servers:
- url: /balance-api - url: /balance-api
*/ */
...@@ -58,6 +59,10 @@ declare ...@@ -58,6 +59,10 @@ declare
{ {
"name": "Accounts", "name": "Accounts",
"description": "Informations about account balances" "description": "Informations about account balances"
},
{
"name": "Other",
"description": "General API information"
} }
], ],
"servers": [ "servers": [
...@@ -213,7 +218,7 @@ declare ...@@ -213,7 +218,7 @@ declare
} }
} }
}, },
"btracker_backend.balance_history_type": { "btracker_backend.balance_history": {
"type": "object", "type": "object",
"properties": { "properties": {
"block_num": { "block_num": {
...@@ -261,7 +266,7 @@ declare ...@@ -261,7 +266,7 @@ declare
"operations_result": { "operations_result": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/components/schemas/btracker_backend.balance_history_type" "$ref": "#/components/schemas/btracker_backend.balance_history"
}, },
"description": "List of operation results" "description": "List of operation results"
} }
...@@ -648,6 +653,58 @@ declare ...@@ -648,6 +653,58 @@ declare
} }
} }
} }
},
"/version": {
"get": {
"tags": [
"Other"
],
"summary": "Get Balance tracker''s version",
"description": "Get Balance tracker''s last commit hash (versions set by by hash value).\n\nSQL example\n* `SELECT * FROM btracker_endpoints.get_btracker_version();`\n\nREST call example\n* `GET ''https://%1$s/balance-api/version''`\n",
"operationId": "btracker_endpoints.get_btracker_version",
"responses": {
"200": {
"description": "Balance tracker version\n\n* Returns `TEXT`\n",
"content": {
"application/json": {
"schema": {
"type": "string"
},
"example": "c2fed8958584511ef1a66dab3dbac8c40f3518f0"
}
}
},
"404": {
"description": "App not installed"
}
}
}
},
"/last-synced-block": {
"get": {
"tags": [
"Other"
],
"summary": "Get last block number synced by balance tracker",
"description": "Get the block number of the last block synced by balance tracker.\n\nSQL example\n* `SELECT * FROM btracker_endpoints.get_btracker_last_synced_block();`\n\nREST call example\n* `GET ''https://%1$s/balance-api/last-synced-block''`\n",
"operationId": "btracker_endpoints.get_btracker_last_synced_block",
"responses": {
"200": {
"description": "Last synced block by balance tracker\n\n* Returns `INT`\n",
"content": {
"application/json": {
"schema": {
"type": "integer"
},
"example": 5000000
}
}
},
"404": {
"description": "No blocks synced"
}
}
}
} }
} }
} }
......
rewrite ^/last-synced-block /rpc/get_btracker_last_synced_block break;
# endpoint for get /last-synced-block
rewrite ^/version /rpc/get_btracker_version break;
# endpoint for get /version
rewrite ^/accounts/([^/]+)/delegations /rpc/get_balance_delegations?account-name=$1 break; rewrite ^/accounts/([^/]+)/delegations /rpc/get_balance_delegations?account-name=$1 break;
# endpoint for get /accounts/{account-name}/delegations # endpoint for get /accounts/{account-name}/delegations
......
#! /bin/sh -e #! /bin/bash -e
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1; pwd -P )" SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1; pwd -P )"
...@@ -99,10 +99,13 @@ psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_S ...@@ -99,10 +99,13 @@ psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_S
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_account_balances.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_account_balances.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_history_aggregation.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_history_aggregation.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_account_delegations.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/account-balances/get_account_delegations.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/other/get_btracker_last_synced_block.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../endpoints/other/get_btracker_version.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/account_dump_schema.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/account_dump_schema.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/account_stats_btracker.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/account_stats_btracker.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/compare_accounts.sql" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/../dump_accounts/compare_accounts.sql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET SEARCH_PATH TO ${BTRACKER_SCHEMA};" -f "$SCRIPTPATH/set_version_in_sql.pgsql"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA ${BTRACKER_SCHEMA} to btracker_user;" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA ${BTRACKER_SCHEMA} to btracker_user;"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA btracker_endpoints to btracker_user;" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA btracker_endpoints to btracker_user;"
psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA btracker_backend to btracker_user;" psql "$POSTGRES_ACCESS" -v ON_ERROR_STOP=on -c "SET ROLE btracker_owner;GRANT USAGE ON SCHEMA btracker_backend to btracker_user;"
......
...@@ -23,7 +23,10 @@ ENDPOINTS_IN_ORDER=" ...@@ -23,7 +23,10 @@ ENDPOINTS_IN_ORDER="
../$endpoints/account-balances/get_account_balances.sql ../$endpoints/account-balances/get_account_balances.sql
../$endpoints/account-balances/get_balance_history.sql ../$endpoints/account-balances/get_balance_history.sql
../$endpoints/account-balances/get_history_aggregation.sql ../$endpoints/account-balances/get_history_aggregation.sql
../$endpoints/account-balances/get_account_delegations.sql" ../$endpoints/account-balances/get_account_delegations.sql
../$endpoints/other/get_btracker_version.sql
../$endpoints/other/get_btracker_last_synced_block.sql"
# Function to reverse the lines # Function to reverse the lines
reverse_lines() { reverse_lines() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment