Add transaction versioning, tx cancellation (#79)

This commit is contained in:
Josh Harvey 2017-08-29 16:08:06 +03:00 committed by GitHub
parent 4a97535dec
commit 500edcf279
15 changed files with 2223 additions and 1468 deletions

View file

@ -23,9 +23,13 @@ function massage (tx) {
const transformDates = r => mapValuesWithKey(transformDate, r)
const mapBN = r => {
const update = r.direction === 'cashIn'
? {cryptoAtoms: BN(r.cryptoAtoms), fiat: BN(r.fiat), cashInFee: BN(r.cashInFee)}
: {cryptoAtoms: BN(r.cryptoAtoms), fiat: BN(r.fiat)}
const update = {
cryptoAtoms: BN(r.cryptoAtoms),
fiat: BN(r.fiat),
cashInFee: BN(r.cashInFee),
cashInFeeCrypto: BN(r.cashInFeeCrypto),
minimumTx: BN(r.minimumTx)
}
return _.assign(r, update)
}
@ -35,4 +39,17 @@ function massage (tx) {
return mapper(tx)
}
module.exports = {post}
function cancel (txId) {
const promises = [
CashInTx.cancel(txId).then(() => true).catch(() => false),
CashOutTx.cancel(txId).then(() => true).catch(() => false)
]
return Promise.all(promises)
.then(r => {
if (_.some(r)) return
throw new Error('No such transaction')
})
}
module.exports = {post, cancel}