mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Get validators api doesn't exist
Solution: Add `GET /api/v1/validators` endpoint
This commit is contained in:
parent
b752b4cbf2
commit
2a20e7042e
@ -243,5 +243,18 @@ class BigchainDB(Bigchain):
|
||||
def fastquery(self):
|
||||
return fastquery.FastQuery(self.connection, self.me)
|
||||
|
||||
def get_validators(self):
|
||||
try:
|
||||
resp = requests.get(f'{ENDPOINT}validators')
|
||||
validators = resp.json()['result']['validators']
|
||||
for v in validators:
|
||||
v.pop('accum')
|
||||
v.pop('address')
|
||||
|
||||
return validators
|
||||
|
||||
except:
|
||||
raise Exception('Error while processing data from tendermint.')
|
||||
|
||||
|
||||
Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))
|
||||
|
@ -8,6 +8,7 @@ from bigchaindb.web.views import (
|
||||
transactions as tx,
|
||||
outputs,
|
||||
votes,
|
||||
validators,
|
||||
)
|
||||
|
||||
|
||||
@ -34,6 +35,7 @@ ROUTES_API_V1 = [
|
||||
r('transactions', tx.TransactionListApi),
|
||||
r('outputs/', outputs.OutputListApi),
|
||||
r('votes/', votes.VotesApi),
|
||||
r('validators/', validators.ValidatorsApi),
|
||||
]
|
||||
|
||||
|
||||
|
@ -50,4 +50,5 @@ def get_api_v1_info(api_prefix):
|
||||
'outputs': '{}outputs/'.format(api_prefix),
|
||||
'streams': websocket_root,
|
||||
'metadata': '{}metadata/'.format(api_prefix),
|
||||
'validators': '{}validators'.format(api_prefix),
|
||||
}
|
||||
|
24
bigchaindb/web/views/validators.py
Normal file
24
bigchaindb/web/views/validators.py
Normal file
@ -0,0 +1,24 @@
|
||||
from flask import current_app
|
||||
from flask_restful import Resource
|
||||
|
||||
from bigchaindb.web.views.base import make_error
|
||||
|
||||
|
||||
class ValidatorsApi(Resource):
|
||||
def get(self):
|
||||
"""API endpoint to get validators set.
|
||||
|
||||
Return:
|
||||
A JSON string containing the validator set of the current node.
|
||||
"""
|
||||
|
||||
pool = current_app.config['bigchain_pool']
|
||||
|
||||
try:
|
||||
with pool() as bigchain:
|
||||
validators = bigchain.get_validators()
|
||||
|
||||
return validators
|
||||
|
||||
except:
|
||||
return make_error(500)
|
Loading…
x
Reference in New Issue
Block a user