This commit is contained in:
Josh Harvey 2016-06-01 00:49:51 +03:00
parent 896bec93cb
commit 35cbb46688
6 changed files with 62 additions and 23 deletions

View file

@ -113,7 +113,7 @@ exports.sentCoins = function sentCoins (session, tx, toSend, fee, error, txHash)
return db.none(sql, [txHash, error, session.id])
}
exports.addInitialIncoming = function addInitialIncoming (session, tx) {
exports.addInitialIncoming = function addInitialIncoming (session, tx, addressRec) {
const fields = ['session_id', 'device_fingerprint', 'to_address',
'crypto_atoms', 'crypto_code', 'currency_code', 'fiat', 'tx_hash',
'phone', 'error'
@ -133,6 +133,15 @@ exports.addInitialIncoming = function addInitialIncoming (session, tx) {
]
return db.none(getInsertQuery('cash_out_txs', fields), values)
.then(() => {
const hd = addressRec.hd
if (hd) {
const fields2 = ['session_id', 'to_address', 'crypto_code',
'hd_path_prefix', 'hd_serial']
const values2 = [tx.sessionId, tx.toAddress, tx.cryptoCode, hd.pathPrefix, hd.serial]
return db.none(getInsertQuery('cash_out_hds', fields2), values2)
}
})
}
function insertDispense (session, tx, cartridges) {
@ -424,3 +433,10 @@ exports.cacheResponse = function (session, path, method, body) {
return db.none(sql, values)
}
exports.nextCashOutSerialHD = function nextCashOutSerialHD (cryptoCode) {
const sql = `select hd_serial from cash_out_hds
where crypto_code=$1 order by hd_serial desc limit 1`
return db.oneOrNone(sql, [cryptoCode])
.then(row => row ? row.hd_serial + 1 : 0)
}