Skip to content

Commit

Permalink
Merge branch 'features/getmininginfo' into features/mining-v0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BHodl committed Mar 22, 2022
2 parents e5cdd07 + 5b29020 commit d90cd3f
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api_auth_docker/api-sample.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cyphernodeconf_docker/templates/gatekeeper/api.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions doc/API.v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
70 changes: 70 additions & 0 deletions doc/openapi/v0/cyphernode-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions proxy_docker/app/script/blockchainrpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()..."

Expand All @@ -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()..."

Expand Down
14 changes: 14 additions & 0 deletions proxy_docker/app/script/requesthandler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d90cd3f

Please sign in to comment.