diff options
author | Bryan Bishop <kanzure@gmail.com> | 2015-06-08 07:43:56 -0500 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2015-06-08 07:43:56 -0500 |
commit | 2ab2ffba1d52f7015de0bbc444fae7d07c5eff69 (patch) | |
tree | 491be9efc4bf01587faa8632bbb327e6bb9964ea | |
parent | 5c656dcb01cab07a3c6a992f12c028477010e170 (diff) | |
download | rpcblockchainexplorer-2ab2ffba1d52f7015de0bbc444fae7d07c5eff69.tar.gz rpcblockchainexplorer-2ab2ffba1d52f7015de0bbc444fae7d07c5eff69.zip |
better index and template, example
-rw-r--r-- | rpcblockchainexplorer/api.py | 19 | ||||
-rw-r--r-- | rpcblockchainexplorer/templates/blocks.html | 4 | ||||
-rw-r--r-- | rpcblockchainexplorer/templates/layout.html (renamed from rpcblockchainexplorer/templates/body.html) | 0 |
3 files changed, 23 insertions, 0 deletions
diff --git a/rpcblockchainexplorer/api.py b/rpcblockchainexplorer/api.py index 8d9ae17..666500c 100644 --- a/rpcblockchainexplorer/api.py +++ b/rpcblockchainexplorer/api.py @@ -35,6 +35,7 @@ from flask import ( Blueprint, request, g, + render_template, ) api = Blueprint("api", __name__, url_prefix="") @@ -175,3 +176,21 @@ def create_api_endpoints(commands=ALLOWED_COMMANDS): # the endpoints to the blueprint, which can then be attached to flask # application instances. create_api_endpoints() + +# TODO: convert from the above format to the following format for each +# API command. Unfortunately it seems that there must be a custom template to +# display the relevant content. +@api.route("/") +def index(): + blocks = [] + + blockcount = g.bitcoin_rpc_client.getblockcount() + + for block_index in range(0, blockcount): + blockhash = g.bitcoin_rpc_client.getblockhash(block_index) + blocks.append({ + "height": block_index, + "hash": blockhash, + }) + + return render_template("blocks.html", blocks=blocks) diff --git a/rpcblockchainexplorer/templates/blocks.html b/rpcblockchainexplorer/templates/blocks.html index c89677a..cb29ada 100644 --- a/rpcblockchainexplorer/templates/blocks.html +++ b/rpcblockchainexplorer/templates/blocks.html @@ -1,3 +1,6 @@ +{% extends "layout.html" %} + +{% block content %} <table> <tr> <td>blockheight</td> @@ -10,3 +13,4 @@ </tr> {% endfor %} </table> +{% endblock %} diff --git a/rpcblockchainexplorer/templates/body.html b/rpcblockchainexplorer/templates/layout.html index e012001..e012001 100644 --- a/rpcblockchainexplorer/templates/body.html +++ b/rpcblockchainexplorer/templates/layout.html |