mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
logical xor & status flag
This commit is contained in:
parent
322d6bde12
commit
ceeba0e89a
@ -23,25 +23,25 @@ class StatusApi(Resource):
|
||||
parser.add_argument('block_id', type=str)
|
||||
|
||||
args = parser.parse_args(strict=True)
|
||||
tx_id = args['tx_id']
|
||||
block_id = args['block_id']
|
||||
|
||||
if sum(arg is not None for arg in args.values()) != 1:
|
||||
# logical xor - exactly one query argument required
|
||||
if bool(tx_id) == bool(block_id):
|
||||
return make_error(400, "Provide exactly one query parameter. Choices are: block_id, tx_id")
|
||||
|
||||
pool = current_app.config['bigchain_pool']
|
||||
status, links = None, None
|
||||
|
||||
with pool() as bigchain:
|
||||
if args['tx_id']:
|
||||
status = bigchain.get_status(args['tx_id'])
|
||||
if tx_id:
|
||||
status = bigchain.get_status(tx_id)
|
||||
links = {
|
||||
"tx": "/transactions/{}".format(args['tx_id'])
|
||||
"tx": "/transactions/{}".format(tx_id)
|
||||
}
|
||||
|
||||
elif args['block_id']:
|
||||
block = bigchain.get_block(block_id=args['block_id'])
|
||||
if not block:
|
||||
return make_error(404)
|
||||
status = bigchain.block_election_status(block['id'], block['block']['voters'])
|
||||
elif block_id:
|
||||
_, status = bigchain.get_block(block_id=block_id, include_status=True)
|
||||
# TODO: enable once blocks endpoint is available
|
||||
# links = {
|
||||
# "block": "/blocks/{}".format(args['block_id'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user