Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jellyfish-api-core): Add multi-txtype, multi-address query support for accounthistorycount RPC #1943

Merged
merged 14 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion apps/whale-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.7'

services:
defi-blockchain:
image: defi/defichain:3.2.0
image: defi/defichain:HEAD-fe4ccb39d
ports:
- "19554:19554"
command: >
Expand Down
3 changes: 2 additions & 1 deletion docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>
}
Expand Down Expand Up @@ -310,6 +310,7 @@ enum DfTxType {
interface AccountHistoryCountOptions {
token?: string
txtype?: DfTxType
txtypes?: DfTxType[]
no_rewards?: boolean
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -19,10 +20,10 @@ describe('Account', () => {
})

async function setup (): Promise<void> {
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)
Expand Down Expand Up @@ -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
Expand All @@ -121,12 +122,31 @@ 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)

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 () => {
helloscoopa marked this conversation as resolved.
Show resolved Hide resolved
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)
})
})
})
6 changes: 4 additions & 2 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
helloscoopa marked this conversation as resolved.
Show resolved Hide resolved
* @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<number>} count of account history
*/
async historyCount (
owner: OwnerType | string = OwnerType.MINE,
owner: OwnerType | string | string [] = OwnerType.MINE,
options: AccountHistoryCountOptions = {}
): Promise<number> {
return await this.client.call('accounthistorycount', [owner, options], 'number')
Expand Down Expand Up @@ -547,6 +548,7 @@ export interface AccountHistoryOptions {
export interface AccountHistoryCountOptions {
token?: string
txtype?: DfTxType
txtypes?: DfTxType[]
no_rewards?: boolean
}

Expand Down
2 changes: 1 addition & 1 deletion packages/testcontainers/src/containers/DeFiDContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.0'
return 'defi/defichain:HEAD-fe4ccb39d'
helloscoopa marked this conversation as resolved.
Show resolved Hide resolved
}

public static readonly DefaultStartOptions = {
Expand Down