当前位置:网站首页>GetEmptyBlcoksPre Info
GetEmptyBlcoksPre Info
2022-06-21 17:49:00 【blockchain_yhj】
// Part 1 Import Related Package
var Web3 = require('web3');
var mongoose = require('mongoose');
var moment = require('moment');
const startBlock = 14983823;
const endBlock = 14983831;
var preBlockNum = 0;
var preBlockMiner = "";
var preBlockBasefee = 0;
var preBlockTxcount = 0;
var preBlockGasusage = 0;
const ethContractSchema = mongoose.Schema({
blockNumber: String,
miner: String,
basefee:String,
txcount:String,
gasusage:String,
preblockNumber: String,
preminer: String,
prebasefee:String,
pretxcount:String,
pregasusage:String
//code: String,
//storage: String,
});
const EthContract = mongoose.model('emptypreinfo', ethContractSchema);
EthContract.addContract = function(newContract, callback) {
newContract.save(callback);
};
EthContract.updateContract = function(contractAddress, newblockNumber, newminer,newbasefee,newcount,newgasusage,newpreblockNumber, newpreminer,newprebasefee,newprecount,newpregasusage) {
EthContract.update({
address: contractAddress}, {
$set: {
"blockNumber": newblockNumber,
"miner": newminer,
"basefee":newbasefee,
"txcount":newcount,
"gasusage":newgasusage,
"preblockNumber": newpreblockNumber,
"preminer": newpreminer,
"prebasefee":newprebasefee,
"pretxcount":newprecount,
"pregasusage":newpregasusage
}}, (err, suc) => {
});
}
EthContract.checkUnique = function(contractAddress) {
let res = EthContract.find({
address: contractAddress});
console.log(res);
if(res) return false;
return true;
};
async function connectDB() {
mongoose.connect('mongodb://localhost:27017/eth_blockminer');
mongoose.connection.on('connected', () => {
console.log('MongoDB has started successfully.');
});
mongoose.connection.on('error', (err) => {
console.log('Database error' + err);
});
}
// Part Connection to Local RPC
async function connectWeb3() {
web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/daa578881869407da748a2603f5cee52"));
//web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8546"));
global.web3 = web3;
console.log('web3 has connected successfully.');
}
async function scanTheChain() {
for(let i = startBlock; i <= endBlock; i++) {
console.log('scanning the chain.');
console.log("[ " + moment().format('MMMM Do YYYY, h:mm:ss a') + " ] " + "Scanning Block " + i);
var blockInfo = await web3.eth.getBlock(i);
var blockMiner = blockInfo.miner;
var blockBasefee = blockInfo.baseFeePerGas;
var blockTxCnt = await web3.eth.getBlockTransactionCount(i);
var blockGasusage = blockInfo.gasUsed;
console.log('TxCount.'+blockTxCnt);
if (blockTxCnt = 0){
EthContract.addContract(new EthContract({
blockNumber: i,
miner: blockMiner,
basefee: blockBasefee,
txcount: blockTxCnt,
gasusage: blockGasusage,
preblockNumber: preBlockNum,
preminer: preBlockMiner,
prebasefee: preBlockBasefee,
pretxcount: preBlockTxcount,
pregasusage: preBlockGasusage
}));
}
preBlockNum = i;
preBlockMiner = blockMiner;
preBlockBasefee = blockBasefee;
preBlockTxcount = blockTxCnt;
preBlockGasusage = blockGasusage;
}
}
// Part Main Function
(async function main(){
moment.locale('zh-cn');
await connectDB();
await connectWeb3();
await scanTheChain();
})();
nohup node EmptyPreInfo.js >>EmptyPreInfo.log 2>&1 &
use eth_blockminer;
db.emptypreinfos.count()
json
mongoexport --forceTableScan -d eth_blockminer -c emptypreinfos -o ./emptypreinfos.json
json–csv
cat emptypreinfos.json | jsoncsv | mkexcel > emptypreinfos.csv
边栏推荐
- Canvas dynamic background text luminous JS effect
- R language bug? report errors? As for the outcome of sub variables 0 and 1, the original content of the outcome variable is changed through the process of factor and numeric?
- Explanation of El table paging select all function
- [AISI software] wechat applet development quotation scheme template
- Three. JS 3D particle animation JS special effect code
- 使用ip怎么申请ssl证书
- 9. suffix and prefix functions -suffix basename addsuffix addprefix
- Full screen menu animation effect expansion in the upper left corner of SVG
- MarkDown初级语法一文精通,兼容MarkText
- Listener and filter (monitor and interceptor) in Servlet
猜你喜欢

【Go语言】Go语言我们应该这样学~全网较全的学习教程

Six steps of JDBC programming

文件上传漏洞靶场分析 UPLOAD_LABS

Servlet中Listener与Filter (监视器与拦截器)

GoF模式-03-行为型模式(下)

Canvas dynamic mesh background JS effect

Cookies and sessions

Niuke: merging two ordered arrays

数据库主键一定要自增吗?有哪些场景不建议自增?

From "village run enterprise" to "ten billion group", why did red star industry complete the "butterfly transformation"?
随机推荐
JDBC编程六步
产品图文列表说明布局样式
9. suffix and prefix functions -suffix basename addsuffix addprefix
Alibaba cloud Yum source configuration
南信大2020-2021第一学期FPGA/CPLD期末试卷
How to use DBA_ hist_ active_ sess_ History analysis database history performance problems
Cookies and sessions
Get some eth from the faucet of the ropsten test network
Must the database primary key be self incremented? What scenarios do not suggest self augmentation?
Canvas interactive color gradient JS special effect code
El expression
数据库主键一定要自增吗?有哪些场景不建议自增?
8. get directory function / get file function -dir / -notdir
GOF mode-03-behavioral mode (bottom)
Servlet中Listener与Filter (监视器与拦截器)
C语言刷题随记 —— 求 s=a+aa+aaa+aaaa+aa...a 的值
Does the school belong to a securities company? Is it safe to open an account?
阿里云yum源配置
JSP 基本知识
[Shangshui Shuo series] day one