From 8fb4c9716ff751b79ec70b43826e999b877f065b Mon Sep 17 00:00:00 2001 From: SsNiPeR1 <63201833+SsNiPeR1@users.noreply.github.com> Date: Sun, 19 Jun 2022 22:02:38 +0200 Subject: [PATCH] added json config + example, now site is customizeable --- .gitignore | 3 +- app.py | 82 +++++++++++++++++++++++++------------ config.json.example | 6 +++ static/style.css | 9 ++++ templates/account.html | 33 ++++++++------- templates/block.html | 35 +++++++++------- templates/bloominfo.html | 4 +- templates/contractinfo.html | 19 +++++++++ templates/error.html | 4 +- templates/index.html | 10 +++-- templates/transactions.html | 6 +-- templates/tx.html | 12 +++--- templates/uncles.html | 4 +- 13 files changed, 152 insertions(+), 75 deletions(-) create mode 100644 config.json.example create mode 100644 templates/contractinfo.html diff --git a/.gitignore b/.gitignore index 7e99e36..4731f01 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.pyc \ No newline at end of file +*.pyc +config.json \ No newline at end of file diff --git a/app.py b/app.py index c437ece..4b19f37 100644 --- a/app.py +++ b/app.py @@ -1,30 +1,44 @@ from web3 import Web3 from flask import Flask, render_template, send_file, request, redirect +import json + +config = open('config.json') +cfg = json.load(config) + +coinName = cfg['coinName'] +coinSymbol = cfg['coinSymbol'] +coinSymbolLower = cfg['coinSymbolLower'] +rpcUrl = cfg['rpcUrl'] app = Flask(__name__) -coinName = "RESIN" -web3 = Web3(Web3.HTTPProvider("https://cum.ssniper1.ml")) +web3 = Web3(Web3.HTTPProvider(rpcUrl)) + @app.route("/static/") def style(file): return send_file("static/{file}".format(file=file)) + @app.route("/") def index(): latestBlock = web3.eth.block_number - return render_template("index.html", latestBlock=latestBlock) + return render_template("index.html", coinSymbolLower=coinSymbolLower, latestBlock=latestBlock) # --- API block --- # + + @app.route("/api/block/") def api_block(number): block = web3.eth.get_block(number) return str(block)[14:-1] + @app.route("/api/txhash/") def api_txhash(txhash): tx = str(web3.eth.getTransaction(txhash)) return tx + @app.route("/api/balance/
") def api_balance(address): balance = str(web3.eth.getBalance(address)) @@ -32,9 +46,11 @@ def api_balance(address): # --- End API block --- # # --- Explorer block --- # + + @app.route("/block/") def block(number): - + try: block = web3.eth.get_block(number) except: @@ -48,7 +64,7 @@ def block(number): logsBloom = "0x0" else: logsBloom = block["logsBloom"].hex() - + miner = block["miner"] mixHash = block["mixHash"].hex() nonce = block["nonce"].hex() @@ -60,7 +76,7 @@ def block(number): stateRoot = block["stateRoot"].hex() timestamp = block["timestamp"] totalDifficulty = block["totalDifficulty"] - + if not block['transactions']: transactions = "None" else: @@ -71,15 +87,16 @@ def block(number): uncles = block["uncles"] return render_template("block.html", difficulty=str(difficulty), extraData=str(extraData), - gasLimit=str(gasLimit), gasUsed=str(gasUsed), - hash=str(hash), logsBloom=str(logsBloom), - miner=str(miner), mixHash=str(mixHash), - nonce=str(nonce), number=str(number), - parentHash=str(parentHash), receiptsRoot=str(receiptsRoot), - sha3Uncles=str(sha3Uncles), size=str(size), - stateRoot=str(stateRoot), timestamp=str(timestamp), - totalDifficulty=str(totalDifficulty), transactions=str(transactions), - transactionsRoot=str(transactionsRoot), uncles=str(uncles)) + gasLimit=str(gasLimit), gasUsed=str(gasUsed), + hash=str(hash), logsBloom=str(logsBloom), + miner=str(miner), mixHash=str(mixHash), + nonce=str(nonce), number=str(number), + parentHash=str(parentHash), receiptsRoot=str(receiptsRoot), + sha3Uncles=str(sha3Uncles), size=str(size), + stateRoot=str(stateRoot), timestamp=str(timestamp), + totalDifficulty=str(totalDifficulty), transactions=str(transactions), + transactionsRoot=str(transactionsRoot), uncles=str(uncles), coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + @app.route("/block//uncles") def uncles(number): @@ -92,7 +109,8 @@ def uncles(number): parsed = [] for uncle in uncles: parsed.append(str(uncle.hex())) - return render_template("uncles.html", uncles=parsed, number=number) + return render_template("uncles.html", uncles=parsed, number=number, coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + @app.route("/block//transactions") def transactions(number): @@ -108,7 +126,9 @@ def transactions(number): parsed.append(str(transaction.hex())) if not parsed: parsed = ["None"] - return render_template("transactions.html", transactions=parsed, number=number) + return render_template("transactions.html", transactions=parsed, number=number, coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + + @app.route("/bloominfo/") def bloominfo(block): try: @@ -117,7 +137,8 @@ def bloominfo(block): return render_template("error.html", error="Block not found") bloom = block["logsBloom"].hex() blockNumber = block["number"] - return render_template("bloominfo.html", bloom=bloom, blockNumber=blockNumber) + return render_template("bloominfo.html", bloom=bloom, blockNumber=blockNumber, coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + @app.route("/account/
") def account(address): @@ -125,7 +146,8 @@ def account(address): nonce = web3.eth.getTransactionCount(address) balance_eth = web3.fromWei(balance, "ether") - return render_template("account.html", address=address, balance_eth=balance_eth, nonce=str(nonce), coinName=coinName) + return render_template("account.html", address=address, balance_eth=balance_eth, nonce=str(nonce), coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + @app.route("/tx/") def tx(txhash): @@ -146,10 +168,11 @@ def tx(txhash): txValue = format(txValueUnformatted, '.18f') txBlockHash = tx["blockHash"] txBlockNumber = tx["blockNumber"] - - return render_template("tx.html", txFrom=txFrom, txTo=txTo, txGas=txGas, txGasPrice=txGasPrice, - txHash=txHash, txNonce=txNonce, txValue=txValue, txBlockHash=txBlockHash, - txBlockNumber=txBlockNumber, coinName=coinName) + + return render_template("tx.html", coinName=coinName, txFrom=txFrom, txTo=txTo, txGas=txGas, txGasPrice=txGasPrice, + txHash=txHash, txNonce=txNonce, txValue=txValue, txBlockHash=txBlockHash, + txBlockNumber=txBlockNumber, coinSymbol=coinSymbol, coinSymbolLower=coinSymbolLower) + @app.route('/', methods=['POST']) def define_redirect(): @@ -164,7 +187,7 @@ def define_redirect(): if int(text): type = "block" except: - return render_template("error.html", error="Malformed input") + return render_template("error.html", error="Malformed input", coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) if type == "account": print(type) @@ -179,7 +202,14 @@ def define_redirect(): del type return redirect("/block/" + text) - return render_template("error.html", error="Malformed input") + return render_template("error.html", error="Malformed input", coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + + +@app.route("/contractinfo") +@app.route("/contractInfo") +def contractinfo(): + return render_template("contractinfo.html", coinSymbolLower=coinSymbolLower, coinSymbol=coinSymbol) + # --- End Explorer block --- # -app.run(host="0.0.0.0") \ No newline at end of file +app.run(host="0.0.0.0") diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..08effe1 --- /dev/null +++ b/config.json.example @@ -0,0 +1,6 @@ +{ + "coinName": "ResinCoin", + "coinSymbol": "RESIN", + "coinSymbolLower": "Resin", + "rpcUrl": "https://cum.ssniper1.ml" +} \ No newline at end of file diff --git a/static/style.css b/static/style.css index 2b74d79..563bf67 100644 --- a/static/style.css +++ b/static/style.css @@ -81,4 +81,13 @@ a:hover { background-color: transparent; text-decoration: none; transition: all 0.2s ease-in-out; +} + +.lowerleft +{ + margin-bottom: 3px; + margin-left : 1px; + position: fixed; + bottom: 0; + color: white; } \ No newline at end of file diff --git a/templates/account.html b/templates/account.html index 06573f3..8204d71 100644 --- a/templates/account.html +++ b/templates/account.html @@ -1,17 +1,20 @@ - - ResinScan - - - - - - -

