WIP
This commit is contained in:
parent
dde57dfba1
commit
44b46bd5ee
2 changed files with 13 additions and 10 deletions
|
|
@ -298,14 +298,16 @@ function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeTx (session, tx) {
|
// NOTE: This will fail if we have already sent coins because there will be
|
||||||
return db.addOutgoingTx(session, tx)
|
// a db unique db record in the table already.
|
||||||
|
function executeTx (fingerprint, tx) {
|
||||||
|
return db.addOutgoingTx(fingerprint, tx)
|
||||||
.then(() => _sendCoins(tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
.then(() => _sendCoins(tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||||
.then(txHash => {
|
.then(txHash => {
|
||||||
const fee = null // Need to fill this out in plugins
|
const fee = null // Need to fill this out in plugins
|
||||||
const toSend = {cryptoAtoms: tx.cryptoAtoms, fiat: tx.fiat}
|
const toSend = {cryptoAtoms: tx.cryptoAtoms, fiat: tx.fiat}
|
||||||
|
|
||||||
return db.sentCoins(session, tx, toSend, fee, null, txHash)
|
return db.sentCoins(tx, toSend, fee, null, txHash)
|
||||||
.then(() => pollBalance(tx.cryptoCode))
|
.then(() => pollBalance(tx.cryptoCode))
|
||||||
.then(() => ({
|
.then(() => ({
|
||||||
statusCode: 201, // Created
|
statusCode: 201, // Created
|
||||||
|
|
@ -358,8 +360,7 @@ exports.recordPing = function recordPing (session, rec, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.sendCoins = function sendCoins (session, rawTx) {
|
exports.sendCoins = function sendCoins (session, rawTx) {
|
||||||
const _session = {id: rawTx.sessionId || session.id, fingerprint: session.fingerprint}
|
return executeTx(session.fingerprint, rawTx)
|
||||||
return executeTx(_session, rawTx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.cashOut = function cashOut (session, tx) {
|
exports.cashOut = function cashOut (session, tx) {
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,17 @@ exports.recordDeviceEvent = function recordDeviceEvent (session, event) {
|
||||||
return db.none(sql, values)
|
return db.none(sql, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.addOutgoingTx = function addOutgoingTx (session, tx) {
|
// NOTE: This will fail if we have already sent coins because there will be
|
||||||
|
// a unique cash_in_txs record in the table already keyed by sessionId.
|
||||||
|
exports.addOutgoingTx = function addOutgoingTx (fingerprint, tx) {
|
||||||
const fields = ['session_id', 'device_fingerprint', 'to_address',
|
const fields = ['session_id', 'device_fingerprint', 'to_address',
|
||||||
'crypto_atoms', 'crypto_code', 'currency_code', 'fiat', 'tx_hash',
|
'crypto_atoms', 'crypto_code', 'currency_code', 'fiat', 'tx_hash',
|
||||||
'fee', 'phone', 'error'
|
'fee', 'phone', 'error'
|
||||||
]
|
]
|
||||||
|
|
||||||
const values = [
|
const values = [
|
||||||
session.id,
|
tx.sessionId,
|
||||||
session.fingerprint,
|
fingerprint,
|
||||||
tx.toAddress,
|
tx.toAddress,
|
||||||
tx.cryptoAtoms.toString(),
|
tx.cryptoAtoms.toString(),
|
||||||
tx.cryptoCode,
|
tx.cryptoCode,
|
||||||
|
|
@ -104,9 +106,9 @@ exports.addOutgoingTx = function addOutgoingTx (session, tx) {
|
||||||
return db.none(getInsertQuery('cash_in_txs', fields), values)
|
return db.none(getInsertQuery('cash_in_txs', fields), values)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.sentCoins = function sentCoins (session, tx, toSend, fee, error, txHash) {
|
exports.sentCoins = function sentCoins (tx, toSend, fee, error, txHash) {
|
||||||
const sql = `update cash_in_txs set tx_hash=$1, error=$2 where session_id=$3`
|
const sql = `update cash_in_txs set tx_hash=$1, error=$2 where session_id=$3`
|
||||||
return db.none(sql, [txHash, error, session.id])
|
return db.none(sql, [txHash, error, tx.sessionId])
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.addInitialIncoming = function addInitialIncoming (session, tx) {
|
exports.addInitialIncoming = function addInitialIncoming (session, tx) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue