ethereum-block-by-date
Advanced tools
Comparing version 1.4.6 to 1.4.7
"use strict"; | ||
const moment = require('moment'); | ||
module.exports = class { | ||
@@ -14,3 +13,2 @@ constructor(web3) { | ||
} | ||
async getBoundaries() { | ||
@@ -21,3 +19,2 @@ this.latestBlock = await this.getBlockWrapper('latest'); | ||
} | ||
async getDate(date, after = true, refresh = false) { | ||
@@ -32,8 +29,6 @@ if (!moment.isMoment(date)) date = moment(date).utc(); | ||
} | ||
async getEvery(duration, start, end, every = 1, after = true, refresh = false) { | ||
start = moment(start), end = moment(end); | ||
let current = start, | ||
dates = []; | ||
dates = []; | ||
while (current.isSameOrBefore(end)) { | ||
@@ -43,7 +38,5 @@ dates.push(current.format()); | ||
} | ||
if (typeof this.firstBlock == 'undefined' || typeof this.latestBlock == 'undefined' || typeof this.blockTime == 'undefined' || refresh) await this.getBoundaries(); | ||
return await Promise.all(dates.map(date => this.getDate(date, after))); | ||
} | ||
async findBetter(date, predictedBlock, after, blockTime = this.blockTime) { | ||
@@ -58,6 +51,4 @@ if (await this.isBetterBlock(date, predictedBlock, after)) return predictedBlock.number; | ||
} | ||
async isBetterBlock(date, predictedBlock, after) { | ||
let blockTime = moment.unix(predictedBlock.timestamp); | ||
if (after) { | ||
@@ -72,6 +63,4 @@ if (blockTime.isBefore(date)) return false; | ||
} | ||
return false; | ||
} | ||
getNextBlock(date, currentBlock, skip) { | ||
@@ -84,3 +73,2 @@ let nextBlock = currentBlock + skip; | ||
} | ||
returnWrapper(date, block) { | ||
@@ -93,3 +81,2 @@ return { | ||
} | ||
async getBlockWrapper(block) { | ||
@@ -108,3 +95,2 @@ if (this.savedBlocks[block]) return this.savedBlocks[block]; | ||
} | ||
}; |
{ | ||
"name": "ethereum-block-by-date", | ||
"version": "1.4.6", | ||
"version": "1.4.7", | ||
"description": "Get Ethereum block number by a given date. Or blocks by a given period duration.", | ||
@@ -35,13 +35,14 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.19.3", | ||
"@babel/core": "^7.19.3", | ||
"@babel/preset-env": "^7.19.3", | ||
"chai": "^4.3.6", | ||
"@babel/cli": "^7.21.0", | ||
"@babel/core": "^7.21.4", | ||
"@babel/preset-env": "^7.21.4", | ||
"chai": "^4.3.7", | ||
"dotenv": "^16.0.3", | ||
"eslint": "^8.24.0", | ||
"ethers": "^5.7.1", | ||
"mocha": "^10.0.0", | ||
"prettier": "^2.7.1", | ||
"rimraf": "^3.0.2", | ||
"web3": "^1.8.0" | ||
"eslint": "^8.38.0", | ||
"ethers": "^6.3.0", | ||
"ethers-v5": "npm:ethers@5.7.2", | ||
"mocha": "^10.2.0", | ||
"prettier": "^2.8.7", | ||
"rimraf": "^5.0.0", | ||
"web3": "^1.9.0" | ||
}, | ||
@@ -48,0 +49,0 @@ "browserslist": [ |
@@ -42,2 +42,7 @@ # Ethereum Block By Date | ||
const { ethers } = require('ethers'); | ||
// For Ethers.js v6 use: | ||
const provider = new ethers.CloudflareProvider(); | ||
// For Ethers.js v5 use: | ||
const provider = new ethers.providers.CloudflareProvider(); | ||
@@ -44,0 +49,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11880
148
12