ResinScan

- Balance of {{ address }}: -

- {{ balance_eth }} {{ coinName }} -

- Address has a total of {{ nonce }} transactions. - + + + {{ coinSymbolLower }}Scan + + + + + + + +

{{ coinSymbolLower }}Scan

+ Balance of {{ address }}: +

+ {{ balance_eth }} {{ coinSymbol }} +

+ Address has a total of {{ nonce }} transactions. + + \ No newline at end of file diff --git a/templates/block.html b/templates/block.html index a23e69c..a250162 100644 --- a/templates/block.html +++ b/templates/block.html @@ -1,21 +1,27 @@ - - ResinScan - - - - - - - -

ResinScan

-

+ + + {{ coinSymbolLower }}Scan + + + + + + + + +

{{ coinSymbolLower }}Scan

+

Difficulty: {{ difficulty }}
Extra data: {{ extraData }}
Gas limit: {{ gasLimit }}
Gas used: {{ gasUsed }}
Hash: {{ hash }}
- Logs bloom: {{ logsBloom }}
+ {% if logsBloom != "0x0" %} + Logs bloom: there.
+ {% else %} + Logs bloom: 0x0
+ {% endif %} Miner: {{ miner }}
Mix hash: {{ mixHash }}
Nonce: {{ nonce }}
@@ -34,6 +40,7 @@

