Prevent address reuse option
This commit is contained in:
parent
55cdc2fa52
commit
98cc3b18b7
9 changed files with 141 additions and 13 deletions
|
|
@ -12,7 +12,7 @@ const rl = readline.createInterface({
|
|||
})
|
||||
|
||||
const sql = `select regexp_replace(crypto_code, '$', ' ') as code,regexp_replace(address, '^', ' ') as address from blacklist`
|
||||
const insertSql = `insert into blacklist(crypto_code, address) values ($1, $2)`
|
||||
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)
|
||||
|
|
|
|||
58
bin/lamassu-remove-from-blacklist
Normal file
58
bin/lamassu-remove-from-blacklist
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#!/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 deleteSql = `delete from blacklist where crypto_code = $1 and address = $2`
|
||||
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 remove from 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(deleteSql, [cryptoCode, address])
|
||||
.then(() => db.query(sql))
|
||||
.then(many2 => {
|
||||
console.log(os.EOL, `Address removed. 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue