Skip to content

Commit 93a30c5

Browse files
authored
Merge pull request #886 from PayButton/fix/slow-tx-refresh
[#830] Fix: slow tx refresh
2 parents 5ee1145 + f8dc5e1 commit 93a30c5

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

services/chronikService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,15 @@ export class ChronikBlockchainClient implements BlockchainClient {
406406
}
407407
}
408408

409+
private async getRelatedAddressesForTransaction (transaction: Tx_InNode): Promise<string[]> {
410+
const inputAddresses = transaction.inputs.map(inp => outputScriptToAddress(this.networkSlug, inp.outputScript))
411+
const outputAddresses = transaction.outputs.map(out => outputScriptToAddress(this.networkSlug, out.outputScript))
412+
return [...inputAddresses, ...outputAddresses].filter(a => a !== undefined) as string[]
413+
}
414+
409415
private async getAddressesForTransaction (transaction: Tx_InNode): Promise<AddressWithTransaction[]> {
410-
const addressesFromStringArray = await fetchAddressesArray(this.getSubscribedAddresses())
416+
const relatedAddresses = await this.getRelatedAddressesForTransaction(transaction)
417+
const addressesFromStringArray = await fetchAddressesArray(relatedAddresses)
411418
const addressesWithTransactions: AddressWithTransaction[] = await Promise.all(addressesFromStringArray.map(
412419
async address => {
413420
return {

services/transactionService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function getTransactionValue (transaction: TransactionWithPrices):
1717
cad: new Prisma.Decimal(0)
1818
}
1919
if (transaction.prices.length !== N_OF_QUOTES) {
20-
throw new Error(`Error: ${RESPONSE_MESSAGES.MISSING_PRICE_FOR_TRANSACTION_400.message} found in ${transaction.prices.length}. txId: ${transaction.id}, at ${transaction.timestamp}`)
20+
throw new Error(`Error: ${RESPONSE_MESSAGES.MISSING_PRICE_FOR_TRANSACTION_400.message} found ${transaction.prices.length}. txId: ${transaction.hash}, at ${transaction.timestamp}`)
2121
}
2222
for (const p of transaction.prices) {
2323
if (p.price.quoteId === USD_QUOTE_ID) {
@@ -504,7 +504,7 @@ export const getTransactionValueInCurrency = (transaction: TransactionWithAddres
504504
const {
505505
prices,
506506
amount,
507-
id,
507+
hash,
508508
timestamp
509509
} = transaction
510510

@@ -514,7 +514,7 @@ export const getTransactionValueInCurrency = (transaction: TransactionWithAddres
514514
}
515515

516516
if (prices.length !== N_OF_QUOTES) {
517-
throw new Error(`${RESPONSE_MESSAGES.MISSING_PRICE_FOR_TRANSACTION_400.message}, txId ${id}, at ${timestamp}`)
517+
throw new Error(`${RESPONSE_MESSAGES.MISSING_PRICE_FOR_TRANSACTION_400.message}, txId ${hash}, at ${timestamp}`)
518518
}
519519

520520
for (const p of prices) {

0 commit comments

Comments
 (0)