Merge remote-tracking branch 'upstream/defiant-dingirma' into fix/flat-schema
This commit is contained in:
commit
db32ad4f16
29 changed files with 2454 additions and 3157 deletions
|
|
@ -78,7 +78,7 @@ function getFunding (_cryptoCode) {
|
|||
const rate = (rates.ask.add(rates.bid)).div(2)
|
||||
const fundingConfirmedBalance = fundingRec.fundingConfirmedBalance
|
||||
const fiatConfirmedBalance = computeFiat(rate, cryptoCode, fundingConfirmedBalance)
|
||||
const pending = fundingRec.fundingPendingBalance.sub(fundingConfirmedBalance)
|
||||
const pending = fundingRec.fundingPendingBalance
|
||||
const fiatPending = computeFiat(rate, cryptoCode, pending)
|
||||
const fundingAddress = fundingRec.fundingAddress
|
||||
const fundingAddressUrl = coinUtils.buildUrl(cryptoCode, fundingAddress)
|
||||
|
|
|
|||
|
|
@ -21,28 +21,28 @@ module.exports = {
|
|||
|
||||
const BINARIES = {
|
||||
BTC: {
|
||||
url: 'https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-0.18.1/bin'
|
||||
url: 'https://bitcoincore.org/bin/bitcoin-core-0.19.1/bitcoin-0.19.1-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-0.19.1/bin'
|
||||
},
|
||||
ETH: {
|
||||
url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.7-a718daa6.tar.gz',
|
||||
dir: 'geth-linux-amd64-1.9.7-a718daa6'
|
||||
url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.14-6d74d1e5.tar.gz',
|
||||
dir: 'geth-linux-amd64-1.9.14-6d74d1e5'
|
||||
},
|
||||
ZEC: {
|
||||
url: 'https://z.cash/downloads/zcash-2.1.0-1-linux64-debian-jessie.tar.gz',
|
||||
dir: 'zcash-2.1.0-1/bin'
|
||||
url: 'https://z.cash/downloads/zcash-2.1.2-3-linux64-debian-jessie.tar.gz',
|
||||
dir: 'zcash-2.1.2-3/bin'
|
||||
},
|
||||
DASH: {
|
||||
url: 'https://github.com/dashpay/dash/releases/download/v0.14.0.3/dashcore-0.14.0.3-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'dashcore-0.14.0/bin'
|
||||
url: 'https://github.com/dashpay/dash/releases/download/v0.15.0.0/dashcore-0.15.0.0-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'dashcore-0.15.0/bin'
|
||||
},
|
||||
LTC: {
|
||||
url: 'https://download.litecoin.org/litecoin-0.17.1/linux/litecoin-0.17.1-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'litecoin-0.17.1/bin'
|
||||
},
|
||||
BCH: {
|
||||
url: 'https://download.bitcoinabc.org/0.20.5/linux/bitcoin-abc-0.20.5-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-abc-0.20.5/bin',
|
||||
url: 'https://download.bitcoinabc.org/0.21.7/linux/bitcoin-abc-0.21.7-x86_64-linux-gnu.tar.gz',
|
||||
dir: 'bitcoin-abc-0.21.7/bin',
|
||||
files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,5 +23,7 @@ dbcache=500
|
|||
keypool=10000
|
||||
litemode=1
|
||||
prune=4000
|
||||
txindex=0`
|
||||
txindex=0
|
||||
enableprivatesend=1
|
||||
privatesendautostart=1`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,11 +65,7 @@ function preProcess (t, oldTx, newTx, pi) {
|
|||
.then(updatedTx => {
|
||||
if (updatedTx.status !== oldTx.status) {
|
||||
const isZeroConf = pi.isZeroConf(updatedTx)
|
||||
if (wasJustAuthorized(oldTx, updatedTx, isZeroConf)) {
|
||||
pi.sell(updatedTx)
|
||||
pi.notifyOperator(updatedTx, { isRedemption: false })
|
||||
.catch((err) => logger.error('Failure sending transaction notification', err))
|
||||
}
|
||||
updatedTx.justAuthorized = wasJustAuthorized(oldTx, updatedTx, isZeroConf)
|
||||
|
||||
const rec = {
|
||||
to_address: updatedTx.toAddress,
|
||||
|
|
|
|||
|
|
@ -11,14 +11,18 @@ module.exports = { redeemableTxs, toObj, toDb, REDEEMABLE_AGE }
|
|||
const mapValuesWithKey = _.mapValues.convert({cap: false})
|
||||
|
||||
function convertBigNumFields (obj) {
|
||||
const convert = (value, key) => _.includes(key, [
|
||||
'cryptoAtoms',
|
||||
'fiat',
|
||||
'commissionPercentage',
|
||||
'rawTickerPrice'
|
||||
])
|
||||
? value.toString()
|
||||
: value
|
||||
const convert = (value, key) => {
|
||||
if (_.includes(key, [ 'cryptoAtoms', 'receivedCryptoAtoms', 'fiat' ])) {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
// Only test isNil for these fields since the others should not be empty.
|
||||
if (_.includes(key, [ 'commissionPercentage', 'rawTickerPrice' ]) && !_.isNil(value)) {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
const convertKey = key => _.includes(key, ['cryptoAtoms', 'fiat'])
|
||||
? key + '#'
|
||||
|
|
@ -58,6 +62,10 @@ function toObj (row) {
|
|||
|
||||
keys.forEach(key => {
|
||||
const objKey = _.camelCase(key)
|
||||
if (key === 'received_crypto_atoms' && row[key]) {
|
||||
newObj[objKey] = BN(row[key])
|
||||
return
|
||||
}
|
||||
if (_.includes(key, ['crypto_atoms', 'fiat', 'commission_percentage', 'raw_ticker_price'])) {
|
||||
newObj[objKey] = BN(row[key])
|
||||
return
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ const toDb = helper.toDb
|
|||
const toObj = helper.toObj
|
||||
|
||||
const UPDATEABLE_FIELDS = ['txHash', 'txVersion', 'status', 'dispense', 'dispenseConfirmed',
|
||||
'notified', 'redeem', 'phone', 'error', 'swept', 'publishedAt', 'confirmedAt', 'errorCode']
|
||||
'notified', 'redeem', 'phone', 'error', 'swept', 'publishedAt', 'confirmedAt', 'errorCode',
|
||||
'receivedCryptoAtoms' ]
|
||||
|
||||
module.exports = {upsert, update, insert}
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ function upsert (t, oldTx, tx) {
|
|||
}
|
||||
|
||||
return update(t, tx, diff(oldTx, tx))
|
||||
.then(newTx => [oldTx, newTx])
|
||||
.then(newTx => [oldTx, newTx, tx.justAuthorized])
|
||||
}
|
||||
|
||||
function insert (t, tx) {
|
||||
|
|
|
|||
|
|
@ -45,15 +45,21 @@ function selfPost (tx, pi) {
|
|||
function post (tx, pi, fromClient = true) {
|
||||
return db.tx(cashOutAtomic.atomic(tx, pi, fromClient))
|
||||
.then(txVector => {
|
||||
const [, newTx] = txVector
|
||||
return postProcess(txVector, pi)
|
||||
const [, newTx, justAuthorized] = txVector
|
||||
return postProcess(txVector, justAuthorized, pi)
|
||||
.then(changes => cashOutLow.update(db, newTx, changes))
|
||||
})
|
||||
}
|
||||
|
||||
function postProcess (txVector, pi) {
|
||||
function postProcess (txVector, justAuthorized, pi) {
|
||||
const [oldTx, newTx] = txVector
|
||||
|
||||
if (justAuthorized) {
|
||||
pi.sell(newTx)
|
||||
pi.notifyOperator(newTx, { isRedemption: false })
|
||||
.catch((err) => logger.error('Failure sending transaction notification', err))
|
||||
}
|
||||
|
||||
if ((newTx.dispense && !oldTx.dispense) || (newTx.redeem && !oldTx.redeem)) {
|
||||
return pi.buildAvailableCassettes(newTx.id)
|
||||
.then(cassettes => {
|
||||
|
|
@ -106,7 +112,7 @@ function processTxStatus (tx, settings) {
|
|||
const pi = plugins(settings, tx.deviceId)
|
||||
|
||||
return pi.getStatus(tx)
|
||||
.then(res => _.assign(tx, {status: res.status}))
|
||||
.then(res => _.assign(tx, { receivedCryptoAtoms: res.receivedCryptoAtoms, status: res.status }))
|
||||
.then(_tx => selfPost(_tx, pi))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ function mapCoin (rates, deviceId, settings, cryptoCode) {
|
|||
cryptoCode,
|
||||
cashInFee,
|
||||
cashOutFee,
|
||||
cashInFixedFee,
|
||||
cashInRate,
|
||||
cashOutRate
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ function plugins (settings, deviceId) {
|
|||
|
||||
const rate = rawRate.div(cashInCommission)
|
||||
|
||||
const lowBalanceMargin = BN(1)
|
||||
const lowBalanceMargin = BN(1.03)
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
|
||||
const unitScale = cryptoRec.unitScale
|
||||
|
|
|
|||
|
|
@ -25,16 +25,22 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function accountBalance (account, cryptoCode, confirmations) {
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getbalance', ['', confirmations]))
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
// have at least 1 confirmation. getbalance does this for us automatically.
|
||||
function balance (account, cryptoCode) {
|
||||
return accountBalance(account, cryptoCode, 1)
|
||||
return accountBalance(cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -80,13 +86,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress, cryptoCode))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(requested)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress, cryptoCode)
|
||||
.then(pending => {
|
||||
if (pending.gte(requested)) return {status: 'authorized'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -95,9 +101,9 @@ function newFunding (account, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const promises = [
|
||||
accountBalance(account, cryptoCode, 0),
|
||||
accountBalance(account, cryptoCode, 1),
|
||||
newAddress(account, {cryptoCode})
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
|
|||
|
|
@ -25,16 +25,22 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function accountBalance (account, cryptoCode, confirmations) {
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getbalance', ['*', confirmations]))
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
// have at least 1 confirmation. getbalance does this for us automatically.
|
||||
function balance (account, cryptoCode) {
|
||||
return accountBalance(account, cryptoCode, 1)
|
||||
return accountBalance(cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -80,13 +86,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress, cryptoCode))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(requested)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress, cryptoCode)
|
||||
.then(pending => {
|
||||
if (pending.gte(requested)) return {status: 'authorized'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -95,9 +101,9 @@ function newFunding (account, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const promises = [
|
||||
accountBalance(account, cryptoCode, 0),
|
||||
accountBalance(account, cryptoCode, 1),
|
||||
newAddress(account, {cryptoCode})
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
|
|||
|
|
@ -124,10 +124,10 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
const confirmed = _.compose(sum, toBn, filterConfirmed)(transfers)
|
||||
const pending = _.compose(sum, toBn, filterPending)(transfers)
|
||||
|
||||
if (confirmed.gte(requested)) return { status: 'confirmed' }
|
||||
if (pending.gte(requested)) return { status: 'authorized' }
|
||||
if (pending.gt(0)) return { status: 'insufficientFunds' }
|
||||
return { status: 'notSeen' }
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function accountBalance (acount, cryptoCode, confirmations) {
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getbalance', ['', confirmations]))
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
// have at least 1 confirmation. getbalance does this for us automatically.
|
||||
function balance (account, cryptoCode) {
|
||||
return accountBalance(account, cryptoCode, 1)
|
||||
return accountBalance(cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress, cryptoCode))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(requested)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress, cryptoCode)
|
||||
.then(pending => {
|
||||
if (pending.gte(requested)) return {status: 'authorized'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const promises = [
|
||||
accountBalance(account, cryptoCode, 0),
|
||||
accountBalance(account, cryptoCode, 1),
|
||||
newAddress(account, {cryptoCode})
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
|
|||
|
|
@ -158,13 +158,13 @@ function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(cryptoAtoms)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(cryptoAtoms)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress)
|
||||
.then(pending => {
|
||||
if (pending.gte(cryptoAtoms)) return {status: 'published'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(cryptoAtoms)) return { receivedCryptoAtoms: pending, status: 'published' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function accountBalance (acount, cryptoCode, confirmations) {
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getbalance', ['*', confirmations]))
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
// have at least 1 confirmation. getbalance does this for us automatically.
|
||||
function balance (account, cryptoCode) {
|
||||
return accountBalance(account, cryptoCode, 1)
|
||||
return accountBalance(cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress, cryptoCode))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(requested)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress, cryptoCode)
|
||||
.then(pending => {
|
||||
if (pending.gte(requested)) return {status: 'authorized'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const promises = [
|
||||
accountBalance(account, cryptoCode, 0),
|
||||
accountBalance(account, cryptoCode, 1),
|
||||
newAddress(account, {cryptoCode})
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
|
|||
|
|
@ -79,9 +79,9 @@ function newFunding (account, cryptoCode) {
|
|||
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
const elapsed = Date.now() - t0
|
||||
|
||||
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'})
|
||||
if (elapsed < PUBLISH_TIME) return Promise.resolve({ receivedCryptoAtoms: BN(0), status: 'notSeen' })
|
||||
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({ receivedCryptoAtoms: cryptoAtoms, status: 'published' })
|
||||
if (elapsed < CONFIRM_TIME) return Promise.resolve({ receivedCryptoAtoms: cryptoAtoms, status: 'authorized' })
|
||||
|
||||
console.log('[%s] DEBUG: Mock wallet has confirmed transaction [%s]', cryptoCode, toAddress.slice(0, 5))
|
||||
|
||||
|
|
|
|||
|
|
@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function accountBalance (acount, cryptoCode, confirmations) {
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getbalance', ['', confirmations]))
|
||||
.then(r => BN(r).shift(unitScale).round())
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => BN(balance).shift(unitScale).round())
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
// have at least 1 confirmation. getbalance does this for us automatically.
|
||||
function balance (account, cryptoCode) {
|
||||
return accountBalance(account, cryptoCode, 1)
|
||||
return accountBalance(cryptoCode)
|
||||
}
|
||||
|
||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||
|
|
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress, cryptoCode))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(requested)) return {status: 'confirmed'}
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress, cryptoCode)
|
||||
.then(pending => {
|
||||
if (pending.gte(requested)) return {status: 'authorized'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
|
|||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const promises = [
|
||||
accountBalance(account, cryptoCode, 0),
|
||||
accountBalance(account, cryptoCode, 1),
|
||||
newAddress(account, {cryptoCode})
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
|
|
|
|||
|
|
@ -114,10 +114,10 @@ function poll (req, res, next) {
|
|||
operatorInfo
|
||||
}
|
||||
|
||||
// BACKWARDS_COMPATIBILITY 7.5
|
||||
// machines before 7.5 expect t&c on poll
|
||||
if (!machineVersion || semver.lt(machineVersion, '7.5.0-beta')) {
|
||||
response.terms = createTerms(terms)
|
||||
// BACKWARDS_COMPATIBILITY 7.4.9
|
||||
// machines before 7.4.9 expect t&c on poll
|
||||
if (!machineVersion || semver.lt(machineVersion, '7.4.9')) {
|
||||
response.terms = config.termsScreenActive && config.termsScreenText ? createTerms(config) : null
|
||||
}
|
||||
|
||||
return res.json(_.assign(response, results))
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ function massage (tx, pi) {
|
|||
cashInFee: BN(r.cashInFee),
|
||||
cashInFeeCrypto: BN(r.cashInFeeCrypto),
|
||||
commissionPercentage: BN(r.commissionPercentage),
|
||||
rawTickerPrice: BN(r.rawTickerPrice),
|
||||
rawTickerPrice: r.rawTickerPrice ? BN(r.rawTickerPrice) : null,
|
||||
minimumTx: BN(r.minimumTx)
|
||||
}
|
||||
: {
|
||||
cryptoAtoms: BN(r.cryptoAtoms),
|
||||
fiat: BN(r.fiat),
|
||||
rawTickerPrice: BN(r.rawTickerPrice),
|
||||
rawTickerPrice: r.rawTickerPrice ? BN(r.rawTickerPrice) : null,
|
||||
commissionPercentage: BN(r.commissionPercentage)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ function mergeStatus (a, b) {
|
|||
if (!a) return b
|
||||
if (!b) return a
|
||||
|
||||
return { status: mergeStatusMode(a.status, b.status) }
|
||||
return { receivedCryptoAtoms: a.receivedCryptoAtoms, status: mergeStatusMode(a.status, b.status) }
|
||||
}
|
||||
|
||||
function mergeStatusMode (a, b) {
|
||||
|
|
@ -122,8 +122,11 @@ function mergeStatusMode (a, b) {
|
|||
}
|
||||
|
||||
function getWalletStatus (settings, tx) {
|
||||
const fudgeFactorEnabled = configManager.unscoped(settings.config).fudgeFactorActive
|
||||
const fudgeFactor = fudgeFactorEnabled ? 100 : 0
|
||||
|
||||
const walletStatusPromise = fetchWallet(settings, tx.cryptoCode)
|
||||
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode))
|
||||
.then(r => r.wallet.getStatus(r.account, tx.toAddress, tx.cryptoAtoms.minus(fudgeFactor), tx.cryptoCode))
|
||||
|
||||
return Promise.all([
|
||||
walletStatusPromise,
|
||||
|
|
@ -169,7 +172,7 @@ function getStatus (settings, tx, machineId) {
|
|||
|
||||
const status = isAuthorized ? 'authorized' : unauthorizedStatus
|
||||
|
||||
return { status }
|
||||
return { receivedCryptoAtoms: statusRec.receivedCryptoAtoms, status }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue