summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpcblockchainexplorer/api.py19
-rw-r--r--rpcblockchainexplorer/templates/blocks.html4
-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