forked from austintgriffith/clevis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
32 lines (29 loc) · 904 Bytes
/
utils.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
const winston = require('winston')
function checkForReceipt(backoffMs, params, transactionHash, resolve) {
params.web3.eth.getTransactionReceipt(transactionHash,(error,result) => {
if(result && result.transactionHash){
winston.debug(result)
resolve(result)
} else {
if(winston.level === 'debug') process.stdout.write(".")
backoffMs = Math.min(backoffMs * 2, 1000)
setTimeout(checkForReceipt.bind(this, backoffMs, params, transactionHash, resolve), backoffMs)
}
})
}
async function normalizeAddress(addr, web3) {
if(web3.utils.isAddress(addr)) {
return web3.utils.toChecksumAddress(addr)
} else {
let accounts = await web3.eth.getAccounts()
if(accounts[addr] !== undefined) {
return accounts[addr]
} else {
throw(`Could not normalize address: ${addr}`)
}
}
}
module.exports = {
checkForReceipt,
normalizeAddress
}