Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
added json config + example, now site is customizeable
Browse files Browse the repository at this point in the history
  • Loading branch information
SsNiPeR1 committed Jun 19, 2022
1 parent 8e1e5b8 commit 8fb4c97
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 75 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.pyc
config.json
82 changes: 56 additions & 26 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
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/<file>")
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/<int:number>")
def api_block(number):
block = web3.eth.get_block(number)
return str(block)[14:-1]


@app.route("/api/txhash/<txhash>")
def api_txhash(txhash):
tx = str(web3.eth.getTransaction(txhash))
return tx


@app.route("/api/balance/<address>")
def api_balance(address):
balance = str(web3.eth.getBalance(address))
return balance
# --- End API block --- #

# --- Explorer block --- #


@app.route("/block/<int:number>")
def block(number):

try:
block = web3.eth.get_block(number)
except:
Expand All @@ -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()
Expand All @@ -60,7 +76,7 @@ def block(number):
stateRoot = block["stateRoot"].hex()
timestamp = block["timestamp"]
totalDifficulty = block["totalDifficulty"]

if not block['transactions']:
transactions = "None"
else:
Expand All @@ -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/<int:number>/uncles")
def uncles(number):
Expand All @@ -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/<int:number>/transactions")
def transactions(number):
Expand All @@ -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/<int:block>")
def bloominfo(block):
try:
Expand All @@ -117,15 +137,17 @@ 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/<address>")
def account(address):
balance = web3.eth.getBalance(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/<txhash>")
def tx(txhash):
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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")
app.run(host="0.0.0.0")
6 changes: 6 additions & 0 deletions config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"coinName": "ResinCoin",
"coinSymbol": "RESIN",
"coinSymbolLower": "Resin",
"rpcUrl": "https://cum.ssniper1.ml"
}
9 changes: 9 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
33 changes: 18 additions & 15 deletions templates/account.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<html>
<head>
<title>ResinScan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
Balance of {{ address }}:
<p class="codebox">
{{ balance_eth }} {{ coinName }}
</p>
Address has a total of {{ nonce }} transactions.
</body>

<head>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>

<body>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
Balance of {{ address }}:
<p class="codebox">
{{ balance_eth }} {{ coinSymbol }}
</p>
Address has a total of {{ nonce }} transactions.
</body>

</html>
35 changes: 21 additions & 14 deletions templates/block.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<html>
<head>
<title>ResinScan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<base href="/block/{{ number }}/" />
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
<p class="codebox">

<head>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<base href="/block/{{ number }}/" />
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>

<body>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
<p class="codebox">
Difficulty: {{ difficulty }} <br>
Extra data: {{ extraData }} <br>
Gas limit: {{ gasLimit }} <br>
Gas used: {{ gasUsed }} <br>
Hash: {{ hash }} <br>
Logs bloom: {{ logsBloom }} <br>
{% if logsBloom != "0x0" %}
Logs bloom: <a href="/bloominfo/{{ number }}">there.</a><br>
{% else %}
Logs bloom: 0x0<br>
{% endif %}
Miner: <a href="/account/{{ miner }}">{{ miner }}</a> <br>
Mix hash: {{ mixHash }} <br>
Nonce: {{ nonce }} <br>
Expand All @@ -34,6 +40,7 @@ <h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
{% if uncles != "None" %}
Uncles: <a href="uncles">full list here</a><br>
{% endif %}
</p>
</body>
</p>
</body>

</html>
4 changes: 2 additions & 2 deletions templates/bloominfo.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<html>
<head>
<title>ResinScan</title>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
Bloom info of block {{ blockNumber }}:
<p class="codebox">
{{ bloom }}
Expand Down
19 changes: 19 additions & 0 deletions templates/contractinfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
More info about smart contracts:
<p class="codebox">
A smart contract is a program that is deployed in the blockchain and ran in an EVM. <br>
Each such program has its own address, that looks like an Ethereum address. <br>
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. <br>
To remove any complains about the lack of address, we have written this small explanation. <br>
</p>
</body>
</html>
4 changes: 2 additions & 2 deletions templates/error.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<html>
<head>
<title>ResinScan</title>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
Sorry, error happened:
<p class="codebox">
{{ error }}
Expand Down
10 changes: 6 additions & 4 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<html>
<head>
<title>ResinScan</title>
<title>{{ coinSymbolLower }}Scan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
<script src="/static/redir.js"></script>
<script src="https://kit.fontawesome.com/e9230a7663.js" crossorigin="anonymous"></script>
</head>
<body>
<h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
<h1><a href="/" class="a">{{ coinSymbolLower }}Scan <i class='fab fa-ethereum'></i></a></h1>
<!--
<input type="text" id="blockNumber" placeholder="Search for a block number...">
<button id="search" onclick="redirBlock()">Search</button> <br>
Expand All @@ -17,9 +17,11 @@ <h1><a href="/" class="a">ResinScan <i class='fab fa-ethereum'></i></a></h1>
<button id="search" onclick="redirAddress()">Search</button> <br>
<p>Current number of blocks in the network: <a href=/block/{{ latestBlock }}>{{ latestBlock }}</a></p>
-->
<div>
<div class="center">
<form method="POST" class="center">
<input name="text" placeholder="Search for an address, block number or transaction..." size="50">
<input name="text" placeholder="Search for an address, block number or transaction..." size="50"> <br>
</form>
</div>
<p class="lowerLeft">There are <a href="/block/{{ latestBlock }}">{{ latestBlock }}</a> blocks in the network.</p>
</body>
</html>
Loading

0 comments on commit 8fb4c97

Please sign in to comment.