Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions services/addressService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,32 @@ Address[]
})
}

export async function fetchAllAddresses (includeTransactions = false): Promise<AddressWithTransactions[]> {
return await prisma.address.findMany({
include: {
transactions: includeTransactions
}
})
}

export async function fetchUnsyncedAddresses (): Promise<Address[]> {
return await prisma.address.findMany({
where: {
lastSynced: null
}
})
}

export async function fetchAllAddressesForNetworkId (networkId: number): Promise<Address[]> {
export async function fetchAddressesToSync (networkId: number): Promise<Address[]> {
return await prisma.address.findMany({
where: {
networkId
networkId,
OR: [
{
transactions: {
some: {}
}
},
{
userProfiles: {
some: {}
}
},
{
paybuttons: {
some: {}
}
},
{
clientPayments: {
some: {}
}
}
]
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions services/chronikService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { Address, Prisma, ClientPaymentStatus } from '@prisma/client'
import xecaddr from 'xecaddrjs'
import { getAddressPrefix, satoshisToUnit } from 'utils/index'
import { fetchAddressesArray, fetchAllAddressesForNetworkId, getEarliestUnconfirmedTxTimestampForAddress, getLatestConfirmedTxTimestampForAddress, setSyncing, setSyncingBatch, updateLastSynced, updateManyLastSynced, upsertAddress } from './addressService'
import { fetchAddressesArray, fetchAddressesToSync, getEarliestUnconfirmedTxTimestampForAddress, getLatestConfirmedTxTimestampForAddress, setSyncing, setSyncingBatch, updateLastSynced, updateManyLastSynced, upsertAddress } from './addressService'
import * as ws from 'ws'
import { BroadcastTxData } from 'ws-service/types'
import config from 'config'
Expand Down Expand Up @@ -957,7 +957,7 @@ export class ChronikBlockchainClient {
}

public async syncMissedTransactions (): Promise<void> {
const addresses = await fetchAllAddressesForNetworkId(this.networkId)
const addresses = await fetchAddressesToSync(this.networkId)
try {
const { failedAddressesWithErrors, successfulAddressesWithCount } = await this.syncAddresses(addresses, true)
Object.keys(failedAddressesWithErrors).forEach((addr) => {
Expand All @@ -975,7 +975,7 @@ export class ChronikBlockchainClient {
}

public async subscribeInitialAddresses (): Promise<void> {
const addresses = await fetchAllAddressesForNetworkId(this.networkId)
const addresses = await fetchAddressesToSync(this.networkId)
try {
await this.subscribeAddresses(addresses)
} catch (err: any) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/chronikService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jest.mock('config', () => ({

// Mock all the services that might be called during initialization
jest.mock('../../services/addressService', () => ({
fetchAllAddressesForNetworkId: jest.fn().mockResolvedValue([]),
fetchAddressesToSync: jest.fn().mockResolvedValue([]),
fetchAddressBySubstring: jest.fn(),
fetchAddressesArray: jest.fn(),
getEarliestUnconfirmedTxTimestampForAddress: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/handleUpdateClientPaymentStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jest.mock('config', () => ({
}))

jest.mock('../../services/addressService', () => ({
fetchAllAddressesForNetworkId: jest.fn().mockResolvedValue([])
fetchAddressesToSync: jest.fn().mockResolvedValue([])
}))

jest.mock('../../services/priceService', () => ({
Expand Down