作者:是乐浅浅啊
看到人家欧科云链的链上天眼,浅浅就也想要做一个跟他们一模一样的社区天眼,初步规划是有三个步骤。
- 获取全网地址和地址余额,并存入MySQL数据库
- 通过微信小程序,实现地址余额查询
- 实现监控地址大额异动的实时警报
目前浅浅社区数据库,已经处理200万条区块信息,获得超过20,000个主网地址,处理的程序我索性也开源啦:
使用的是 PlatON Python SDK
from client_sdk_python import Web3, HTTPProvider
from client_sdk_python.eth import PlatON
from hexbytes import HexBytes
import pymysql
# using mysql to save the address for platon by qianqian
db = pymysql.connect(host='你的数据库ip地址',
user='你的数据库用户名',
password='你的数据库密码',
database='连接的数据库名称')
cursor = db.cursor()
w3 = Web3(HTTPProvider("http://*.*.*.*:6789"))
platon = PlatON(w3)
for i in range(开始区块编号,结束区块编号):
if platon.getBlock(i).gasUsed != 0:
if platon.getTransactionByBlock(i,0).to == None:
print("第",i,"个区块找不到接收地址")
continue
else:
print("地址",i,"是:",platon.getTransactionByBlock(i,0).to)
latAddress = platon.getTransactionByBlock(i,0).to
sql_select = "SELECT * FROM `表名` WHERE 地址字段 = %s"
cursor.execute(sql_select,latAddress)
results = cursor.fetchall()
if len(results) != 0 :
print("该地址已存在了!")
else:
sql_insert = "INSERT INTO `表名` (地址字段) VALUES ('%s')" % (latAddress)
cursor.execute(sql_insert)
db.commit()
else:
print("第",i,"次的燃气为",platon.getBlock(i).gasUsed)
continue
本文转载自https://forum.latticex.foundation/t/topic/5681