add cancel script

This commit is contained in:
Josh Harvey 2017-04-17 19:04:10 +03:00
parent 985e3811e3
commit d2700b4eb3
4 changed files with 58 additions and 8 deletions

25
bin/lamassu-cancel Executable file
View 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))

View file

@ -12,7 +12,8 @@ module.exports = {
post, post,
monitorLiveIncoming, monitorLiveIncoming,
monitorStaleIncoming, monitorStaleIncoming,
monitorUnnotified monitorUnnotified,
cancel
} }
const mapValuesWithKey = _.mapValues.convert({cap: false}) const mapValuesWithKey = _.mapValues.convert({cap: false})
@ -273,3 +274,21 @@ function monitorUnnotified (settings) {
.then(txs => Promise.all(txs.map(notify))) .then(txs => Promise.all(txs.map(notify)))
.catch(logger.error) .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')
})
}

View file

@ -6,6 +6,7 @@
"license": "Unlicense", "license": "Unlicense",
"author": "Lamassu (https://lamassu.is)", "author": "Lamassu (https://lamassu.is)",
"dependencies": { "dependencies": {
"@fczbkk/uuid4": "^3.0.0",
"axios": "^0.16.1", "axios": "^0.16.1",
"base-x": "^3.0.0", "base-x": "^3.0.0",
"bignumber.js": "^4.0.1", "bignumber.js": "^4.0.1",
@ -56,7 +57,8 @@
"lamassu-backup-pg": "./bin/lamassu-backup-pg", "lamassu-backup-pg": "./bin/lamassu-backup-pg",
"lamassu-install-bitcoind": "./bin/lamassu-install-bitcoind", "lamassu-install-bitcoind": "./bin/lamassu-install-bitcoind",
"lamassu-install-geth": "./bin/lamassu-install-geth", "lamassu-install-geth": "./bin/lamassu-install-geth",
"lamassu-mnemonic": "./bin/lamassu-mnemonic" "lamassu-mnemonic": "./bin/lamassu-mnemonic",
"lamassu-cancel": "./bin/lamassu-cancel"
}, },
"scripts": { "scripts": {
"test": "ava" "test": "ava"

View file

@ -37,6 +37,10 @@
ansi-styles "^2.2.1" ansi-styles "^2.2.1"
esutils "^2.0.2" 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: abbrev@1:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f" 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" get-stdin "^4.0.1"
meow "^3.3.0" meow "^3.3.0"
debug@2, debug@2.6.3, debug@^2.1.1: debug@2, debug@2.6.1, debug@^2.2.0, debug@^2.4.5:
version "2.6.3" version "2.6.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
dependencies: dependencies:
ms "0.7.2" ms "0.7.2"
@ -1359,9 +1363,9 @@ debug@2.3.3:
dependencies: dependencies:
ms "0.7.2" ms "0.7.2"
debug@2.6.1, debug@^2.2.0, debug@^2.4.5: debug@2.6.3, debug@^2.1.1:
version "2.6.1" version "2.6.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
dependencies: dependencies:
ms "0.7.2" ms "0.7.2"