From 1a95671c3f139fef3f9ffc0552d7a033d4dd3e2b Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Wed, 16 May 2018 15:17:58 +0300 Subject: [PATCH 1/2] rename analytics to ts --- basic/{analytics.js => analytics.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename basic/{analytics.js => analytics.ts} (100%) diff --git a/basic/analytics.js b/basic/analytics.ts similarity index 100% rename from basic/analytics.js rename to basic/analytics.ts From 312b8f1b7cba33058e9b793bead08a70b540dfb5 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Wed, 16 May 2018 09:50:15 +0300 Subject: [PATCH 2/2] convert analytics to ts --- basic/analytics.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/basic/analytics.ts b/basic/analytics.ts index 3bb356a..483dc51 100644 --- a/basic/analytics.ts +++ b/basic/analytics.ts @@ -1,4 +1,5 @@ -var Web3 = require('web3'); +import Web3 from 'web3'; +import { Block, TransactionReceipt } from 'web3/types'; //////////////////////////////////////////////////////////////////////////// ////////////////////////// GLOBAL VARIABLES //////////////////////////////// @@ -7,6 +8,16 @@ var Web3 = require('web3'); var web3 = new Web3(); web3.setProvider(new web3.providers.HttpProvider('http://localhost:8100')); +interface ExtendedBlock extends Block { + time: string; +} + +interface ExtendedTransactionReceipt extends TransactionReceipt { + input: string; + gasPrice: string; + gas: number; +} + // DATABASE TO BE var dbBlocks = []; // ARRAY OF BLOCKS // var dbTrans = []; @@ -743,7 +754,7 @@ export const getBalancePerBlockOfAccount = function( const getBlockInfoMinimalNoChecks = function(blockNumber) { return web3.eth .getBlock(blockNumber, true) - .then(bl => { + .then((bl: ExtendedBlock) => { // bl.timestamp = this.decodeTime(bl.timestamp); bl.time = decodeTime(bl.timestamp); return bl; @@ -763,7 +774,7 @@ export const getBlockInfoMinimal = function(blockNumber) { var check = searchFor(blockNumber); if (check === -1) { - web3.eth.getBlock(blockNumber, true).then(bl => { + web3.eth.getBlock(blockNumber, true).then((bl: ExtendedBlock) => { // console.log("GET BLOCK: " + blockNumber); // SAVE TO DB bl.timestamp = decodeTime(bl.timestamp); @@ -784,7 +795,7 @@ export const getBlockInfoMinimal = function(blockNumber) { } } else { // console.log("VVVVVVVVVVVVV"); - web3.eth.getBlock(res, true).then(bl => { + web3.eth.getBlock(res, true).then((bl: ExtendedBlock) => { // console.log("IN IFFFF GET BLOCK: " + res); // SAVE TO DB dbBlocks.push(bl); @@ -970,7 +981,7 @@ export const getNumberOfTranscationsOfAccountPerBlock = function( const getTranscationInfo = function(e) { return web3.eth .getTransactionReceipt(e.hash) - .then(res => { + .then((res: ExtendedTransactionReceipt) => { if (res !== null) { // console.log("Input: " + rs.input); res.input = e.input; @@ -1001,7 +1012,7 @@ export const getTranscationInfoHash = function(hash) { if (rs !== null) { web3.eth .getTransactionReceipt(rs.hash) - .then(res => { + .then((res: ExtendedTransactionReceipt) => { if (res !== null) { // console.log("Input: " + rs.input); res.input = rs.input; @@ -1761,7 +1772,7 @@ export const getContractDetails = function(startBlockNumber, endBlockNumber) { }); }; -const getBalance = function(account, block) { +const getBalance = function(account, block?) { return new Promise((resolve, reject) => { if (block) { web3.eth