Created
August 8, 2015 00:19
-
-
Save 4z3/f84312088da7560bd9da to your computer and use it in GitHub Desktop.
eth tv.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tv = {}; (function () { | |
tv.txhashes = [ | |
'0xlol', | |
] | |
function bal(a) { | |
return web3.fromWei(eth.getBalance(a), "ether") | |
} | |
function confs (tx) { | |
return web3.eth.blockNumber - eth.getTransaction(tx).blockNumber | |
} | |
tv.bals = function bals () { | |
var out = {} | |
personal.listAccounts.forEach(function (a) { | |
out[a] = bal(a).toNumber() | |
}) | |
return out | |
} | |
tv.confs = function (txs) { | |
var out = {} | |
txs = txs || tv.txhashes | |
Object.keys(txs).forEach(function (i) { | |
var tx = txs[i] | |
out[tx] = { | |
confs: confs(tx), | |
//eta_s: (6000 - confs(tx)) * 12, | |
eta: formatTime((6000 - confs(tx)) * 12), | |
} | |
}) | |
out = { | |
now: (new Date).toISOString(), | |
val: out, | |
} | |
return out | |
} | |
function formatTime (s) { | |
var out = '' | |
;[ | |
{ f: 3600, u: 'h' }, | |
{ f: 60, u: 'm' }, | |
{ f: 1, u: 's' }, | |
].forEach(function (x) { | |
var f = x.f | |
var u = x.u | |
var n = s / f | 0 | |
if (n > 0) { | |
out += n + u | |
s = s % f | |
} | |
}) | |
return out | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment