Merge remote-tracking branch 'upstream/defiant-dingirma' into fix/flat-schema

This commit is contained in:
Taranto 2020-06-01 21:02:44 +01:00
commit db32ad4f16
29 changed files with 2454 additions and 3157 deletions

View file

@ -156,7 +156,7 @@ determineConfigCategory : String -> Maybe Category
determineConfigCategory configCode = determineConfigCategory configCode =
if List.member configCode [ "definition", "setup", "cashOut", "commissions", "balanceAlerts" ] then if List.member configCode [ "definition", "setup", "cashOut", "commissions", "balanceAlerts" ] then
Just MachineSettingsCat Just MachineSettingsCat
else if List.member configCode [ "walletSettings", "notifications", "compliance", "coinAtmRadar", "terms", "operatorInfo" ] then else if List.member configCode [ "walletSettings", "notifications", "compliance", "coinAtmRadar", "terms", "operatorInfo", "fudgeFactor" ] then
Just GlobalSettingsCat Just GlobalSettingsCat
else else
Nothing Nothing
@ -253,6 +253,7 @@ view route invalidGroups =
, configLink "coinAtmRadar" "Coin ATM Radar" , configLink "coinAtmRadar" "Coin ATM Radar"
, configLink "terms" "Terms and Conditions" , configLink "terms" "Terms and Conditions"
, configLink "operatorInfo" "Operator Info" , configLink "operatorInfo" "Operator Info"
, configLink "fudgeFactor" "Fudge Factor"
] ]
, ll ( "Third Party Services", AccountCat, AccountRoute "bitgo", True ) , ll ( "Third Party Services", AccountCat, AccountRoute "bitgo", True )
[ ( "BitGo", AccountRoute "bitgo", True ) [ ( "BitGo", AccountRoute "bitgo", True )

View file

@ -147,6 +147,15 @@
"operatorInfoWebsite", "operatorInfoWebsite",
"operatorInfoCompanyNumber" "operatorInfoCompanyNumber"
] ]
},
{
"code": "fudgeFactor",
"display": "Fudge Factor",
"cryptoScope": "global",
"machineScope": "global",
"fields": [
"fudgeFactorActive"
]
} }
], ],
"fields": [ "fields": [
@ -846,7 +855,8 @@
"notificationsSMSEnabled", "notificationsSMSEnabled",
"cashOutEnabled" "cashOutEnabled"
], ],
"fieldValidation": [{"code": "required"}] "fieldValidation": [{"code": "required"}],
"default": "twilio"
}, },
{ {
"code": "email", "code": "email",
@ -857,7 +867,8 @@
"enabledIfAny": [ "enabledIfAny": [
"notificationsEmailEnabled" "notificationsEmailEnabled"
], ],
"fieldValidation": [{"code": "required"}] "fieldValidation": [{"code": "required"}],
"default": "mailgun"
}, },
{ {
"code": "coinAtmRadarActive", "code": "coinAtmRadarActive",
@ -939,6 +950,14 @@
], ],
"fieldValidation": [] "fieldValidation": []
}, },
{
"code": "fudgeFactorActive",
"displayBottom": "Enabled",
"fieldType": "onOff",
"fieldClass": null,
"fieldValidation": [],
"default": false
},
{ {
"code": "operatorInfoActive", "code": "operatorInfoActive",
"displayBottom": "Info card enabled", "displayBottom": "Info card enabled",

View file

@ -78,7 +78,7 @@ function getFunding (_cryptoCode) {
const rate = (rates.ask.add(rates.bid)).div(2) const rate = (rates.ask.add(rates.bid)).div(2)
const fundingConfirmedBalance = fundingRec.fundingConfirmedBalance const fundingConfirmedBalance = fundingRec.fundingConfirmedBalance
const fiatConfirmedBalance = computeFiat(rate, cryptoCode, fundingConfirmedBalance) const fiatConfirmedBalance = computeFiat(rate, cryptoCode, fundingConfirmedBalance)
const pending = fundingRec.fundingPendingBalance.sub(fundingConfirmedBalance) const pending = fundingRec.fundingPendingBalance
const fiatPending = computeFiat(rate, cryptoCode, pending) const fiatPending = computeFiat(rate, cryptoCode, pending)
const fundingAddress = fundingRec.fundingAddress const fundingAddress = fundingRec.fundingAddress
const fundingAddressUrl = coinUtils.buildUrl(cryptoCode, fundingAddress) const fundingAddressUrl = coinUtils.buildUrl(cryptoCode, fundingAddress)

View file

@ -21,28 +21,28 @@ module.exports = {
const BINARIES = { const BINARIES = {
BTC: { BTC: {
url: 'https://bitcoin.org/bin/bitcoin-core-0.18.1/bitcoin-0.18.1-x86_64-linux-gnu.tar.gz', url: 'https://bitcoincore.org/bin/bitcoin-core-0.19.1/bitcoin-0.19.1-x86_64-linux-gnu.tar.gz',
dir: 'bitcoin-0.18.1/bin' dir: 'bitcoin-0.19.1/bin'
}, },
ETH: { ETH: {
url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.7-a718daa6.tar.gz', url: 'https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.14-6d74d1e5.tar.gz',
dir: 'geth-linux-amd64-1.9.7-a718daa6' dir: 'geth-linux-amd64-1.9.14-6d74d1e5'
}, },
ZEC: { ZEC: {
url: 'https://z.cash/downloads/zcash-2.1.0-1-linux64-debian-jessie.tar.gz', url: 'https://z.cash/downloads/zcash-2.1.2-3-linux64-debian-jessie.tar.gz',
dir: 'zcash-2.1.0-1/bin' dir: 'zcash-2.1.2-3/bin'
}, },
DASH: { DASH: {
url: 'https://github.com/dashpay/dash/releases/download/v0.14.0.3/dashcore-0.14.0.3-x86_64-linux-gnu.tar.gz', 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.14.0/bin' dir: 'dashcore-0.15.0/bin'
}, },
LTC: { LTC: {
url: 'https://download.litecoin.org/litecoin-0.17.1/linux/litecoin-0.17.1-x86_64-linux-gnu.tar.gz', 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' dir: 'litecoin-0.17.1/bin'
}, },
BCH: { BCH: {
url: 'https://download.bitcoinabc.org/0.20.5/linux/bitcoin-abc-0.20.5-x86_64-linux-gnu.tar.gz', url: 'https://download.bitcoinabc.org/0.21.7/linux/bitcoin-abc-0.21.7-x86_64-linux-gnu.tar.gz',
dir: 'bitcoin-abc-0.20.5/bin', dir: 'bitcoin-abc-0.21.7/bin',
files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']] files: [['bitcoind', 'bitcoincashd'], ['bitcoin-cli', 'bitcoincash-cli']]
} }
} }

View file

@ -23,5 +23,7 @@ dbcache=500
keypool=10000 keypool=10000
litemode=1 litemode=1
prune=4000 prune=4000
txindex=0` txindex=0
enableprivatesend=1
privatesendautostart=1`
} }

View file

@ -65,11 +65,7 @@ function preProcess (t, oldTx, newTx, pi) {
.then(updatedTx => { .then(updatedTx => {
if (updatedTx.status !== oldTx.status) { if (updatedTx.status !== oldTx.status) {
const isZeroConf = pi.isZeroConf(updatedTx) const isZeroConf = pi.isZeroConf(updatedTx)
if (wasJustAuthorized(oldTx, updatedTx, isZeroConf)) { updatedTx.justAuthorized = wasJustAuthorized(oldTx, updatedTx, isZeroConf)
pi.sell(updatedTx)
pi.notifyOperator(updatedTx, { isRedemption: false })
.catch((err) => logger.error('Failure sending transaction notification', err))
}
const rec = { const rec = {
to_address: updatedTx.toAddress, to_address: updatedTx.toAddress,

View file

@ -11,14 +11,18 @@ module.exports = { redeemableTxs, toObj, toDb, REDEEMABLE_AGE }
const mapValuesWithKey = _.mapValues.convert({cap: false}) const mapValuesWithKey = _.mapValues.convert({cap: false})
function convertBigNumFields (obj) { function convertBigNumFields (obj) {
const convert = (value, key) => _.includes(key, [ const convert = (value, key) => {
'cryptoAtoms', if (_.includes(key, [ 'cryptoAtoms', 'receivedCryptoAtoms', 'fiat' ])) {
'fiat', return value.toString()
'commissionPercentage', }
'rawTickerPrice'
]) // Only test isNil for these fields since the others should not be empty.
? value.toString() if (_.includes(key, [ 'commissionPercentage', 'rawTickerPrice' ]) && !_.isNil(value)) {
: value return value.toString()
}
return value
}
const convertKey = key => _.includes(key, ['cryptoAtoms', 'fiat']) const convertKey = key => _.includes(key, ['cryptoAtoms', 'fiat'])
? key + '#' ? key + '#'
@ -58,6 +62,10 @@ function toObj (row) {
keys.forEach(key => { keys.forEach(key => {
const objKey = _.camelCase(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'])) { if (_.includes(key, ['crypto_atoms', 'fiat', 'commission_percentage', 'raw_ticker_price'])) {
newObj[objKey] = BN(row[key]) newObj[objKey] = BN(row[key])
return return

View file

@ -7,7 +7,8 @@ const toDb = helper.toDb
const toObj = helper.toObj const toObj = helper.toObj
const UPDATEABLE_FIELDS = ['txHash', 'txVersion', 'status', 'dispense', 'dispenseConfirmed', 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} module.exports = {upsert, update, insert}
@ -18,7 +19,7 @@ function upsert (t, oldTx, tx) {
} }
return update(t, tx, diff(oldTx, tx)) return update(t, tx, diff(oldTx, tx))
.then(newTx => [oldTx, newTx]) .then(newTx => [oldTx, newTx, tx.justAuthorized])
} }
function insert (t, tx) { function insert (t, tx) {

View file

@ -45,15 +45,21 @@ function selfPost (tx, pi) {
function post (tx, pi, fromClient = true) { function post (tx, pi, fromClient = true) {
return db.tx(cashOutAtomic.atomic(tx, pi, fromClient)) return db.tx(cashOutAtomic.atomic(tx, pi, fromClient))
.then(txVector => { .then(txVector => {
const [, newTx] = txVector const [, newTx, justAuthorized] = txVector
return postProcess(txVector, pi) return postProcess(txVector, justAuthorized, pi)
.then(changes => cashOutLow.update(db, newTx, changes)) .then(changes => cashOutLow.update(db, newTx, changes))
}) })
} }
function postProcess (txVector, pi) { function postProcess (txVector, justAuthorized, pi) {
const [oldTx, newTx] = txVector 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)) { if ((newTx.dispense && !oldTx.dispense) || (newTx.redeem && !oldTx.redeem)) {
return pi.buildAvailableCassettes(newTx.id) return pi.buildAvailableCassettes(newTx.id)
.then(cassettes => { .then(cassettes => {
@ -106,7 +112,7 @@ function processTxStatus (tx, settings) {
const pi = plugins(settings, tx.deviceId) const pi = plugins(settings, tx.deviceId)
return pi.getStatus(tx) 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)) .then(_tx => selfPost(_tx, pi))
} }

View file

@ -39,6 +39,7 @@ function mapCoin (rates, deviceId, settings, cryptoCode) {
cryptoCode, cryptoCode,
cashInFee, cashInFee,
cashOutFee, cashOutFee,
cashInFixedFee,
cashInRate, cashInRate,
cashOutRate cashOutRate
} }

View file

@ -302,7 +302,7 @@ function plugins (settings, deviceId) {
const rate = rawRate.div(cashInCommission) const rate = rawRate.div(cashInCommission)
const lowBalanceMargin = BN(1) const lowBalanceMargin = BN(1.03)
const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode) const cryptoRec = coinUtils.getCryptoCurrency(cryptoCode)
const unitScale = cryptoRec.unitScale const unitScale = cryptoRec.unitScale

View file

@ -25,16 +25,22 @@ function checkCryptoCode (cryptoCode) {
return Promise.resolve() return Promise.resolve()
} }
function accountBalance (account, cryptoCode, confirmations) { function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['', confirmations])) .then(() => fetch('getwalletinfo'))
.then(r => BN(r).shift(unitScale).round()) .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 // 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. // have at least 1 confirmation. getbalance does this for us automatically.
function balance (account, cryptoCode) { function balance (account, cryptoCode) {
return accountBalance(account, cryptoCode, 1) return accountBalance(cryptoCode)
} }
function sendCoins (account, address, cryptoAtoms, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) {
@ -80,13 +86,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress, cryptoCode)) .then(() => confirmedBalance(toAddress, cryptoCode))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(requested)) return {status: 'confirmed'} if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress, cryptoCode) return pendingBalance(toAddress, cryptoCode)
.then(pending => { .then(pending => {
if (pending.gte(requested)) return {status: 'authorized'} if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }
@ -95,9 +101,9 @@ function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const promises = [ const promises = [
accountBalance(account, cryptoCode, 0), accountUnconfirmedBalance(cryptoCode),
accountBalance(account, cryptoCode, 1), accountBalance(cryptoCode),
newAddress(account, {cryptoCode}) newAddress(account, { cryptoCode })
] ]
return Promise.all(promises) return Promise.all(promises)

View file

@ -25,16 +25,22 @@ function checkCryptoCode (cryptoCode) {
return Promise.resolve() return Promise.resolve()
} }
function accountBalance (account, cryptoCode, confirmations) { function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['*', confirmations])) .then(() => fetch('getwalletinfo'))
.then(r => BN(r).shift(unitScale).round()) .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 // 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. // have at least 1 confirmation. getbalance does this for us automatically.
function balance (account, cryptoCode) { function balance (account, cryptoCode) {
return accountBalance(account, cryptoCode, 1) return accountBalance(cryptoCode)
} }
function sendCoins (account, address, cryptoAtoms, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) {
@ -80,13 +86,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress, cryptoCode)) .then(() => confirmedBalance(toAddress, cryptoCode))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(requested)) return {status: 'confirmed'} if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress, cryptoCode) return pendingBalance(toAddress, cryptoCode)
.then(pending => { .then(pending => {
if (pending.gte(requested)) return {status: 'authorized'} if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }
@ -95,9 +101,9 @@ function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const promises = [ const promises = [
accountBalance(account, cryptoCode, 0), accountUnconfirmedBalance(cryptoCode),
accountBalance(account, cryptoCode, 1), accountBalance(cryptoCode),
newAddress(account, {cryptoCode}) newAddress(account, { cryptoCode })
] ]
return Promise.all(promises) return Promise.all(promises)

View file

@ -124,10 +124,10 @@ function getStatus (account, toAddress, requested, cryptoCode) {
const confirmed = _.compose(sum, toBn, filterConfirmed)(transfers) const confirmed = _.compose(sum, toBn, filterConfirmed)(transfers)
const pending = _.compose(sum, toBn, filterPending)(transfers) const pending = _.compose(sum, toBn, filterPending)(transfers)
if (confirmed.gte(requested)) return { status: 'confirmed' } if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
if (pending.gte(requested)) return { status: 'authorized' } if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return { status: 'insufficientFunds' } if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return { status: 'notSeen' } return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
} }

View file

@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
return Promise.resolve() return Promise.resolve()
} }
function accountBalance (acount, cryptoCode, confirmations) { function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['', confirmations])) .then(() => fetch('getwalletinfo'))
.then(r => BN(r).shift(unitScale).round()) .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 // 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. // have at least 1 confirmation. getbalance does this for us automatically.
function balance (account, cryptoCode) { function balance (account, cryptoCode) {
return accountBalance(account, cryptoCode, 1) return accountBalance(cryptoCode)
} }
function sendCoins (account, address, cryptoAtoms, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) {
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress, cryptoCode)) .then(() => confirmedBalance(toAddress, cryptoCode))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(requested)) return {status: 'confirmed'} if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress, cryptoCode) return pendingBalance(toAddress, cryptoCode)
.then(pending => { .then(pending => {
if (pending.gte(requested)) return {status: 'authorized'} if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const promises = [ const promises = [
accountBalance(account, cryptoCode, 0), accountUnconfirmedBalance(cryptoCode),
accountBalance(account, cryptoCode, 1), accountBalance(cryptoCode),
newAddress(account, {cryptoCode}) newAddress(account, { cryptoCode })
] ]
return Promise.all(promises) return Promise.all(promises)

View file

@ -158,13 +158,13 @@ function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress)) .then(() => confirmedBalance(toAddress))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(cryptoAtoms)) return {status: 'confirmed'} if (confirmed.gte(cryptoAtoms)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress) return pendingBalance(toAddress)
.then(pending => { .then(pending => {
if (pending.gte(cryptoAtoms)) return {status: 'published'} if (pending.gte(cryptoAtoms)) return { receivedCryptoAtoms: pending, status: 'published' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }

View file

@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
return Promise.resolve() return Promise.resolve()
} }
function accountBalance (acount, cryptoCode, confirmations) { function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['*', confirmations])) .then(() => fetch('getwalletinfo'))
.then(r => BN(r).shift(unitScale).round()) .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 // 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. // have at least 1 confirmation. getbalance does this for us automatically.
function balance (account, cryptoCode) { function balance (account, cryptoCode) {
return accountBalance(account, cryptoCode, 1) return accountBalance(cryptoCode)
} }
function sendCoins (account, address, cryptoAtoms, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) {
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress, cryptoCode)) .then(() => confirmedBalance(toAddress, cryptoCode))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(requested)) return {status: 'confirmed'} if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress, cryptoCode) return pendingBalance(toAddress, cryptoCode)
.then(pending => { .then(pending => {
if (pending.gte(requested)) return {status: 'authorized'} if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const promises = [ const promises = [
accountBalance(account, cryptoCode, 0), accountUnconfirmedBalance(cryptoCode),
accountBalance(account, cryptoCode, 1), accountBalance(cryptoCode),
newAddress(account, {cryptoCode}) newAddress(account, { cryptoCode })
] ]
return Promise.all(promises) return Promise.all(promises)

View file

@ -79,9 +79,9 @@ function newFunding (account, cryptoCode) {
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) { function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
const elapsed = Date.now() - t0 const elapsed = Date.now() - t0
if (elapsed < PUBLISH_TIME) return Promise.resolve({status: 'notSeen'}) if (elapsed < PUBLISH_TIME) return Promise.resolve({ receivedCryptoAtoms: BN(0), status: 'notSeen' })
if (elapsed < AUTHORIZE_TIME) return Promise.resolve({status: 'published'}) if (elapsed < AUTHORIZE_TIME) return Promise.resolve({ receivedCryptoAtoms: cryptoAtoms, status: 'published' })
if (elapsed < CONFIRM_TIME) return Promise.resolve({status: 'authorized'}) 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)) console.log('[%s] DEBUG: Mock wallet has confirmed transaction [%s]', cryptoCode, toAddress.slice(0, 5))

View file

@ -26,16 +26,22 @@ function checkCryptoCode (cryptoCode) {
return Promise.resolve() return Promise.resolve()
} }
function accountBalance (acount, cryptoCode, confirmations) { function accountBalance (cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => fetch('getbalance', ['', confirmations])) .then(() => fetch('getwalletinfo'))
.then(r => BN(r).shift(unitScale).round()) .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 // 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. // have at least 1 confirmation. getbalance does this for us automatically.
function balance (account, cryptoCode) { function balance (account, cryptoCode) {
return accountBalance(account, cryptoCode, 1) return accountBalance(cryptoCode)
} }
function sendCoins (account, address, cryptoAtoms, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) {
@ -81,13 +87,13 @@ function getStatus (account, toAddress, requested, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress, cryptoCode)) .then(() => confirmedBalance(toAddress, cryptoCode))
.then(confirmed => { .then(confirmed => {
if (confirmed.gte(requested)) return {status: 'confirmed'} if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
return pendingBalance(toAddress, cryptoCode) return pendingBalance(toAddress, cryptoCode)
.then(pending => { .then(pending => {
if (pending.gte(requested)) return {status: 'authorized'} if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'authorized' }
if (pending.gt(0)) return {status: 'insufficientFunds'} if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
return {status: 'notSeen'} return { receivedCryptoAtoms: pending, status: 'notSeen' }
}) })
}) })
} }
@ -96,9 +102,9 @@ function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => { .then(() => {
const promises = [ const promises = [
accountBalance(account, cryptoCode, 0), accountUnconfirmedBalance(cryptoCode),
accountBalance(account, cryptoCode, 1), accountBalance(cryptoCode),
newAddress(account, {cryptoCode}) newAddress(account, { cryptoCode })
] ]
return Promise.all(promises) return Promise.all(promises)

View file

@ -114,10 +114,10 @@ function poll (req, res, next) {
operatorInfo operatorInfo
} }
// BACKWARDS_COMPATIBILITY 7.5 // BACKWARDS_COMPATIBILITY 7.4.9
// machines before 7.5 expect t&c on poll // machines before 7.4.9 expect t&c on poll
if (!machineVersion || semver.lt(machineVersion, '7.5.0-beta')) { if (!machineVersion || semver.lt(machineVersion, '7.4.9')) {
response.terms = createTerms(terms) response.terms = config.termsScreenActive && config.termsScreenText ? createTerms(config) : null
} }
return res.json(_.assign(response, results)) return res.json(_.assign(response, results))

View file

@ -29,13 +29,13 @@ function massage (tx, pi) {
cashInFee: BN(r.cashInFee), cashInFee: BN(r.cashInFee),
cashInFeeCrypto: BN(r.cashInFeeCrypto), cashInFeeCrypto: BN(r.cashInFeeCrypto),
commissionPercentage: BN(r.commissionPercentage), commissionPercentage: BN(r.commissionPercentage),
rawTickerPrice: BN(r.rawTickerPrice), rawTickerPrice: r.rawTickerPrice ? BN(r.rawTickerPrice) : null,
minimumTx: BN(r.minimumTx) minimumTx: BN(r.minimumTx)
} }
: { : {
cryptoAtoms: BN(r.cryptoAtoms), cryptoAtoms: BN(r.cryptoAtoms),
fiat: BN(r.fiat), fiat: BN(r.fiat),
rawTickerPrice: BN(r.rawTickerPrice), rawTickerPrice: r.rawTickerPrice ? BN(r.rawTickerPrice) : null,
commissionPercentage: BN(r.commissionPercentage) commissionPercentage: BN(r.commissionPercentage)
} }

View file

@ -104,7 +104,7 @@ function mergeStatus (a, b) {
if (!a) return b if (!a) return b
if (!b) return a 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) { function mergeStatusMode (a, b) {
@ -122,8 +122,11 @@ function mergeStatusMode (a, b) {
} }
function getWalletStatus (settings, tx) { function getWalletStatus (settings, tx) {
const fudgeFactorEnabled = configManager.unscoped(settings.config).fudgeFactorActive
const fudgeFactor = fudgeFactorEnabled ? 100 : 0
const walletStatusPromise = fetchWallet(settings, tx.cryptoCode) 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([ return Promise.all([
walletStatusPromise, walletStatusPromise,
@ -169,7 +172,7 @@ function getStatus (settings, tx, machineId) {
const status = isAuthorized ? 'authorized' : unauthorizedStatus const status = isAuthorized ? 'authorized' : unauthorizedStatus
return { status } return { receivedCryptoAtoms: statusRec.receivedCryptoAtoms, status }
}) })
} }

View file

@ -0,0 +1,13 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_out_txs ADD COLUMN received_crypto_atoms numeric(30) null DEFAULT null'
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

5252
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -37383,7 +37383,11 @@ var _user$project$NavBar$determineConfigCategory = function (configCode) {
_1: { _1: {
ctor: '::', ctor: '::',
_0: 'operatorInfo', _0: 'operatorInfo',
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: 'fudgeFactor',
_1: {ctor: '[]'}
}
} }
} }
} }
@ -37836,7 +37840,11 @@ var _user$project$NavBar$view = F2(
_1: { _1: {
ctor: '::', ctor: '::',
_0: A2(configLink, 'operatorInfo', 'Operator Info'), _0: A2(configLink, 'operatorInfo', 'Operator Info'),
_1: {ctor: '[]'} _1: {
ctor: '::',
_0: A2(configLink, 'fudgeFactor', 'Fudge Factor'),
_1: {ctor: '[]'}
}
} }
} }
} }

View file

@ -4,7 +4,7 @@
"fields": [ "fields": [
{ {
"code": "apiKey", "code": "apiKey",
"display": "API key", "display": "Project ID",
"fieldType": "string", "fieldType": "string",
"secret": true, "secret": true,
"required": true, "required": true,
@ -12,7 +12,7 @@
}, },
{ {
"code": "apiSecret", "code": "apiSecret",
"display": "API secret", "display": "Project secret",
"fieldType": "password", "fieldType": "password",
"secret": true, "secret": true,
"required": true, "required": true,

View file

@ -0,0 +1 @@
### Early experiments in regtest

View file

@ -0,0 +1,35 @@
#!/bin/bash
PREFIX_W1='docker exec --user bitcoin bitcoin-server bitcoin-cli -rpcwallet=wallet1.dat -regtest '
PREFIX_W2='docker exec --user bitcoin bitcoin-server bitcoin-cli -rpcwallet=wallet2.dat -regtest '
# Create address and generate mine blocks
ADDRESS_1=`$PREFIX_W1 getnewaddress`
ADDRESS_2=`$PREFIX_W2 getnewaddress`
$PREFIX_W1 generatetoaddress 101 $ADDRESS_1 > /dev/null 2>&1
echo -e 'Wallet 1 balance'
$PREFIX_W1 getwalletinfo | grep balance
echo -e '\nWallet 2 balance'
$PREFIX_W2 getwalletinfo | grep balance
# Wallet one has one UTXO, so this also tests change
echo -e '\n\nCreate send\n'
$PREFIX_W1 sendtoaddress $ADDRESS_2 0.3 > /dev/null 2>&1
echo -e 'Wallet 1 balance'
$PREFIX_W1 getwalletinfo | grep balance
echo -e '\nWallet 2 balance'
$PREFIX_W2 getwalletinfo | grep balance
echo -e '\n\nMine one block \n'
$PREFIX_W1 generatetoaddress 1 $ADDRESS_1 > /dev/null 2>&1
echo -e 'Wallet 1 balance'
$PREFIX_W1 getwalletinfo | grep balance
echo -e '\nWallet 2 balance'
$PREFIX_W2 getwalletinfo | grep balance

View file

@ -0,0 +1,7 @@
#!/bin/bash
docker run --rm --name bitcoin-server -it ruimarinho/bitcoin-core \
-regtest=1 \
-wallet=wallet1.dat \
-wallet=wallet2.dat