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 all 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
3 changes: 2 additions & 1 deletion docs/node/CATEGORIES/08-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,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 @@ -315,6 +315,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,27 @@ 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 })
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)
const combinedCount = await client.account.historyCount([from, to])

expect(combinedCount).toStrictEqual(fromCount + toCount)
})
})
8 changes: 5 additions & 3 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -337,15 +337,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] 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<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 @@ -554,6 +555,7 @@ export interface AccountHistoryOptions {
export interface AccountHistoryCountOptions {
token?: string
txtype?: DfTxType
txtypes?: DfTxType[]
no_rewards?: boolean
}

Expand Down