diff --git a/api_auth_docker/api-sample.properties b/api_auth_docker/api-sample.properties index 398781940..aeaa9e72e 100644 --- a/api_auth_docker/api-sample.properties +++ b/api_auth_docker/api-sample.properties @@ -6,6 +6,8 @@ action_getblockchaininfo=stats action_installation_info=stats action_getmempoolinfo=stats action_getblockhash=stats +action_getmininginfo=stats +action_getnetworkhashps=stats # Watcher can do what the stats can do, plus: action_watch=watcher diff --git a/cyphernodeconf_docker/templates/gatekeeper/api.properties b/cyphernodeconf_docker/templates/gatekeeper/api.properties index ac5b2fc8d..a5343af2d 100644 --- a/cyphernodeconf_docker/templates/gatekeeper/api.properties +++ b/cyphernodeconf_docker/templates/gatekeeper/api.properties @@ -9,6 +9,8 @@ action_getblockchaininfo=stats action_installation_info=stats action_getmempoolinfo=stats action_getblockhash=stats +action_getmininginfo=stats +action_getnetworkhashps=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 7abf53d8f..f7ff5f76c 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -357,6 +357,43 @@ When cyphernode receives a transaction confirmation (/conf endpoint) on a watche "blockheight":"" } ``` +### Get the mining information (called by your application) + +Returns the mining informations of the current block. + +```http +GET http://cyphernode:8888/getmininginfo +``` + +Proxy response: +```json +{ + "blocks": 697264, + "difficulty": 15556093717702.55, + "networkhashps": 1.657879694896906e+20, + "pooledtx": 136, + "chain": "main", + "warnings": "" +} +``` +### Get Bitcoin estimated hashrare per seconds. Optional block parameters. (called by your application) + +Return the estimated hashrate per seconds of block(s). Default is the blocks since the last difficulty adjustement(-1), but can specify block height and number of blocks. + +```http +POST http://cyphernode:8888/getnetworkhashps +with body... +{"height":-1, "nblocks":120} +``` + +Proxy response: + +```json +{ + "height": -1, + "nblocks": 120, + "hashps": 127647856311107400000 +}``` ### Get mempool information diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index 5af8c1015..4e2fc36be 100644 --- a/doc/openapi/v0/cyphernode-api.yaml +++ b/doc/openapi/v0/cyphernode-api.yaml @@ -802,6 +802,51 @@ paths: application/json: schema: $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' + /getnetworkhashps: + post: + tags: + - "mining" + - "hashrate" + - "core features" + summary: "Get hashrate per seconds matching nblocks and height provided." + description: "Returns hash per seconds." + operationId: "getNetworkHashps" + requestBody: + description: "Block height and number of blocks requested." + required: true + content: + application/json: + schema: + type: "object" + properties: + height: + type: "number" + nblocks: + type: "number" + 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: @@ -883,6 +928,31 @@ paths: application/json: schema: $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' + /getmininginfo: + get: + tags: + - "stats" + - "core features" + summary: "Show mining info" + description: "Returns mining information." + operationId: "getMiningInfo" + responses: + '200': + description: "successful operation" + content: + application/json: + schema: + $ref: '#/components/schemas/MiningInfo' + '403': + $ref: '#/components/schemas/ApiResponseNotAllowed' + '404': + $ref: '#/components/schemas/ApiResponseNotFound' + '503': + description: "Resource temporarily unavailable" + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' /getblockinfo/{blockHash}: get: parameters: diff --git a/proxy_docker/app/script/blockchainrpc.sh b/proxy_docker/app/script/blockchainrpc.sh index 9cf452dba..08c0e034a 100644 --- a/proxy_docker/app/script/blockchainrpc.sh +++ b/proxy_docker/app/script/blockchainrpc.sh @@ -77,6 +77,14 @@ get_blockchain_info() { return $? } +get_mining_info() { + trace "Entering get_mining_info()..." + + local data='{"method":"getmininginfo"}' + send_to_watcher_node "${data}" | jq ".result" + return $? +} + get_mempool_info() { trace "Entering get_mempool_info()..." @@ -93,6 +101,20 @@ get_blockhash() { return $? } +get_networkhashps() { + trace "Entering get_networkhashps()..." + local request=${1} + local height=$(echo "${request}" | jq -r ".height") + local nblocks=$(echo "${request}" | jq -r ".nblocks") + local data="{\"method\":\"getnetworkhashps\",\"params\":[${nblocks},${height}]}" + local result=$(send_to_watcher_node "${data}") + trace "[getnetworkhashps] result = ${result}" + local hashps=$(echo ${result} | jq -r ".result") + local response="{\"height\":${height},\"nblocks\":${nblocks},\"hashps\":${hashps}}" + echo "${response}" + return $? +} + validateaddress() { trace "Entering validateaddress()..." diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index 351668c7a..108473a87 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -239,6 +239,14 @@ main() { response=$(get_blockhash "$(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3)") returncode=$? ;; + getnetworkhashps) + # POST http://192.168.111.152:8080/getnetworkhashps + # BODY {"height":541845,"nblocks":120} + + response=$(get_networkhashps "${line}") + response_to_client "${response}" ${?} + break + ;; getblockinfo) # curl (GET) http://192.168.111.152:8080/getblockinfo/000000006f82a384c208ecfa04d05beea02d420f3f398ddda5c7f900de5718ea @@ -594,6 +602,12 @@ main() { response=$(derivepubpath_bitcoind "${line}") returncode=$? ;; + getmininginfo) + # http://192.168.111.152:8080/getmininginfo + + response=$(get_mining_info) + response_to_client "${response}" ${?} + ;; getmempoolinfo) # curl GET http://192.168.111.152:8080/getmempoolinfo