Skip to content

Commit 80c3896

Browse files
committed
Adding event and transaction types
1 parent 25806ef commit 80c3896

File tree

6 files changed

+138
-47
lines changed

6 files changed

+138
-47
lines changed

.DS_Store

2 KB
Binary file not shown.

app.py

+46-18
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
"okbc_testnet": "https://okbc-testnet.hypersync.xyz"
3333
}
3434

35-
3635
app = Flask(__name__)
3736

3837
@app.route('/', methods=['GET', 'POST'])
3938
def index():
4039
if request.method == 'POST':
4140
address = request.form['address']
4241
address = address.lower()
43-
print(address)
42+
request_type = request.form['type']
4443
selected_network = request.form['network']
4544
network_url = NETWORK_URLS.get(selected_network, "https://eth.hypersync.xyz")
4645
try:
47-
directory = asyncio.run(fetch_data(address, selected_network, network_url))
48-
img = create_plot(directory)
46+
directory = asyncio.run(fetch_data(address, selected_network, network_url, request_type))
47+
img = create_plot(directory, request_type)
48+
# img = 'data:image/png;base64,./assets/sad-pepe.png'
4949
return render_template('plot.html', plot_url=img)
5050
except Exception as e:
5151
print(f"Error: {e}")
@@ -54,27 +54,49 @@ def index():
5454
return render_template('index.html')
5555

5656

57-
async def fetch_data(address, selected_network, network_url):
57+
async def fetch_data(address, selected_network, network_url, request_type):
5858
# Create hypersync client using the chosen hypersync endpoint
5959
client = hypersync.hypersync_client(network_url)
60+
is_event_request = request_type == "event"
6061

6162
# The query to run
62-
query = {
63-
"from_block": 0,
64-
"logs": [{"address": [address]}],
65-
"field_selection": {
66-
"log": ["block_number", "log_index", "transaction_index"],
67-
},
68-
}
63+
if is_event_request:
64+
query = {
65+
"from_block": 0,
66+
"logs": [{"address": [address]}],
67+
"field_selection": {
68+
"log": ["block_number", "log_index", "transaction_index"],
69+
},
70+
}
71+
else:
72+
query = {
73+
"from_block": 0,
74+
"transactions": [
75+
# We want all the transactions that come from this address
76+
{"from": [address]},
77+
# We want all the transactions that went to this address
78+
{"to": [address]},
79+
],
80+
"field_selection": {
81+
"transaction": [
82+
"block_number",
83+
"transaction_index",
84+
"hash",
85+
],
86+
},
87+
}
6988

7089
# Create a directory named after the address
71-
directory = f"data_{selected_network}_{address}"
90+
directory = f"data/data_{selected_network}_{request_type}_{address}"
7291
if not os.path.exists(directory):
7392
os.makedirs(directory)
7493
await client.create_parquet_folder(query, directory)
7594
print("Finished writing parquet folder")
7695
else:
77-
if is_parquet_empty(f'{directory}/log.parquet'):
96+
if is_event_request and is_parquet_empty(f'{directory}/log.parquet'):
97+
await client.create_parquet_folder(query, directory)
98+
print("Parquet previously wasn't successfully populated")
99+
elif not is_event_request and is_parquet_empty(f'{directory}/transaction.parquet'):
78100
await client.create_parquet_folder(query, directory)
79101
print("Parquet previously wasn't successfully populated")
80102
else:
@@ -102,17 +124,22 @@ def round_based_on_magnitude(number):
102124
return round(number / 100000) * 100000
103125

104126

105-
def create_plot(directory):
106-
plt.figure(figsize=(15, 9)) # Width, Height in inches
127+
def create_plot(directory, request_type):
128+
plt.figure(figsize=(15, 7)) # Width, Height in inches
107129
# Read the log.parquet file
108-
df = pd.read_parquet(f'{directory}/log.parquet')
130+
is_event_request = request_type == "event"
131+
132+
if is_event_request:
133+
df = pd.read_parquet(f'{directory}/log.parquet')
134+
else:
135+
df = pd.read_parquet(f'{directory}/transaction.parquet')
109136

110137

111138
# Define the interval size
112139
min_block = df['block_number'].min()
113140
max_block = df['block_number'].max()
114141

115-
interval_size = max(10000, round_based_on_magnitude((max_block - min_block)/ 50))
142+
interval_size = max(5000, round_based_on_magnitude((max_block - min_block)/ 50))
116143

117144
min_block_rounded = min_block - (min_block % interval_size)
118145

@@ -151,5 +178,6 @@ def create_plot(directory):
151178
buf.close()
152179
return f'data:image/png;base64,{plot_url}'
153180

181+
154182
if __name__ == '__main__':
155183
app.run(debug=True, host='0.0.0.0', port=5001)

