fix up zero-conf
This commit is contained in:
parent
23458b6b56
commit
c78519072b
6 changed files with 4205 additions and 180 deletions
|
|
@ -231,7 +231,7 @@ function plugins (settings, deviceId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatus (tx) {
|
function getStatus (tx) {
|
||||||
return wallet.getStatus(settings, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode, tx.fiat, deviceId)
|
return wallet.getStatus(settings, tx, deviceId)
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (tx) {
|
function newAddress (tx) {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ const E = require('../../../error')
|
||||||
const NAME = 'FakeWallet'
|
const NAME = 'FakeWallet'
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const PUBLISH_TIME = 3 * SECONDS
|
const PUBLISH_TIME = 2 * SECONDS
|
||||||
const AUTHORIZE_TIME = 8 * SECONDS
|
const AUTHORIZE_TIME = 8 * SECONDS
|
||||||
const CONFIRM_TIME = 60 * SECONDS
|
const CONFIRM_TIME = 180 * SECONDS
|
||||||
|
|
||||||
let t0
|
let t0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode)
|
||||||
|
|
||||||
const authorizedValue = 1e5 * 10
|
const authorizedValue = 1e5 * 2
|
||||||
|
console.log('DEBUG300: %j', cryptoAtoms.lte(authorizedValue))
|
||||||
return cryptoAtoms.lte(authorizedValue)
|
return cryptoAtoms.lte(authorizedValue)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ const pify = require('pify')
|
||||||
const fs = pify(require('fs'))
|
const fs = pify(require('fs'))
|
||||||
const options = require('./options')
|
const options = require('./options')
|
||||||
const ph = require('./plugin-helper')
|
const ph = require('./plugin-helper')
|
||||||
|
const db = require('./db')
|
||||||
|
|
||||||
const FETCH_INTERVAL = 5000
|
const FETCH_INTERVAL = 5000
|
||||||
const INSUFFICIENT_FUNDS_CODE = 570
|
const INSUFFICIENT_FUNDS_CODE = 570
|
||||||
const INSUFFICIENT_FUNDS_NAME = 'InsufficientFunds'
|
const INSUFFICIENT_FUNDS_NAME = 'InsufficientFunds'
|
||||||
|
const ZERO_CONF_EXPIRATION = 60000
|
||||||
|
|
||||||
function httpError (msg, code) {
|
function httpError (msg, code) {
|
||||||
const err = new Error(msg)
|
const err = new Error(msg)
|
||||||
|
|
@ -67,36 +69,56 @@ function newAddress (settings, info) {
|
||||||
.then(r => r.wallet.newAddress(r.account, info))
|
.then(r => r.wallet.newAddress(r.account, info))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWalletStatus (settings, toAddress, cryptoAtoms, cryptoCode) {
|
function getWalletStatus (settings, tx) {
|
||||||
return fetchWallet(settings, cryptoCode)
|
return fetchWallet(settings, tx.cryptoCode)
|
||||||
.then(r => r.wallet.getStatus(r.account, toAddress, cryptoAtoms, cryptoCode))
|
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
function authorizeZeroConf (settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId) {
|
function authorizeZeroConf (settings, tx, machineId) {
|
||||||
const cryptoConfig = configManager.cryptoScoped(cryptoCode, settings.config)
|
console.log('DEBUG330: %j', machineId)
|
||||||
|
const cryptoConfig = configManager.cryptoScoped(tx.cryptoCode, settings.config)
|
||||||
const machineConfig = configManager.machineScoped(machineId, settings.config)
|
const machineConfig = configManager.machineScoped(machineId, settings.config)
|
||||||
const plugin = cryptoConfig.zeroConf
|
const plugin = cryptoConfig.zeroConf
|
||||||
const zeroConfLimit = machineConfig.zeroConfLimit
|
const zeroConfLimit = machineConfig.zeroConfLimit
|
||||||
|
|
||||||
if (fiat.gt(zeroConfLimit)) return Promise.resolve(false)
|
if (tx.fiat.gt(zeroConfLimit)) return Promise.resolve(false)
|
||||||
if (cryptoCode !== 'BTC' || plugin === 'all-zero-conf') return Promise.resolve(true)
|
if (tx.cryptoCode !== 'BTC' || plugin === 'all-zero-conf') return Promise.resolve(true)
|
||||||
|
|
||||||
const zeroConf = ph.load(ph.ZERO_CONF, plugin)
|
const zeroConf = ph.load(ph.ZERO_CONF, plugin)
|
||||||
const account = settings.accounts[plugin]
|
const account = settings.accounts[plugin]
|
||||||
|
|
||||||
return zeroConf.authorize(account, toAddress, cryptoAtoms, cryptoCode)
|
return zeroConf.authorize(account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getStatus (settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId) {
|
function getPublishAge (txId) {
|
||||||
|
const sql = `select extract(epoch from (now() - created)) * 1000 as age
|
||||||
|
from cash_out_actions
|
||||||
|
where tx_id=$1
|
||||||
|
and action=$2`
|
||||||
|
|
||||||
|
return db.oneOrNone(sql, [txId, 'published'])
|
||||||
|
.then(row => row && row.age)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatus (settings, tx, machineId) {
|
||||||
const promises = [
|
const promises = [
|
||||||
getWalletStatus(settings, toAddress, cryptoAtoms, cryptoCode),
|
getWalletStatus(settings, tx),
|
||||||
authorizeZeroConf(settings, toAddress, cryptoAtoms, cryptoCode, fiat, machineId)
|
authorizeZeroConf(settings, tx, machineId),
|
||||||
|
getPublishAge(tx.id)
|
||||||
]
|
]
|
||||||
|
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
.then(([status, isAuthorized]) => {
|
.then(([statusRec, isAuthorized, publishAge]) => {
|
||||||
if (status === 'authorized') return isAuthorized ? 'authorized' : 'published'
|
console.log('DEBUG301: %j', [statusRec, isAuthorized])
|
||||||
return status
|
if (statusRec.status === 'authorized') {
|
||||||
|
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||||
|
? 'published'
|
||||||
|
: 'rejected'
|
||||||
|
|
||||||
|
return {status: (isAuthorized ? 'authorized' : unauthorizedStatus)}
|
||||||
|
}
|
||||||
|
|
||||||
|
return statusRec
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
4246
public/elm.js
4246
public/elm.js
File diff suppressed because one or more lines are too long
|
|
@ -12,7 +12,7 @@
|
||||||
{
|
{
|
||||||
"code": "confidenceFactor",
|
"code": "confidenceFactor",
|
||||||
"display": "Confidence Factor",
|
"display": "Confidence Factor",
|
||||||
"fieldType": "string",
|
"fieldType": "integer",
|
||||||
"required": true,
|
"required": true,
|
||||||
"value": ""
|
"value": ""
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue