From 1cd1e1d9abdeaab6e7abcba26395127e30cc4d09 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Wed, 10 Jan 2024 23:11:21 +0000 Subject: [PATCH] chore: use old galoy api --- lib/plugins/wallet/galoy/galoy.js | 58 +++++++++++++------------------ package-lock.json | 14 ++++---- package.json | 2 +- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/lib/plugins/wallet/galoy/galoy.js b/lib/plugins/wallet/galoy/galoy.js index c98de2ce..eb62f9ad 100644 --- a/lib/plugins/wallet/galoy/galoy.js +++ b/lib/plugins/wallet/galoy/galoy.js @@ -35,17 +35,15 @@ function checkCryptoCode (cryptoCode) { return Promise.resolve() } -function getTransactionsByAddress (token, endpoint, address) { +function getTransactionsByAddress (token, endpoint, walletId, address) { const accountInfo = { 'operationName': 'me', 'query': `query me { me { defaultAccount { - defaultWalletId wallets { id - walletCurrency - transactionsByAddress (address: "${address}") + transactionsByAddress (address: "${address}") { edges { node { direction @@ -62,33 +60,32 @@ function getTransactionsByAddress (token, endpoint, address) { } return request(accountInfo, token, endpoint) .then(r => { - return r.data.me.defaultAccount + return _.find(it => it.id === walletId, r.data.me.defaultAccount.wallets).transactionsByAddress }) .catch(err => { throw new Error(err) }) } -function getGaloyAccount (token, endpoint, walletId) { +function getGaloyWallet (token, endpoint, walletId) { const accountInfo = { 'operationName': 'me', - 'query': `query me($walletId: WalletId!) { + 'query': `query me { me { defaultAccount { - walletById(walletId: $walletId) { + wallets { id walletCurrency balance - pendingIncomingBalance } } } }`, - 'variables': { 'walletId': `${walletId}` } + 'variables': {} } return request(accountInfo, token, endpoint) .then(r => { - return r.data.me.defaultAccount + return _.find(it => it.id === walletId, r.data.me.defaultAccount.wallets) }) .catch(err => { throw new Error(err) @@ -157,9 +154,8 @@ function sendCoins (account, tx, settings, operatorId) { const { toAddress, cryptoAtoms, cryptoCode } = tx const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode) return checkCryptoCode(cryptoCode) - .then(() => getGaloyAccount(account.apiSecret, account.endpoint, account.walletId)) - .then(galoyAccount => { - const wallet = galoyAccount.walletById + .then(() => getGaloyWallet(account.apiSecret, account.endpoint, account.walletId)) + .then(wallet => { if (isLightning(toAddress)) { return sendFundsLN(wallet.id, toAddress, cryptoAtoms, account.apiSecret, account.endpoint) } @@ -235,9 +231,8 @@ function newInvoice (walletId, cryptoAtoms, token, endpoint) { function balance (account, cryptoCode, settings, operatorId) { return checkCryptoCode(cryptoCode) - .then(() => getGaloyAccount(account.apiSecret, account.endpoint)) - .then(galoyAccount => { - const wallet = galoyAccount.walletById + .then(() => getGaloyWallet(account.apiSecret, account.endpoint)) + .then(wallet => { return new BN(wallet.balance || 0) }) } @@ -245,9 +240,8 @@ function balance (account, cryptoCode, settings, operatorId) { function newAddress (account, info, tx, settings, operatorId) { const { cryptoAtoms, cryptoCode } = tx return checkCryptoCode(cryptoCode) - .then(() => getGaloyAccount(account.apiSecret, account.endpoint)) - .then(galoyAccount => { - const wallet = galoyAccount.walletById + .then(() => getGaloyWallet(account.apiSecret, account.endpoint)) + .then(wallet => { const promises = [ newOnChainAddress(wallet.id, account.apiSecret, account.endpoint), newInvoice(wallet.id, cryptoAtoms, account.apiSecret, account.endpoint) @@ -275,13 +269,10 @@ function getStatus (account, tx, requested, settings, operatorId) { return { receivedCryptoAtoms: cryptoAtoms, status: 'confirmed' } } // On-chain and intra-ledger transactions - return getTransactionsByAddress(account.apiSecret, account.endpoint, address) - .then(accountInfo => { - const transactions = - _.find(wallet => wallet.walletCurrency === externalCryptoCode && - wallet.id === accountInfo.defaultWalletId && - wallet.id === account.walletId)(accountInfo.wallets).transactions.edges - const { SUCCESS: confirmed, PENDING: pending } = getBalance(transactions) + return getTransactionsByAddress(account.apiSecret, account.endpoint, account.walletId, address) + .then(transactions => { + const txEdges = transactions.edges + const { SUCCESS: confirmed, PENDING: pending } = getBalance(txEdges) 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' } @@ -294,15 +285,15 @@ function newFunding (account, cryptoCode, settings, operatorId) { const externalCryptoCode = coinUtils.getEquivalentCode(cryptoCode) // Regular BTC address return checkCryptoCode(cryptoCode) - .then(() => getGaloyAccount(account.apiSecret, account.endpoint)) - .then(galoyAccount => { - const wallet = galoyAccount.walletById + .then(() => getGaloyWallet(account.apiSecret, account.endpoint)) + .then(wallet => { return newOnChainAddress(wallet.id, account.apiSecret, account.endpoint) - .then(onChainAddress => [onChainAddress, wallet.balance, wallet.pendingIncomingBalance]) + .then(onChainAddress => [onChainAddress, wallet.balance]) }) - .then(([onChainAddress, balance, pendingIncomingBalance]) => { + .then(([onChainAddress, balance]) => { return { - fundingPendingBalance: new BN(pendingIncomingBalance), + // with the old api is not possible to get pending balance + fundingPendingBalance: new BN(0), fundingConfirmedBalance: new BN(balance), fundingAddress: onChainAddress } @@ -328,6 +319,5 @@ module.exports = { newFunding, cryptoNetwork, checkBlockchainStatus, - sendProbeRequest, probeLN } diff --git a/package-lock.json b/package-lock.json index 9b5ad76a..c16bbee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4040,9 +4040,9 @@ } }, "@lamassu/bolt11": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@lamassu/bolt11/-/bolt11-1.5.0.tgz", - "integrity": "sha512-zvPbYuWuTJmvlU4nUjYBY/OtLFczHm5v/yNS9PTvFQJGSIQ2/7K3OEwl8FtTnV9KhIojoR7ue6NMSK2VHHqACA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@lamassu/bolt11/-/bolt11-1.5.1.tgz", + "integrity": "sha512-uP1FyG2cGUveX4tpcbpfs+px0aty0/cJ0O+v+yro24sSYOUvWT/N89yhZBOo/dOGEW+S3J45vzBoeH/OnK6jgA==", "requires": { "bech32": "^1.1.2", "bitcoinjs-lib": "4.0.3", @@ -4065,11 +4065,11 @@ } }, "@lamassu/coins": { - "version": "1.4.0-beta.4", - "resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.0-beta.4.tgz", - "integrity": "sha512-Tjy3g1FwMJWGNe8pSxSG6ZeETF70ekzTSmNQX/v5BE3l5vsCcmIyug65KU265eyHQT6/IwzUNL8p7NE6VAKakQ==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@lamassu/coins/-/coins-1.4.2.tgz", + "integrity": "sha512-eMDpKn/PEUVNsQ31ErLnHxObp7Wrab2g5YANnavUlfD5IUnmmlPGBTfYwDLWy9SHB1P46WsZJPncR12EcnrGqA==", "requires": { - "@lamassu/bolt11": "1.5.0", + "@lamassu/bolt11": "1.5.1", "bech32": "2.0.0", "big-integer": "^1.6.48", "bignumber.js": "^9.0.0", diff --git a/package.json b/package.json index f1b39217..18f24149 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@ethereumjs/common": "^2.6.4", "@ethereumjs/tx": "^3.5.1", "@graphql-tools/merge": "^6.2.5", - "@lamassu/coins": "v1.4.0-beta.4", + "@lamassu/coins": "v1.4.2", "@simplewebauthn/server": "^3.0.0", "@vonage/auth": "^1.5.0", "@vonage/sms": "^1.7.0",