Skip to content

Commit

Permalink
fixup! Upgrade to edge-core-js v2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec committed May 7, 2024
1 parent 8609930 commit 4c20028
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
33 changes: 27 additions & 6 deletions src/common/utxobased/db/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ interface FetchTransactionArgs {
blockHeight?: number
blockHeightMax?: number
txId?: string
options?: EdgeGetTransactionsOptions
options?: EdgeGetTransactionsOptions & {
endDate?: Date
startDate?: Date
startEntries?: number
startIndex?: number
}
}

interface FetchUtxosArgs {
Expand Down Expand Up @@ -368,12 +373,28 @@ export async function makeProcessor(
txs.push(...txsById)
}
if (options != null) {
const {
startEntries,
startIndex,
startDate = new Date(0),
endDate = new Date()
} = options

// Fetch transaction IDs ordered by date
const txData: TxIdByDate[] = await tables.txIdsByDate.query(
'',
0,
unixTime(Date.now())
)
let txData: TxIdByDate[]
if (startEntries != null && startIndex != null) {
txData = await tables.txIdsByDate.queryByCount(
'',
startEntries,
startIndex
)
} else {
txData = await tables.txIdsByDate.query(
'',
unixTime(startDate.getTime()),
unixTime(endDate.getTime())
)
}
const txIdsByOptions = await txData
.reverse()
.map(({ txid: id }) => id)
Expand Down
38 changes: 34 additions & 4 deletions test/common/utxobased/db/Processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,29 @@ describe('Processor transactions tests', () => {
expect(tx3?.ourAmount).to.eqls('1')

const [tx4] = await processor.fetchTransactions({
options: { tokenId: null }
options: {
tokenId: null
}
})
expect(tx4).not.to.be.undefined

const results = await processor.fetchTransactions({
options: {
tokenId: null,
startDate: new Date(11_000),
endDate: new Date(15_000)
}
})
expect(results).to.deep.equal([])

const [tx6] = await processor.fetchTransactions({
options: {
tokenId: null,
startDate: new Date(9_000),
endDate: new Date(15_000)
}
})
expect(tx6).not.to.be.undefined
})

it('insert multiple transactions to baselets', async () => {
Expand Down Expand Up @@ -683,17 +703,27 @@ describe('Processor transactions tests', () => {
expect(tx3?.ourAmount).to.eqls('1')

const [tx4] = await processor.fetchTransactions({
options: { tokenId: null }
options: {
tokenId: null
}
})
expect(tx4).not.to.be.undefined

const [tx5] = await processor.fetchTransactions({
options: { tokenId: null }
options: {
tokenId: null,
startDate: new Date(11_000),
endDate: new Date(20_000)
}
})
expect(tx5).not.to.be.undefined

const tx6 = await processor.fetchTransactions({
options: { tokenId: null }
options: {
tokenId: null,
startDate: new Date(9_000),
endDate: new Date(21_000)
}
})
expect(tx6.length).to.eqls(2)
})
Expand Down

0 comments on commit 4c20028

Please sign in to comment.