Merge branch 'release-9.0' into chore/merge-9-into-10-20240214

This commit is contained in:
Rafael Taranto 2024-02-14 20:00:20 +00:00
commit 82acc20b9b
2 changed files with 30 additions and 8 deletions

View file

@ -4,6 +4,7 @@ const crypto = require('crypto')
const logger = require('../logger')
function sha256 (buf) {
if (!buf) return null
const hash = crypto.createHash('sha256')
hash.update(buf)
@ -12,9 +13,10 @@ function sha256 (buf) {
const populateDeviceId = function (req, res, next) {
const deviceId = _.isFunction(req.connection.getPeerCertificate)
? sha256(req.connection.getPeerCertificate().raw)
? sha256(req.connection.getPeerCertificate()?.raw)
: null
if (!deviceId) return res.status(500).json({ error: 'Unable to find certificate' })
req.deviceId = deviceId
req.deviceTime = req.get('date')

View file

@ -152,7 +152,6 @@ function sendProbeRequest (walletId, invoice, cryptoAtoms, token, endpoint) {
function sendCoins (account, tx, settings, operatorId) {
const { toAddress, cryptoAtoms, cryptoCode } = tx
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
return checkCryptoCode(cryptoCode)
.then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId))
.then(wallet => {
@ -166,7 +165,7 @@ function sendCoins (account, tx, settings, operatorId) {
case 'ALREADY_PAID':
throw new Error('Transaction already exists!')
case 'FAILURE':
throw new Error('Transaction failed!')
throw new Error('Transaction failed!', JSON.stringify(result.errors))
case 'SUCCESS':
return '<galoy transaction>'
case 'PENDING':
@ -178,7 +177,7 @@ function sendCoins (account, tx, settings, operatorId) {
}
function probeLN (account, cryptoCode, invoice) {
const probeHardLimits = [100, 500, 1000]
const probeHardLimits = [200000, 1000000, 2000000]
const promises = probeHardLimits.map(limit => {
return sendProbeRequest(account.walletId, invoice, limit, account.apiSecret, account.endpoint)
.then(r => _.isEmpty(r.errors))
@ -253,6 +252,25 @@ function newAddress (account, info, tx, settings, operatorId) {
})
}
function getInvoiceStatus (token, endpoint, address) {
const query = {
'operationName': 'lnInvoicePaymentStatus',
'query': `query lnInvoicePaymentStatus($input: LnInvoicePaymentStatusInput!) {
lnInvoicePaymentStatus(input: $input) {
status
}
}`,
'variables': {"input": {"paymentRequest": address}}
}
return request(query, token, endpoint)
.then(r => {
return r?.data?.lnInvoicePaymentStatus?.status
})
.catch(err => {
throw new Error(err)
})
}
function getStatus (account, tx, requested, settings, operatorId) {
const { toAddress, cryptoAtoms, cryptoCode } = tx
const getBalance = _.reduce((acc, value) => {
@ -260,13 +278,16 @@ function getStatus (account, tx, requested, settings, operatorId) {
return acc
}, { SUCCESS: new BN(0), PENDING: new BN(0), FAILURE: new BN(0) })
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
return checkCryptoCode(cryptoCode)
.then(() => {
const address = coinUtils.parseUrl(cryptoCode, account.environment, toAddress, false)
// Consider all LN transactions successful
if (isLightning(address)) {
return { receivedCryptoAtoms: cryptoAtoms, status: 'confirmed' }
return getInvoiceStatus(account.apiSecret, account.endpoint, address)
.then(it => {
const isPaid = it === 'PAID'
if (isPaid) return { receivedCryptoAtoms: cryptoAtoms, status: 'confirmed' }
return { receivedCryptoAtoms: BN(0), status: 'notSeen' }
})
}
// On-chain and intra-ledger transactions
return getTransactionsByAddress(account.apiSecret, account.endpoint, account.walletId, address)
@ -282,7 +303,6 @@ function getStatus (account, tx, requested, settings, operatorId) {
}
function newFunding (account, cryptoCode, settings, operatorId) {
const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode)
// Regular BTC address
return checkCryptoCode(cryptoCode)
.then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId))