From b252c4079358d514653a073cdf924fc0ab91b7ba Mon Sep 17 00:00:00 2001 From: diminator Date: Tue, 3 Jan 2017 17:20:16 +0100 Subject: [PATCH] GET /votes examples -> samples --- .../generate_http_server_api_documentation.py | 34 ++++++++++++++++++- .../http-client-server-api.rst | 31 +++-------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/docs/server/generate_http_server_api_documentation.py b/docs/server/generate_http_server_api_documentation.py index 0716107a..c6c9b63f 100644 --- a/docs/server/generate_http_server_api_documentation.py +++ b/docs/server/generate_http_server_api_documentation.py @@ -5,9 +5,11 @@ import os import os.path from bigchaindb.common.transaction import Transaction, Input, TransactionLink +from bigchaindb.core import Bigchain from bigchaindb.models import Block + TPLS = {} @@ -80,6 +82,7 @@ Host: example.com """ + TPLS['get-statuses-tx-invalid-response'] = """\ HTTP/1.1 200 OK Content-Type: application/json @@ -107,6 +110,7 @@ Host: example.com """ + TPLS['get-block-response'] = """\ HTTP/1.1 200 OK Content-Type: application/json @@ -114,12 +118,14 @@ Content-Type: application/json %(block)s """ + TPLS['get-block-txid-request'] = """\ GET /blocks?tx_id=%(txid)s HTTP/1.1 Host: example.com """ + TPLS['get-block-txid-response'] = """\ HTTP/1.1 200 OK Content-Type: application/json @@ -128,8 +134,25 @@ Content-Type: application/json """ +TPLS['get-vote-request'] = """\ +GET /votes?block_id=%(blockid)s HTTP/1.1 +Host: example.com + +""" + + +TPLS['get-vote-response'] = """\ +HTTP/1.1 200 OK +Content-Type: application/json + +[%(vote)s] +""" + + def main(): """ Main function """ + + # tx create privkey = 'CfdqtD7sS7FgkMoGPXw55MVGGFwQLAoHYTcBhZDtF99Z' pubkey = '4K9sWUMFwTgaDGPfdynrbxWqWS6sWmKbZoTjxLtVUibD' asset = {'msg': 'Hello BigchainDB!'} @@ -137,6 +160,7 @@ def main(): tx = tx.sign([privkey]) tx_json = json.dumps(tx.to_dict(), indent=2, sort_keys=True) + # tx transfer privkey_transfer = '3AeWpPdhEZzWLYfkfYHBfMFC2r1f8HEaGS9NtbbKssya' pubkey_transfer = '3yfQPHeWAa1MxTX9Zf9176QqcpcnWcanVZZbaHb8B3h9' @@ -159,6 +183,7 @@ def main(): tx_transfer_last = tx_transfer_last.sign([privkey_transfer]) tx_transfer_last_json = json.dumps(tx_transfer_last.to_dict(), indent=2, sort_keys=True) + # block node = "ErEeVZt8AfLbMJub25tjNxbpzzTNp3mGidL3GxGdd9bt" signature = "53wxrEQDYk1dXzmvNSytbCfmNVnPqPkDQaTnAe8Jf43s6ssejPxezkCvUnGTnduNUmaLjhaan1iRLi3peu6s5DzA" block = Block(transactions=[tx], node_pubkey=node, voters=[node], signature=signature) @@ -167,6 +192,12 @@ def main(): base_path = os.path.join(os.path.dirname(__file__), 'source/drivers-clients/samples') + # vote + DUMMY_SHA3 = '0123456789abcdef' * 4 + b = Bigchain(public_key=node) + vote = b.vote(block.id, DUMMY_SHA3, True) + vote_json = json.dumps(vote, indent=2, sort_keys=True) + if not os.path.exists(base_path): os.makedirs(base_path) @@ -182,7 +213,8 @@ def main(): 'public_keys_transfer': tx_transfer.outputs[0].public_keys[0], 'public_keys_transfer_last': tx_transfer_last.outputs[0].public_keys[0], 'block': block_json, - 'blockid': block.id} + 'blockid': block.id, + 'vote': vote_json} with open(path, 'w') as handle: handle.write(code) diff --git a/docs/server/source/drivers-clients/http-client-server-api.rst b/docs/server/source/drivers-clients/http-client-server-api.rst index b11566c2..90ccc58c 100644 --- a/docs/server/source/drivers-clients/http-client-server-api.rst +++ b/docs/server/source/drivers-clients/http-client-server-api.rst @@ -26,7 +26,7 @@ with something like the following in the body: { "_links": { "docs": { "href": "https://docs.bigchaindb.com/projects/server/en/v0.9.0/" } - } + }, "keyring": [ "6qHyZew94NMmUTYyHnkZsB8cxJYuRNEiEpXHe1ih9QX3", "AdDuyrTyjrDt935YnFu4VBCVDhHtY2Y6rcy7x2TFeiRi" @@ -365,29 +365,13 @@ Votes **Example request**: - .. sourcecode:: http - - GET /votes?block_id=6152f...e7202 HTTP/1.1 - Host: example.com + .. literalinclude:: samples/get-vote-request.http + :language: http **Example response**: - .. sourcecode:: http - - HTTP/1.1 200 OK - Content-Type: application/json - - [{ - "node_pubkey": "ErEeVZt8AfLbMJub25tjNxbpzzTNp3mGidL3GxGdd9bt" , - "signature": "53wxrEQDYk1dXzmvNSytbCfmNVnPqPkDQaTnAe8Jf43s6ssejPxezkCvUnGTnduNUmaLjhaan1iRLi3peu6s5DzA", - "vote": { - "invalid_reason": null , - "is_block_valid": true , - "previous_block": "6152fbc7e0f7686512ed6b92c01e8c73ea1e3f51a7b037ac5cc8c860215e7202" , - "timestamp": "1480082692" , - "voting_for_block": "6152f...e7202" - } - }] + .. literalinclude:: samples/get-vote-response.http + :language: http :resheader Content-Type: ``application/json`` @@ -395,11 +379,6 @@ Votes :statuscode 400: The request wasn't understood by the server, e.g. just requesting ``/votes``, without defining ``block_id``. -.. http:get:: /votes?block_id={block_id}&voter={voter} - - Description: TODO - - Determining the API Root URL ----------------------------