add sendConfirmed
This commit is contained in:
parent
9495aa8424
commit
d5aab9dfd0
5 changed files with 39 additions and 14 deletions
|
|
@ -2,9 +2,9 @@ const _ = require('lodash/fp')
|
||||||
|
|
||||||
const db = require('../db')
|
const db = require('../db')
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const pu = require('../plugin-helper')
|
const ph = require('../plugin-helper')
|
||||||
|
|
||||||
const schemas = pu.loadSchemas()
|
const schemas = ph.loadSchemas()
|
||||||
|
|
||||||
function fetchAccounts () {
|
function fetchAccounts () {
|
||||||
return db.oneOrNone('select data from user_config where type=$1', ['accounts'])
|
return db.oneOrNone('select data from user_config where type=$1', ['accounts'])
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,20 @@ const _ = require('lodash/fp')
|
||||||
const pgp = require('pg-promise')()
|
const pgp = require('pg-promise')()
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const BN = require('./bn')
|
const BN = require('./bn')
|
||||||
const logger = require('./logger')
|
|
||||||
|
|
||||||
const mapValuesWithKey = _.mapValues.convert({cap: false})
|
const mapValuesWithKey = _.mapValues.convert({cap: false})
|
||||||
|
|
||||||
module.exports = {post}
|
module.exports = {post}
|
||||||
|
|
||||||
const UPDATEABLE_FIELDS = ['fee', 'txHash', 'phone', 'error', 'send', 'cryptoAtoms', 'fiat']
|
const UPDATEABLE_FIELDS = ['fee', 'txHash', 'phone', 'error', 'send',
|
||||||
|
'cryptoAtoms', 'fiat', 'timedout']
|
||||||
|
|
||||||
function post (tx, pi) {
|
function post (tx, pi) {
|
||||||
const TransactionMode = pgp.txMode.TransactionMode
|
const TransactionMode = pgp.txMode.TransactionMode
|
||||||
const isolationLevel = pgp.txMode.isolationLevel
|
const isolationLevel = pgp.txMode.isolationLevel
|
||||||
const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable})
|
const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable})
|
||||||
|
|
||||||
|
console.log('DEBUG502: %j', tx)
|
||||||
function transaction (t) {
|
function transaction (t) {
|
||||||
const sql = 'select * from cash_in_txs where id=$1'
|
const sql = 'select * from cash_in_txs where id=$1'
|
||||||
const sql2 = 'select * from bills where cash_in_txs_id=$1'
|
const sql2 = 'select * from bills where cash_in_txs_id=$1'
|
||||||
|
|
@ -36,9 +37,11 @@ function post (tx, pi) {
|
||||||
|
|
||||||
return db.tx(transaction)
|
return db.tx(transaction)
|
||||||
.then(txVector => {
|
.then(txVector => {
|
||||||
const [, newTx] = txVector
|
const [oldTx, newTx, newBills] = txVector
|
||||||
|
const oldBills = oldTx ? oldTx.bills : []
|
||||||
return postProcess(txVector, pi)
|
return postProcess(txVector, pi)
|
||||||
.then(changes => update(newTx, changes))
|
.then(changes => update(newTx, changes))
|
||||||
|
.then(tx => _.merge({bills: _.concat(oldBills, newBills)}, tx))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,7 +112,7 @@ const massage = _.flow(_.omit(['direction', 'bills']), convertBigNumFields, _.ma
|
||||||
|
|
||||||
function insertNewBills (billRows, tx) {
|
function insertNewBills (billRows, tx) {
|
||||||
const bills = pullNewBills(billRows, tx)
|
const bills = pullNewBills(billRows, tx)
|
||||||
if (_.isEmpty(bills)) return Promise.resolve()
|
if (_.isEmpty(bills)) return Promise.resolve([])
|
||||||
|
|
||||||
const dbBills = _.map(massage, bills)
|
const dbBills = _.map(massage, bills)
|
||||||
const columns = _.keys(dbBills[0])
|
const columns = _.keys(dbBills[0])
|
||||||
|
|
@ -120,9 +123,11 @@ function insertNewBills (billRows, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function upsert (row, tx) {
|
function upsert (row, tx) {
|
||||||
|
console.log('DEBUG501: %j', row)
|
||||||
const oldTx = toObj(row)
|
const oldTx = toObj(row)
|
||||||
|
|
||||||
if (!oldTx) {
|
if (!oldTx) {
|
||||||
|
console.log('DEBUG500: %j', tx)
|
||||||
return insert(tx)
|
return insert(tx)
|
||||||
.then(newTx => [oldTx, newTx])
|
.then(newTx => [oldTx, newTx])
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +169,11 @@ function postProcess (txVector, pi) {
|
||||||
|
|
||||||
if (newTx.send && !oldTx.send) {
|
if (newTx.send && !oldTx.send) {
|
||||||
return pi.sendCoins(newTx)
|
return pi.sendCoins(newTx)
|
||||||
.then(txHash => ({txHash}))
|
.then(txHash => ({
|
||||||
|
txHash,
|
||||||
|
sendConfirmed: true,
|
||||||
|
sendTime: 'now()^'
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({})
|
return Promise.resolve({})
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ function sendNoAlerts (plugins) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkNotification (plugins) {
|
function checkNotification (plugins) {
|
||||||
console.log('DEBUG444')
|
|
||||||
return checkStatus(plugins)
|
return checkStatus(plugins)
|
||||||
.then(alertRec => {
|
.then(alertRec => {
|
||||||
console.log('DEBUG445: %j', alertRec)
|
console.log('DEBUG445: %j', alertRec)
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ const BN = require('../../../bn')
|
||||||
const NAME = 'FakeWallet'
|
const NAME = 'FakeWallet'
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const UNSEEN_TIME = 6 * SECONDS
|
const PUBLISH_TIME = 3 * SECONDS
|
||||||
const PUBLISH_TIME = 12 * SECONDS
|
const AUTHORIZE_TIME = 8 * SECONDS
|
||||||
const AUTHORIZE_TIME = 60 * SECONDS
|
const CONFIRM_TIME = 60 * SECONDS
|
||||||
|
|
||||||
let t0
|
let t0
|
||||||
|
|
||||||
|
|
@ -36,9 +36,9 @@ function newAddress () {
|
||||||
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
const elapsed = Date.now() - t0
|
const elapsed = Date.now() - t0
|
||||||
|
|
||||||
if (elapsed < UNSEEN_TIME) return Promise.resolve({status: 'notSeen'})
|
if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'notSeen'})
|
||||||
if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'published'})
|
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'published'})
|
||||||
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'authorized'})
|
if (elapsed < CONFIRM_TIME) return Promise.resolve({status: 'authorized'})
|
||||||
|
|
||||||
console.log('[%s] DEBUG: Mock wallet has confirmed transaction', cryptoCode)
|
console.log('[%s] DEBUG: Mock wallet has confirmed transaction', cryptoCode)
|
||||||
return Promise.resolve({status: 'confirmed'})
|
return Promise.resolve({status: 'confirmed'})
|
||||||
|
|
|
||||||
17
migrations/026-add_send_confirmed.js
Normal file
17
migrations/026-add_send_confirmed.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
var db = require('./db')
|
||||||
|
|
||||||
|
exports.up = function (next) {
|
||||||
|
var sql = [
|
||||||
|
'alter table cash_in_txs add column send_confirmed boolean not null default false',
|
||||||
|
'alter table cash_in_txs add column device_time bigint not null',
|
||||||
|
'alter table cash_in_txs add column timedout boolean not null default false',
|
||||||
|
'alter table cash_in_txs add column send_time timestamptz',
|
||||||
|
'alter table cash_out_txs add column device_time bigint not null',
|
||||||
|
'alter table cash_out_txs add column timedout boolean not null default false'
|
||||||
|
]
|
||||||
|
db.multi(sql, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (next) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue