-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
49 lines (42 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const Web3 = require('web3');
const logger = require('log4js').getLogger('etherscanner');
const async = require('async');
const fs = require('fs');
const Geth = require('./geth.js');
const Parity = require('./parity.js');
class EtherScanner {
/**
*
* @param HttpProvider
* @param loggerLevel
*/
constructor(HttpProvider, loggerLevel = 'OFF') {
logger.level = loggerLevel;
this.requestId = 1;
this.web3 = new Web3(HttpProvider);
if (!this.web3.isConnected()) {
logger.error("Ethereum node is not connected");
return;
}
logger.info('WEB3 connected');
this.node = this.web3.version.node.match(/Parity/) ? new Parity(this.web3) : new Geth(this.web3);
}
}
module.exports = (HttpProvider, loggerLevel) => {
let scanner = new EtherScanner(HttpProvider, loggerLevel);
return {
scanBlock: scanner.node.scanBlock.bind(scanner.node),
scanTransaction: scanner.node.scanTransaction.bind(scanner.node),
}
};
/**
* @typedef {object} etherscannerObj
* @property {String} hash
* @property {String} from
* @property {String} to
* @property {Number} value
* @property {Number} blockNumber
* @property {String} blockHash
* @property {Boolean} isInternal
* @property {String} type
*/