feat: create blacklist page
This commit is contained in:
parent
8a9de5d185
commit
fd6f1a2fe0
9 changed files with 446 additions and 14 deletions
|
|
@ -1,22 +1,52 @@
|
|||
const db = require('./db')
|
||||
|
||||
function blocked (address, cryptoCode) {
|
||||
const sql = `select * from blacklist where address = $1 and crypto_code = $2`
|
||||
return db.any(sql, [
|
||||
address,
|
||||
cryptoCode
|
||||
])
|
||||
// Get all blacklist rows from the DB "blacklist" table
|
||||
const getBlacklist = () => {
|
||||
return db.any('select * from blacklist').then(res =>
|
||||
res.map(item => ({
|
||||
cryptoCode: item.crypto_code,
|
||||
address: item.address,
|
||||
createdByOperator: item.created_by_operator
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
function addToUsedAddresses (address, cryptoCode) {
|
||||
// Delete row from blacklist table by crypto code and address
|
||||
const deleteFromBlacklist = (cryptoCode, address) => {
|
||||
return db.none(
|
||||
'delete from blacklist where crypto_code = $1 and address = $2;',
|
||||
[cryptoCode, address]
|
||||
)
|
||||
}
|
||||
|
||||
const insertIntoBlacklist = (cryptoCode, address) => {
|
||||
return db
|
||||
.any(
|
||||
'insert into blacklist(crypto_code, address, created_by_operator) values($1, $2, $3);',
|
||||
[cryptoCode, address, true]
|
||||
)
|
||||
.then(() => {
|
||||
return { cryptoCode, address }
|
||||
})
|
||||
}
|
||||
|
||||
function blocked(address, cryptoCode) {
|
||||
const sql = `select * from blacklist where address = $1 and crypto_code = $2`
|
||||
return db.any(sql, [address, cryptoCode])
|
||||
}
|
||||
|
||||
function addToUsedAddresses(address, cryptoCode) {
|
||||
// ETH reuses addresses
|
||||
if (cryptoCode === 'ETH') return Promise.resolve()
|
||||
|
||||
const sql = `insert into blacklist(crypto_code, address, created_by_operator) values ($1, $2, 'f')`
|
||||
return db.oneOrNone(sql, [
|
||||
cryptoCode,
|
||||
address
|
||||
])
|
||||
return db.oneOrNone(sql, [cryptoCode, address])
|
||||
}
|
||||
|
||||
module.exports = { blocked, addToUsedAddresses }
|
||||
module.exports = {
|
||||
blocked,
|
||||
addToUsedAddresses,
|
||||
getBlacklist,
|
||||
deleteFromBlacklist,
|
||||
insertIntoBlacklist
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue