From 6b881638044d927a010a6ec6c607d1e9c8f0b046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Ka=C5=A1tovsk=C3=BD?= Date: Wed, 1 Nov 2023 08:50:03 +0100 Subject: [PATCH] UTXO `Address.getTransactions` block ranges support (#1007) ALL-3243: add utxo block range params --- CHANGELOG.md | 4 +++ package.json | 2 +- src/e2e/tatum.address.spec.ts | 57 ++++++++++++++++++++++++++++++++++ src/service/address/address.ts | 15 ++++++++- 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ab2b54e67..bb1a2c56fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package.json b/package.json index f5ae457ba0..feeb1a1e08 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/e2e/tatum.address.spec.ts b/src/e2e/tatum.address.spec.ts index 1ac4c7de55..95d6842830 100644 --- a/src/e2e/tatum.address.spec.ts +++ b/src/e2e/tatum.address.spec.ts @@ -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 @@ -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 @@ -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', () => { diff --git a/src/service/address/address.ts b/src/service/address/address.ts index 96c52177ae..55fc14113a 100644 --- a/src/service/address/address.ts +++ b/src/service/address/address.ts @@ -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, + ) }) } @@ -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< @@ -367,6 +378,8 @@ export class Address { pageSize, offset: page * pageSize, txType: transactionDirection, + blockFrom, + blockTo, }, }) .then((r) => {