ResinScan

{% if uncles != "None" %} Uncles: full list here
{% endif %} -

- +

+ + \ No newline at end of file diff --git a/templates/bloominfo.html b/templates/bloominfo.html index 8e924df..2a08212 100644 --- a/templates/bloominfo.html +++ b/templates/bloominfo.html @@ -1,13 +1,13 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

Bloom info of block {{ blockNumber }}:

{{ bloom }} diff --git a/templates/contractinfo.html b/templates/contractinfo.html new file mode 100644 index 0000000..23f4e33 --- /dev/null +++ b/templates/contractinfo.html @@ -0,0 +1,19 @@ + + + {{ coinSymbolLower }}Scan + + + + + + +

{{ coinSymbolLower }}Scan

+ More info about smart contracts: +

+ A smart contract is a program that is deployed in the blockchain and ran in an EVM.
+ Each such program has its own address, that looks like an Ethereum address.
+ When a smart contract is being deployed, it does not have an address and you send coins to None, which may be strange for you.
+ To remove any complains about the lack of address, we have written this small explanation.
+

+ + \ No newline at end of file diff --git a/templates/error.html b/templates/error.html index 3a60c04..c871557 100644 --- a/templates/error.html +++ b/templates/error.html @@ -1,13 +1,13 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

Sorry, error happened:

{{ error }} diff --git a/templates/index.html b/templates/index.html index d7950bb..fd80b5c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,13 +1,13 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

-
+
- +
+
+

There are {{ latestBlock }} blocks in the network.

\ No newline at end of file diff --git a/templates/transactions.html b/templates/transactions.html index 5549499..d9a2436 100644 --- a/templates/transactions.html +++ b/templates/transactions.html @@ -1,19 +1,19 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

List of all transactions for block {{ number }}: {% for transaction in transactions %} {% if transaction == "None" %}

No transactions found.

{% else %} -

{{ transaction }}

+

{{ transaction }}

{% endif %} {% endfor %}

diff --git a/templates/tx.html b/templates/tx.html index 2e76d40..68606a9 100644 --- a/templates/tx.html +++ b/templates/tx.html @@ -1,30 +1,30 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

{% if not txTo %} Transasction {{ txHash }} is a contract creation transaction.

From: {{ txFrom }}
To: more info
- Value: {{ txValue }} {{ coinName }}
+ Value: {{ txValue }} {{ coinSymbolLower }}
Gas used: {{ txGas }}
- Gas price: {{ txGasPrice }} {{ coinName }} + Gas price: {{ txGasPrice }} {{ coinSymbol }}

{% else %} Transaction {{ txHash }}:

From: {{ txFrom }}
To: {{ txTo }}
- Value: {{ txValue }} {{ coinName }}
+ Value: {{ txValue }} {{ coinSymbol }}
Gas used: {{ txGas }}
- Gas price: {{ txGasPrice }} {{ coinName }} + Gas price: {{ txGasPrice }} {{ coinSymbol }}

{% endif %} diff --git a/templates/uncles.html b/templates/uncles.html index 702dfbd..ba24f82 100644 --- a/templates/uncles.html +++ b/templates/uncles.html @@ -1,13 +1,13 @@ - ResinScan + {{ coinSymbolLower }}Scan -

ResinScan

+

{{ coinSymbolLower }}Scan

List of all uncles for block {{ number }}: {% if uncles %} {% for uncle in uncles %}