Problem: Get validators api doesn't exist

Solution: Add `GET /api/v1/validators` endpoint
This commit is contained in:
kansi 2018-02-27 13:30:56 +05:30
parent b752b4cbf2
commit 2a20e7042e
4 changed files with 40 additions and 0 deletions

View File

@ -243,5 +243,18 @@ class BigchainDB(Bigchain):
def fastquery(self): def fastquery(self):
return fastquery.FastQuery(self.connection, self.me) 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')) Block = namedtuple('Block', ('app_hash', 'height', 'transactions'))

View File

@ -8,6 +8,7 @@ from bigchaindb.web.views import (
transactions as tx, transactions as tx,
outputs, outputs,
votes, votes,
validators,
) )
@ -34,6 +35,7 @@ ROUTES_API_V1 = [
r('transactions', tx.TransactionListApi), r('transactions', tx.TransactionListApi),
r('outputs/', outputs.OutputListApi), r('outputs/', outputs.OutputListApi),
r('votes/', votes.VotesApi), r('votes/', votes.VotesApi),
r('validators/', validators.ValidatorsApi),
] ]

View File

@ -50,4 +50,5 @@ def get_api_v1_info(api_prefix):
'outputs': '{}outputs/'.format(api_prefix), 'outputs': '{}outputs/'.format(api_prefix),
'streams': websocket_root, 'streams': websocket_root,
'metadata': '{}metadata/'.format(api_prefix), 'metadata': '{}metadata/'.format(api_prefix),
'validators': '{}validators'.format(api_prefix),
} }

View 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)