add sendConfirmed

This commit is contained in:
Josh Harvey 2017-04-19 02:25:08 +03:00
parent 9495aa8424
commit d5aab9dfd0
5 changed files with 39 additions and 14 deletions

View file

@ -2,9 +2,9 @@ const _ = require('lodash/fp')
const db = require('../db')
const config = require('./config')
const pu = require('../plugin-helper')
const ph = require('../plugin-helper')
const schemas = pu.loadSchemas()
const schemas = ph.loadSchemas()
function fetchAccounts () {
return db.oneOrNone('select data from user_config where type=$1', ['accounts'])

View file

@ -2,19 +2,20 @@ const _ = require('lodash/fp')
const pgp = require('pg-promise')()
const db = require('./db')
const BN = require('./bn')
const logger = require('./logger')
const mapValuesWithKey = _.mapValues.convert({cap: false})
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) {
const TransactionMode = pgp.txMode.TransactionMode
const isolationLevel = pgp.txMode.isolationLevel
const tmSRD = new TransactionMode({tiLevel: isolationLevel.serializable})
console.log('DEBUG502: %j', tx)
function transaction (t) {
const sql = 'select * from cash_in_txs where 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)
.then(txVector => {
const [, newTx] = txVector
const [oldTx, newTx, newBills] = txVector
const oldBills = oldTx ? oldTx.bills : []
return postProcess(txVector, pi)
.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) {
const bills = pullNewBills(billRows, tx)
if (_.isEmpty(bills)) return Promise.resolve()
if (_.isEmpty(bills)) return Promise.resolve([])
const dbBills = _.map(massage, bills)
const columns = _.keys(dbBills[0])
@ -120,9 +123,11 @@ function insertNewBills (billRows, tx) {
}
function upsert (row, tx) {
console.log('DEBUG501: %j', row)
const oldTx = toObj(row)
if (!oldTx) {
console.log('DEBUG500: %j', tx)
return insert(tx)
.then(newTx => [oldTx, newTx])
}
@ -164,7 +169,11 @@ function postProcess (txVector, pi) {
if (newTx.send && !oldTx.send) {
return pi.sendCoins(newTx)
.then(txHash => ({txHash}))
.then(txHash => ({
txHash,
sendConfirmed: true,
sendTime: 'now()^'
}))
}
return Promise.resolve({})

View file

@ -40,7 +40,6 @@ function sendNoAlerts (plugins) {
}
function checkNotification (plugins) {
console.log('DEBUG444')
return checkStatus(plugins)
.then(alertRec => {
console.log('DEBUG445: %j', alertRec)

View file

@ -3,9 +3,9 @@ const BN = require('../../../bn')
const NAME = 'FakeWallet'
const SECONDS = 1000
const UNSEEN_TIME = 6 * SECONDS
const PUBLISH_TIME = 12 * SECONDS
const AUTHORIZE_TIME = 60 * SECONDS
const PUBLISH_TIME = 3 * SECONDS
const AUTHORIZE_TIME = 8 * SECONDS
const CONFIRM_TIME = 60 * SECONDS
let t0
@ -36,9 +36,9 @@ function newAddress () {
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
const elapsed = Date.now() - t0
if (elapsed < UNSEEN_TIME) return Promise.resolve({status: 'notSeen'})
if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'published'})
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'authorized'})
if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'notSeen'})
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'published'})
if (elapsed < CONFIRM_TIME) return Promise.resolve({status: 'authorized'})
console.log('[%s] DEBUG: Mock wallet has confirmed transaction', cryptoCode)
return Promise.resolve({status: 'confirmed'})

View 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()
}