From 52af486b3796c6909610e571db34c35782b83a63 Mon Sep 17 00:00:00 2001 From: BHodl Date: Wed, 23 Mar 2022 23:06:30 -0400 Subject: [PATCH 1/5] Previous correct changes --- api_auth_docker/api-sample.properties | 2 + .../templates/gatekeeper/api.properties | 2 + doc/API.v0.md | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+) 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 From 1276d56eb80b74cf2a3c6719f2686486de703633 Mon Sep 17 00:00:00 2001 From: BHodl Date: Wed, 23 Mar 2022 23:08:43 -0400 Subject: [PATCH 2/5] Added MiningInfo component shemas --- doc/openapi/v0/cyphernode-api.yaml | 86 ++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index 5af8c1015..c2adbefbc 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: @@ -3010,6 +3080,22 @@ components: type: "object" additionalProperties: $ref: '#/components/schemas/TypeBip9SoftFork' + MiningInfo: + type: "object" + properties: + blocks: + type: "integer" + difficulty: + type: "number" + networkhashps: + type: "number" + pooledtx: + type: "integer" + chain: + type: "string" + enum: ["test", "main"] + warnings: + type: "string" InstallationInfo: type: "object" properties: From e248fae3e638f3071f7d13dd561d55e18ecfef8c Mon Sep 17 00:00:00 2001 From: BHodl Date: Wed, 23 Mar 2022 23:10:33 -0400 Subject: [PATCH 3/5] Return unmodified BTC response --- proxy_docker/app/script/blockchainrpc.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/proxy_docker/app/script/blockchainrpc.sh b/proxy_docker/app/script/blockchainrpc.sh index 9cf452dba..5b73f1733 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}" + return $? +} + get_mempool_info() { trace "Entering get_mempool_info()..." @@ -93,6 +101,18 @@ 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}" + echo "${result}" + return $? +} + validateaddress() { trace "Entering validateaddress()..." From daef2bd3a4ba413aefedf7ca68bd219e25ac354d Mon Sep 17 00:00:00 2001 From: BHodl Date: Wed, 23 Mar 2022 23:12:45 -0400 Subject: [PATCH 4/5] Adapt to v0.8 code change --- proxy_docker/app/script/requesthandler.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index 351668c7a..264c68f86 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -239,6 +239,13 @@ 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}") + returncode=$? + ;; getblockinfo) # curl (GET) http://192.168.111.152:8080/getblockinfo/000000006f82a384c208ecfa04d05beea02d420f3f398ddda5c7f900de5718ea @@ -594,6 +601,12 @@ main() { response=$(derivepubpath_bitcoind "${line}") returncode=$? ;; + getmininginfo) + # http://192.168.111.152:8080/getmininginfo + + response=$(get_mining_info) + returncode=$? + ;; getmempoolinfo) # curl GET http://192.168.111.152:8080/getmempoolinfo From 50584d6895f4c87d1f52efa2e1df196ec599c895 Mon Sep 17 00:00:00 2001 From: BHodl Date: Thu, 24 Mar 2022 00:41:30 -0400 Subject: [PATCH 5/5] Update mining doc --- doc/API.v0.md | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/API.v0.md b/doc/API.v0.md index f7ff5f76c..44d90d846 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -368,12 +368,16 @@ GET http://cyphernode:8888/getmininginfo Proxy response: ```json { - "blocks": 697264, - "difficulty": 15556093717702.55, - "networkhashps": 1.657879694896906e+20, - "pooledtx": 136, - "chain": "main", - "warnings": "" + "result": { + "blocks": 2191222, + "difficulty": 1, + "networkhashps": 118625307084442.9, + "pooledtx": 0, + "chain": "test", + "warnings": "" + }, + "error": null, + "id": null } ``` ### Get Bitcoin estimated hashrare per seconds. Optional block parameters. (called by your application) @@ -385,15 +389,20 @@ POST http://cyphernode:8888/getnetworkhashps with body... {"height":-1, "nblocks":120} ``` +height: default(-1) since last difficulty adjustent. + +nblocks: default(120) number of block average. + Proxy response: ```json { - "height": -1, - "nblocks": 120, - "hashps": 127647856311107400000 -}``` + "result": 97145748652669.34, + "error": null, + "id": null +} +``` ### Get mempool information