58 lines
1.9 KiB
JavaScript
58 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const os = require('os')
|
|
const readline = require('readline')
|
|
|
|
const coinUtils = require('../lib/coin-utils')
|
|
const db = require('../lib/db')
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
})
|
|
|
|
const sql = `select regexp_replace(crypto_code, '$', ' ') as code,regexp_replace(address, '^', ' ') as address from blacklist`
|
|
const insertSql = `insert into blacklist(crypto_code, address, created_by_operator) values ($1, $2, 't')`
|
|
const makeDimAndReset = '\x1b[2m%s\x1b[0m'
|
|
|
|
db.query(sql)
|
|
.then(many => {
|
|
console.log(os.EOL, 'Here is your current list of prohibited addresses:', os.EOL)
|
|
console.log(many.map(it => `${it.code} | ${it.address}`).join(os.EOL), os.EOL)
|
|
console.log('What address would you like to add to the list?', os.EOL)
|
|
console.log(makeDimAndReset, 'Example:', 'bc1q8pu2zlfxg8jf4cyuf844rl3uxmmw8sj9yaa393', os.EOL)
|
|
|
|
rl.question('Address: ', (address) => {
|
|
var aphaNumericRegex = /^([0-9]|[a-z])+([0-9a-z]+)$/i
|
|
if (!address.match(aphaNumericRegex)) {
|
|
return errorHandler(new Error('Invalid address'))
|
|
}
|
|
|
|
console.log(os.EOL, 'What is the ticker symbol of the coin that this address belongs to?', os.EOL)
|
|
console.log(makeDimAndReset, 'Example:', 'BTC', os.EOL)
|
|
|
|
rl.question('Ticker symbol: ', (cryptoCode) => {
|
|
try {
|
|
coinUtils.getCryptoCurrency(cryptoCode)
|
|
} catch (err) {
|
|
errorHandler(err)
|
|
}
|
|
|
|
db.none(insertSql, [cryptoCode, address])
|
|
.then(() => db.query(sql))
|
|
.then(many2 => {
|
|
console.log(os.EOL, `Address added. Here's the new list of prohibited addresses:`, os.EOL)
|
|
console.log(many2.map(it => `${it.code} | ${it.address}`).join(os.EOL))
|
|
rl.close()
|
|
process.exit(0)
|
|
})
|
|
.catch(errorHandler)
|
|
})
|
|
})
|
|
}).catch(errorHandler)
|
|
|
|
function errorHandler (err) {
|
|
rl.close()
|
|
console.log(err)
|
|
process.exit(1)
|
|
}
|