From 9feacb4e5e792a5f0128a0eb36313bbad5a6ccce Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Fri, 23 Dec 2022 15:52:22 +0800 Subject: [PATCH 1/6] Update to support multi-txtype multi-address filter --- apps/whale-api/docker-compose.yml | 2 +- .../account/accountHistoryCount.test.ts | 28 ++++++++++++++++--- .../src/category/account.ts | 6 ++-- .../src/containers/DeFiDContainer.ts | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/apps/whale-api/docker-compose.yml b/apps/whale-api/docker-compose.yml index bb7dd884aa..4e6f5a659e 100644 --- a/apps/whale-api/docker-compose.yml +++ b/apps/whale-api/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.7' services: defi-blockchain: - image: defi/defichain:3.1.1 + image: defi/defichain:HEAD-22a537405 ports: - "19554:19554" command: > diff --git a/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts b/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts index 800914996a..1e36ebeede 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts @@ -6,6 +6,7 @@ import { AccountHistoryCountOptions, DfTxType } from '../../../src/category/acco describe('Account', () => { const container = new MasterNodeRegTestContainer() const client = new ContainerAdapterClient(container) + let from: string, to: string beforeAll(async () => { await container.start() @@ -19,10 +20,10 @@ describe('Account', () => { }) async function setup (): Promise { - const from = await container.call('getnewaddress') + from = await container.call('getnewaddress') await createToken(from, 'DBTC', 200) - const to = await accountToAccount('DBTC', 5, from) + to = await accountToAccount('DBTC', 5, from) await accountToAccount('DBTC', 18, from, to) await createToken(from, 'DETH', 200) @@ -102,7 +103,7 @@ describe('Account', () => { }) }) - it('should get accountHistory with txtype option', async () => { + it('should get accountHistoryCount with txtype option', async () => { await waitForExpect(async () => { const options: AccountHistoryCountOptions = { txtype: DfTxType.MINT_TOKEN @@ -121,7 +122,6 @@ describe('Account', () => { } const options2: AccountHistoryCountOptions = { txtype: DfTxType.POOL_SWAP - } const count1 = await client.account.historyCount('mine', options1) const count2 = await client.account.historyCount('mine', options2) @@ -129,4 +129,24 @@ describe('Account', () => { expect(count1 === count2).toStrictEqual(false) }) }) + + it('should get accountHistoryCount for multiple txtypes at once', async () => { + const mintCount = await client.account.historyCount('mine', { txtype: DfTxType.MINT_TOKEN }) + const poolSwapCount = await client.account.historyCount('mine', { txtype: DfTxType.POOL_SWAP }) + + await waitForExpect(async () => { + const combinedCount = await client.account.historyCount('mine', { txtypes: [DfTxType.MINT_TOKEN, DfTxType.POOL_SWAP] }) + expect(combinedCount).toStrictEqual(mintCount + poolSwapCount) + }) + }) + + it('should get accountHistoryCount for multiple addresses at once', async () => { + const fromCount = await client.account.historyCount(from) + const toCount = await client.account.historyCount(to) + + await waitForExpect(async () => { + const combinedCount = await client.account.historyCount([from, to]) + expect(combinedCount).toStrictEqual(fromCount + toCount) + }) + }) }) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 76071ca132..76e626af5a 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -333,15 +333,16 @@ export class Account { /** * Returns count of account history * - * @param {OwnerType | string} [owner=OwnerType.MINE] single account ID (CScript or address) or reserved words 'mine' to list history count for all owned accounts or 'all' to list whole DB + * @param {OwnerType | string | string[]} [owner=OwnerType.MINE] Single/multiple account ID(s) (CScript or address) or reserved words 'mine' to list history count for all owned accounts or 'all' to list whole DB * @param {AccountHistoryCountOptions} [options] * @param {boolean} [options.no_rewards] Filter out rewards * @param {string} [options.token] Filter by token * @param {DfTxType} [options.txtype] Filter by transaction type. See DfTxType. + * @param {DfTxType[]} [options.txtypes] Filter by multiple transaction types. See DfTxType. * @return {Promise} count of account history */ async historyCount ( - owner: OwnerType | string = OwnerType.MINE, + owner: OwnerType | string | string [] = OwnerType.MINE, options: AccountHistoryCountOptions = {} ): Promise { return await this.client.call('accounthistorycount', [owner, options], 'number') @@ -547,6 +548,7 @@ export interface AccountHistoryOptions { export interface AccountHistoryCountOptions { token?: string txtype?: DfTxType + txtypes?: DfTxType[] no_rewards?: boolean } diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index f9aeb7e1a5..faa2eb7cb8 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -36,7 +36,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:3.1.1' + return 'defi/defichain:HEAD-22a537405' } public static readonly DefaultStartOptions = { From 1d88862c2f377f3d438921eda9d4429c22792c83 Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Tue, 3 Jan 2023 14:08:58 +0800 Subject: [PATCH 2/6] Bump image to fe4ccb39d --- apps/whale-api/docker-compose.yml | 2 +- packages/testcontainers/src/containers/DeFiDContainer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/whale-api/docker-compose.yml b/apps/whale-api/docker-compose.yml index 4e6f5a659e..336d10eec7 100644 --- a/apps/whale-api/docker-compose.yml +++ b/apps/whale-api/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.7' services: defi-blockchain: - image: defi/defichain:HEAD-22a537405 + image: defi/defichain:HEAD-fe4ccb39d ports: - "19554:19554" command: > diff --git a/packages/testcontainers/src/containers/DeFiDContainer.ts b/packages/testcontainers/src/containers/DeFiDContainer.ts index faa2eb7cb8..21857480c0 100644 --- a/packages/testcontainers/src/containers/DeFiDContainer.ts +++ b/packages/testcontainers/src/containers/DeFiDContainer.ts @@ -36,7 +36,7 @@ export abstract class DeFiDContainer extends DockerContainer { if (process?.env?.DEFICHAIN_DOCKER_IMAGE !== undefined) { return process.env.DEFICHAIN_DOCKER_IMAGE } - return 'defi/defichain:HEAD-22a537405' + return 'defi/defichain:HEAD-fe4ccb39d' } public static readonly DefaultStartOptions = { From c3acc51df0d31dfe5372f7073dd6aad8f0405aeb Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Tue, 3 Jan 2023 14:54:20 +0800 Subject: [PATCH 3/6] Update docs --- docs/node/CATEGORIES/08-account.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index e2c03c0d86..818ed69ff3 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -276,7 +276,7 @@ Returns count of account history ```ts title="client.account.historyCount()" interface account { historyCount ( - owner: OwnerType | string = OwnerType.MINE, + owner: OwnerType | string | string[] = OwnerType.MINE, options: AccountHistoryCountOptions = {} ): Promise } @@ -310,6 +310,7 @@ enum DfTxType { interface AccountHistoryCountOptions { token?: string txtype?: DfTxType + txtypes?: DfTxType[] no_rewards?: boolean } ``` @@ -588,4 +589,4 @@ interface DusdSwapsInfo { owner: string amount: BigNumber } -``` \ No newline at end of file +``` From 8eb155b69f12b810d13a60a3ce53bbec7e804636 Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Tue, 3 Jan 2023 15:04:42 +0800 Subject: [PATCH 4/6] Remove extra line --- docs/node/CATEGORIES/08-account.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/node/CATEGORIES/08-account.md b/docs/node/CATEGORIES/08-account.md index 818ed69ff3..540f5fb2ff 100644 --- a/docs/node/CATEGORIES/08-account.md +++ b/docs/node/CATEGORIES/08-account.md @@ -589,4 +589,4 @@ interface DusdSwapsInfo { owner: string amount: BigNumber } -``` +``` \ No newline at end of file From fe753048621b58f14c4ed9e5baba375faeb77838 Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Thu, 5 Jan 2023 16:12:14 +0800 Subject: [PATCH 5/6] Remove waitForExpect --- .../category/account/accountHistoryCount.test.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts b/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts index 1e36ebeede..8abd85e59c 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/accountHistoryCount.test.ts @@ -133,20 +133,16 @@ describe('Account', () => { it('should get accountHistoryCount for multiple txtypes at once', async () => { const mintCount = await client.account.historyCount('mine', { txtype: DfTxType.MINT_TOKEN }) const poolSwapCount = await client.account.historyCount('mine', { txtype: DfTxType.POOL_SWAP }) + const combinedCount = await client.account.historyCount('mine', { txtypes: [DfTxType.MINT_TOKEN, DfTxType.POOL_SWAP] }) - await waitForExpect(async () => { - const combinedCount = await client.account.historyCount('mine', { txtypes: [DfTxType.MINT_TOKEN, DfTxType.POOL_SWAP] }) - expect(combinedCount).toStrictEqual(mintCount + poolSwapCount) - }) + expect(combinedCount).toStrictEqual(mintCount + poolSwapCount) }) it('should get accountHistoryCount for multiple addresses at once', async () => { const fromCount = await client.account.historyCount(from) const toCount = await client.account.historyCount(to) + const combinedCount = await client.account.historyCount([from, to]) - await waitForExpect(async () => { - const combinedCount = await client.account.historyCount([from, to]) - expect(combinedCount).toStrictEqual(fromCount + toCount) - }) + expect(combinedCount).toStrictEqual(fromCount + toCount) }) }) From 8b12991c020effca9ed0120b3560613294673579 Mon Sep 17 00:00:00 2001 From: Dilshan Madushanka Date: Thu, 19 Jan 2023 18:45:04 +0800 Subject: [PATCH 6/6] Update jsDocs --- packages/jellyfish-api-core/src/category/account.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 4f2eb08768..f2be397586 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -294,7 +294,7 @@ export class Account { /** * Returns information about account history * - * @param {OwnerType | string | string[]} [owner=OwnerType.MINE] Single/multiple account ID(s) (CScript or address) or reserved words 'mine' to list history for all owned accounts or 'all' to list whole DB + * @param {OwnerType | string | string[]} [owner=OwnerType.MINE] Account ID(s) (CScript or address) or reserved words 'mine' to list history for all owned accounts or 'all' to list whole DB * @param {AccountHistoryOptions} [options] * @param {number} [options.maxBlockHeight] Optional height to iterate from (down to genesis block), (default = chaintip). * @param {number} [options.depth] Maximum depth, from the genesis block is the default @@ -337,7 +337,7 @@ export class Account { /** * Returns count of account history * - * @param {OwnerType | string | string[]} [owner=OwnerType.MINE] Single/multiple account ID(s) (CScript or address) or reserved words 'mine' to list history count for all owned accounts or 'all' to list whole DB + * @param {OwnerType | string | string[]} [owner=OwnerType.MINE] Account ID(s) (CScript or address) or reserved words 'mine' to list history count for all owned accounts or 'all' to list whole DB * @param {AccountHistoryCountOptions} [options] * @param {boolean} [options.no_rewards] Filter out rewards * @param {string} [options.token] Filter by token