assets/sad-pepe.png

168 KB
Loading

data/.DS_Store

10 KB
Binary file not shown.

read.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
df = pd.read_parquet('data_eth_0x5bf9dfb1b27c28e5a1d8e5c5385a1a353ec9d118/log.parquet')
44

55
print(len(df))
6-
print(df.head(50))
6+
print(df.head(10))
7+
print(df.describe())

templates/index.html

+90-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,97 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Event Density Viewer</title>
4+
<title> Density Viewer</title>
5+
<style>
6+
body {
7+
font-family: Arial, sans-serif;
8+
background-color: #f4f4f4;
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
height: 100vh;
13+
margin: 0;
14+
}
15+
.container {
16+
background-color: #fff;
17+
padding: 40px;
18+
border-radius: 10px;
19+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
20+
}
21+
h1 {
22+
text-align: center;
23+
color: #333;
24+
}
25+
form {
26+
display: flex;
27+
flex-direction: column;
28+
width: 300px;
29+
}
30+
input[type="text"] {
31+
padding: 10px;
32+
margin: 10px 0;
33+
border: 1px solid #ddd;
34+
border-radius: 5px;
35+
box-sizing: border-box;
36+
font-size: 16px;
37+
}
38+
select {
39+
padding: 10px;
40+
margin-bottom: 20px;
41+
border: 1px solid #ddd;
42+
border-radius: 5px;
43+
font-size: 16px;
44+
}
45+
input[type="submit"] {
46+
padding: 10px;
47+
background-color: #bb581a;
48+
border: none;
49+
border-radius: 5px;
50+
color: white;
51+
cursor: pointer;
52+
transition: background-color 0.3s;
53+
}
54+
input[type="submit"]:hover {
55+
background-color: #d29656;
56+
}
57+
58+
</style>
559
</head>
660
<body>
7-
<h1>Enter Smart Contract Address and Select Network</h1>
8-
<form method="post">
9-
Smart Contract Address: <input type="text" name="address" /><br />
10-
Network:
11-
<select name="network">
12-
<option value="arbitrum">Arbitrum</option>
13-
<option value="base">Base</option>
14-
<option value="bsc">BSC</option>
15-
<option value="eth">Ethereum</option>
16-
<option value="gnosis">Gnosis</option>
17-
<option value="goerli">Goerli</option>
18-
<option value="linea">Linea</option>
19-
<option value="optimism">Optimism</option>
20-
<option value="polygon">Polygon</option>
21-
<option value="scroll">Scroll</option>
22-
<option value="sepolia">Sepolia</option>
23-
<option value="taiko_jolnr">Taiko Jolnr</option>
24-
<option value="manta">Manta</option>
25-
<option value="polygon_zkevm">Polygon ZkEVM</option>
26-
<option value="metis">Metis</option>
27-
<option value="kroma">Kroma</option>
28-
<option value="celo">Celo</option>
29-
<option value="zksync">zkSync</option>
30-
<option value="okbc_testnet">OKBC Testnet</option></select
31-
><br />
32-
<input type="submit" value="Submit" />
33-
</form>
61+
<div class="container">
62+
<h1>Density Scanner Tool</h1>
63+
<h3>Event and Transaction density graphed</h3>
64+
<form method="post">
65+
<label for="address">Address:</label>
66+
<input type="text" id="address" name="address" />
67+
<label for="type">Event or Transaction:</label>
68+
<select id="type" name="type">
69+
<option value="event">Event</option>
70+
<option value="transaction">Transaction</option>
71+
</select>
72+
<label for="network">Network:</label>
73+
<select id="network" name="network">
74+
<option value="eth">Ethereum</option>
75+
<option value="arbitrum">Arbitrum</option>
76+
<option value="base">Base</option>
77+
<option value="optimism">Optimism</option>
78+
<option value="polygon">Polygon</option>
79+
<option value="bsc">BSC</option>
80+
<option value="gnosis">Gnosis</option>
81+
<option value="goerli">Goerli</option>
82+
<option value="linea">Linea</option>
83+
<option value="scroll">Scroll</option>
84+
<option value="sepolia">Sepolia</option>
85+
<option value="taiko_jolnr">Taiko Jolnr</option>
86+
<option value="manta">Manta</option>
87+
<option value="polygon_zkevm">Polygon ZkEVM</option>
88+
<option value="metis">Metis</option>
89+
<option value="kroma">Kroma</option>
90+
<option value="celo">Celo</option>
91+
<option value="zksync">zkSync</option>
92+
<option value="okbc_testnet">OKBC Testnet</option>
93+
</select>
94+
<input type="submit" value="Submit" />
95+
</form>
3496
</body>
3597
</html>

0 commit comments

Comments
 (0)