From 3465173e1a09a085d56c220a3380d57e657aac57 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Fri, 9 Feb 2024 19:05:25 +0000 Subject: [PATCH 1/4] fix: check for invoice fulfillment --- lib/plugins/wallet/galoy/galoy.js | 32 +++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/plugins/wallet/galoy/galoy.js b/lib/plugins/wallet/galoy/galoy.js index 0299aab0..ec4e57c8 100644 --- a/lib/plugins/wallet/galoy/galoy.js +++ b/lib/plugins/wallet/galoy/galoy.js @@ -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 '' case 'PENDING': @@ -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)) From d950a84e2a1a36c598c27f111cb1fc01bb70076f Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Fri, 9 Feb 2024 19:05:58 +0000 Subject: [PATCH 2/4] chore: declutter server logs --- lib/middlewares/populateDeviceId.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/middlewares/populateDeviceId.js b/lib/middlewares/populateDeviceId.js index 4c8913ae..dd2fd9e2 100644 --- a/lib/middlewares/populateDeviceId.js +++ b/lib/middlewares/populateDeviceId.js @@ -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') From fd2e9f24a57a644391f279e5bead48274af2f80d Mon Sep 17 00:00:00 2001 From: CrypticaScriptura <7396812+CrypticaScriptura@users.noreply.github.com> Date: Fri, 9 Feb 2024 14:14:12 -0500 Subject: [PATCH 3/4] chore: v9.0.0-beta.8 (#1649) --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cd102a4..58bc3dc4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lamassu-server", - "version": "9.0.0-beta.7", + "version": "9.0.0-beta.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 23110d46..f3c3bdce 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "lamassu-server", "description": "bitcoin atm client server protocol module", "keywords": [], - "version": "9.0.0-beta.7", + "version": "9.0.0-beta.8", "license": "./LICENSE", "author": "Lamassu (https://lamassu.is)", "dependencies": { From 15225024561372cd4bd77868f3657b2e6f821d79 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Mon, 12 Feb 2024 21:44:44 +0000 Subject: [PATCH 4/4] chore: adjust probe numbers temporarily --- lib/plugins/wallet/galoy/galoy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/wallet/galoy/galoy.js b/lib/plugins/wallet/galoy/galoy.js index ec4e57c8..cc47da35 100644 --- a/lib/plugins/wallet/galoy/galoy.js +++ b/lib/plugins/wallet/galoy/galoy.js @@ -177,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))