Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getmininginfo call #228

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
46 changes: 46 additions & 0 deletions doc/API.v0.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,52 @@ 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
{
"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)

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}
```
height: default(-1) since last difficulty adjustent.

nblocks: default(120) number of block average.


Proxy response:

```json
{
"result": 97145748652669.34,
"error": null,
"id": null
}
```

### Get mempool information

Expand Down
86 changes: 86 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'
BHodl marked this conversation as resolved.
Show resolved Hide resolved
'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 Expand Up @@ -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:
Expand Down
20 changes: 20 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}"
return $?
}

get_mempool_info() {
trace "Entering get_mempool_info()..."

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

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

Expand Down Expand Up @@ -594,6 +601,12 @@ main() {
response=$(derivepubpath_bitcoind "${line}")
returncode=$?
;;
getmininginfo)
# http://192.168.111.152:8080/getmininginfo
BHodl marked this conversation as resolved.
Show resolved Hide resolved

response=$(get_mining_info)
returncode=$?
;;
getmempoolinfo)
# curl GET http://192.168.111.152:8080/getmempoolinfo

Expand Down