Skip to content

Commit

Permalink
UTXO Address.getTransactions block ranges support (#1007)
Browse files Browse the repository at this point in the history
ALL-3243: add utxo block range params
  • Loading branch information
filipkastovsky authored Nov 1, 2023
1 parent de96b53 commit 6b88163
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [4.1.20] - 2023.10.31
### Fixed
- Fixed usage of `fromBlock` and `toBlock` params for UTXO-based blockchains in `Address.getTransactions`

## [4.1.19] - 2023.10.31
### Fixed
- Configurable extension usage typing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "4.1.19",
"version": "4.1.20",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
57 changes: 57 additions & 0 deletions src/e2e/tatum.address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,25 @@ describe.skip('Address', () => {
transactionType: 'incoming',
})
})

it('should get transactions by block with cursor pagination', async () => {
const txs = await tatum.address.getTransactions({
address: 'tb1qrd9jz8ksy3qqm400vt296udlvk89z96p443mv0',
fromBlock: 2427335,
toBlock: 2427654,
})
expect(txs.status === Status.SUCCESS)
expect(txs.data).toHaveLength(1)
expect(txs.data[0]).toStrictEqual({
address: 'tb1qrd9jz8ksy3qqm400vt296udlvk89z96p443mv0',
amount: '0.01796111',
blockNumber: 2427335,
chain: 'bitcoin-testnet',
hash: 'ea428edd33dbadf1c9fc11320ab8d4cac4a3b52fc5f086ab46c8b02c71b1e53e',
timestamp: 1680597327,
transactionType: 'outgoing',
})
})
})
describe('getTransactions DOGECOIN', () => {
let tatum: Dogecoin
Expand Down Expand Up @@ -554,6 +573,25 @@ describe.skip('Address', () => {
transactionType: 'outgoing',
})
})

it('should get transactions by block with cursor pagination', async () => {
const txs = await tatum.address.getTransactions({
address: 'nqNmVv1PCPFbNQLBMbeKhW4YrswqEgpVsr',
fromBlock: 4334638,
toBlock: 4373217,
})
expect(txs.status === Status.SUCCESS)
expect(txs.data).toHaveLength(1)
expect(txs.data[0]).toStrictEqual({
address: 'nqNmVv1PCPFbNQLBMbeKhW4YrswqEgpVsr',
amount: '2',
blockNumber: 4334638,
chain: 'doge-testnet',
hash: 'b417a1b5ffa6aec9d6f6ba2895876ac9036353efc555bdb660194a5af3b88036',
timestamp: 1680110455,
transactionType: 'outgoing',
})
})
})
describe('getTransactions LITECOIN', () => {
let tatum: Litecoin
Expand Down Expand Up @@ -609,6 +647,25 @@ describe.skip('Address', () => {
transactionType: 'incoming',
})
})

it('should get transactions by block with cursor pagination', async () => {
const txs = await tatum.address.getTransactions({
address: 'n22dLZeTMRCUpaLMdgDcQzUXJJnfKcsnS3',
fromBlock: 2719828,
toBlock: 2719829,
})
expect(txs.status === Status.SUCCESS)
expect(txs.data).toHaveLength(1)
expect(txs.data[0]).toStrictEqual({
address: 'n22dLZeTMRCUpaLMdgDcQzUXJJnfKcsnS3',
amount: '0.0009',
blockNumber: 2719828,
chain: 'litecoin-testnet',
hash: '7643cfd74bfd6cea2fc6f2b80ebbe03d3f1673125d445b63f23a32f83d1438c6',
timestamp: 1680110627,
transactionType: 'outgoing',
})
})
})

describe('getTransactions Tezos', () => {
Expand Down
15 changes: 14 additions & 1 deletion src/service/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,16 @@ export class Address {
// TODO: implement for other networks - TRON, XRP, CARDANO, SOL, XLM etc etc
throw new Error(`Not supported for ${chain} network.`)
}
return this.processUtxoBasedTxs(path, pageSize, page, transactionDirection, chain, address)
return this.processUtxoBasedTxs(
path,
pageSize,
page,
transactionDirection,
chain,
address,
fromBlock,
toBlock,
)
})
}

Expand Down Expand Up @@ -350,6 +359,8 @@ export class Address {
transactionDirection: 'incoming' | 'outgoing' | undefined,
chain: Network,
address: string,
blockFrom: number | undefined,
blockTo: number | undefined,
) {
return this.connector
.get<
Expand All @@ -367,6 +378,8 @@ export class Address {
pageSize,
offset: page * pageSize,
txType: transactionDirection,
blockFrom,
blockTo,
},
})
.then((r) => {
Expand Down

0 comments on commit 6b88163

Please sign in to comment.