From 8c7f2724ffcdf595f1f2f75d3cb820e42d44ce7a Mon Sep 17 00:00:00 2001 From: g-homebase Date: Tue, 3 Sep 2019 17:31:34 -0400 Subject: [PATCH] Added getblockhash call --- api_auth_docker/api-sample.properties | 1 + doc/API.v0.md | 18 +++++++++++++ doc/openapi/v0/cyphernode-api.yaml | 32 +++++++++++++++++++++++ proxy_docker/app/script/blockchainrpc.sh | 7 +++++ proxy_docker/app/script/requesthandler.sh | 7 +++++ 5 files changed, 65 insertions(+) diff --git a/api_auth_docker/api-sample.properties b/api_auth_docker/api-sample.properties index 12dfd37..4d59d81 100644 --- a/api_auth_docker/api-sample.properties +++ b/api_auth_docker/api-sample.properties @@ -5,6 +5,7 @@ action_helloworld=stats action_getblockchaininfo=stats action_installation_info=stats action_getmempoolinfo=stats +action_getblockhash=stats # Watcher can do what the stats can do, plus: action_watch=watcher diff --git a/doc/API.v0.md b/doc/API.v0.md index 619f893..d62a1a2 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -376,6 +376,24 @@ Proxy response: } ``` +### Get the Block Hash from Height (called by application) + +Returns the best block hash matching height provided. + +```http +GET http://cyphernode:8888/getblockhash/593104 +``` + +Proxy response: + +```json +{ + "result":"00000000000000000005dc459f0575b17413dbe7685e3e0fd382ed521f1be68b", + "error":null, + "id":null +} +``` + ### Get the Best Block Hash (called by application) Returns the best block hash of the watching Bitcoin node. diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index 46e6e81..b1c2415 100644 --- a/doc/openapi/v0/cyphernode-api.yaml +++ b/doc/openapi/v0/cyphernode-api.yaml @@ -436,6 +436,38 @@ paths: schema: $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' + /getblockhash: + get: + tags: + - "block" + - "core features" + summary: "Get block hash matching height provided." + description: "Returns the block matching the height provided of the watching Bitcoin node." + operationId: "getBlockHash" + responses: + '200': + description: "successful operation" + content: + application/json: + schema: + type: "object" + required: + - "result" + properties: + result: + $ref: '#/components/schemas/TypeHashString' + error: + type: "string" + id: + type: "string" + '403': + $ref: '#/components/schemas/ApiResponseNotAllowed' + '503': + description: "Resource temporarily unavailable" + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' /getbestblockhash: get: tags: diff --git a/proxy_docker/app/script/blockchainrpc.sh b/proxy_docker/app/script/blockchainrpc.sh index 89bcca7..661d91f 100644 --- a/proxy_docker/app/script/blockchainrpc.sh +++ b/proxy_docker/app/script/blockchainrpc.sh @@ -84,3 +84,10 @@ get_mempool_info() { send_to_watcher_node "${data}" | jq ".result" return $? } +get_blockhash() { + trace "Entering get_blockhash()..." + local blockheight=${1} + local data="{\"method\":\"getblockhash\",\"params\":[${blockheight}]}" + send_to_watcher_node "${data}" | jq ".result" + return $? +} diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index 5bf6771..dad4ca2 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -182,6 +182,13 @@ main() { response_to_client "${response}" ${?} break ;; + getblockhash) + # curl (GET) http://192.168.111.152:8080/getblockhash/522322 + + response=$(get_blockhash $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3)) + response_to_client "${response}" ${?} + break + ;; getblockinfo) # curl (GET) http://192.168.111.152:8080/getblockinfo/000000006f82a384c208ecfa04d05beea02d420f3f398ddda5c7f900de5718ea