add cancel script
This commit is contained in:
parent
985e3811e3
commit
d2700b4eb3
4 changed files with 58 additions and 8 deletions
25
bin/lamassu-cancel
Executable file
25
bin/lamassu-cancel
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const uuid = require('@fczbkk/uuid4')
|
||||
|
||||
const tx = require('../lib/cash-out-tx')
|
||||
|
||||
const argv = process.argv.slice(2)
|
||||
|
||||
if (argv.length !== 1) {
|
||||
console.log('Usage: lamassu-cancel <tx-id>')
|
||||
console.log('Cancels the cash out transaction with given tx-id so it cannot be dispensed.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const txId = argv[0]
|
||||
|
||||
if (!uuid.validate(txId)) {
|
||||
console.log('tx-id must be valid uuid. e.g.: f8093ded-c542-4916-8ab5-6ebeceb287c1')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
tx.cancel(txId)
|
||||
.then(() => console.log('Success.'))
|
||||
.catch(err => console.log(`Error: ${err.message}`))
|
||||
.then(() => process.exit(0))
|
||||
|
|
@ -12,7 +12,8 @@ module.exports = {
|
|||
post,
|
||||
monitorLiveIncoming,
|
||||
monitorStaleIncoming,
|
||||
monitorUnnotified
|
||||
monitorUnnotified,
|
||||
cancel
|
||||
}
|
||||
|
||||
const mapValuesWithKey = _.mapValues.convert({cap: false})
|
||||
|
|
@ -273,3 +274,21 @@ function monitorUnnotified (settings) {
|
|||
.then(txs => Promise.all(txs.map(notify)))
|
||||
.catch(logger.error)
|
||||
}
|
||||
|
||||
function cancel (txId) {
|
||||
const updateRec = {
|
||||
'dispense_time': 'now()^',
|
||||
dispense_error: 'Operator cancel',
|
||||
dispensed: true
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
return pgp.helpers.update(updateRec, null, 'cash_out_txs') +
|
||||
pgp.as.format(' where id=$1', [txId])
|
||||
})
|
||||
.then(sql => db.result(sql, false))
|
||||
.then(res => {
|
||||
if (res.rowCount !== 1) throw new Error('No such tx-id')
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
"license": "Unlicense",
|
||||
"author": "Lamassu (https://lamassu.is)",
|
||||
"dependencies": {
|
||||
"@fczbkk/uuid4": "^3.0.0",
|
||||
"axios": "^0.16.1",
|
||||
"base-x": "^3.0.0",
|
||||
"bignumber.js": "^4.0.1",
|
||||
|
|
@ -56,7 +57,8 @@
|
|||
"lamassu-backup-pg": "./bin/lamassu-backup-pg",
|
||||
"lamassu-install-bitcoind": "./bin/lamassu-install-bitcoind",
|
||||
"lamassu-install-geth": "./bin/lamassu-install-geth",
|
||||
"lamassu-mnemonic": "./bin/lamassu-mnemonic"
|
||||
"lamassu-mnemonic": "./bin/lamassu-mnemonic",
|
||||
"lamassu-cancel": "./bin/lamassu-cancel"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "ava"
|
||||
|
|
|
|||
16
yarn.lock
16
yarn.lock
|
|
@ -37,6 +37,10 @@
|
|||
ansi-styles "^2.2.1"
|
||||
esutils "^2.0.2"
|
||||
|
||||
"@fczbkk/uuid4@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@fczbkk/uuid4/-/uuid4-3.0.0.tgz#964b221cb955e1cb0f044767a966828023a384bb"
|
||||
|
||||
abbrev@1:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
|
||||
|
|
@ -1341,9 +1345,9 @@ dateformat@^1.0.12:
|
|||
get-stdin "^4.0.1"
|
||||
meow "^3.3.0"
|
||||
|
||||
debug@2, debug@2.6.3, debug@^2.1.1:
|
||||
version "2.6.3"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
|
||||
debug@2, debug@2.6.1, debug@^2.2.0, debug@^2.4.5:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
|
||||
dependencies:
|
||||
ms "0.7.2"
|
||||
|
||||
|
|
@ -1359,9 +1363,9 @@ debug@2.3.3:
|
|||
dependencies:
|
||||
ms "0.7.2"
|
||||
|
||||
debug@2.6.1, debug@^2.2.0, debug@^2.4.5:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
|
||||
debug@2.6.3, debug@^2.1.1:
|
||||
version "2.6.3"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
|
||||
dependencies:
|
||||
ms "0.7.2"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue