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

Added listBurnHistory RPC #444

Merged
merged 23 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e7ca57e
Added listBurnHistory RPC
Jouzo Jul 6, 2021
0cd7ef8
Added listBurnHistory tests
Jouzo Jul 6, 2021
0731def
Added transaction type NONE
Jouzo Jul 6, 2021
8bb6a13
Added listBurnHistory API documentation
Jouzo Jul 6, 2021
afb3d2a
import createToken and accountToAccount from @defichain/testing
Jouzo Jul 6, 2021
c6f7730
remove global variables
Jouzo Jul 6, 2021
7daa763
Refactor test. Creates history beforeAll and then checks each element…
Jouzo Jul 12, 2021
81f7f45
Merge branch 'main' of https://github.com/DeFiCh/jellyfish into jouzo…
Jouzo Jul 12, 2021
1a839fd
Update packages/jellyfish-api-core/src/category/account.ts
Jouzo Jul 12, 2021
eb1335a
with maxBlockHeight, depth and limit tests
Jouzo Jul 13, 2021
c29b84f
remove duplicated tests
Jouzo Jul 15, 2021
30ae17d
requested change on maxBlockHeight test
Jouzo Jul 15, 2021
3aa69d5
with clearer depth test
Jouzo Jul 15, 2021
22b89ec
revert changes to maxblockheight and depth tests and make them cleare…
Jouzo Jul 16, 2021
1bf37f7
remove redundant block generation
Jouzo Jul 16, 2021
b2fede2
change depth and maxBlockHeight to correctly work after removal of tw…
Jouzo Jul 16, 2021
cee1964
Assert history length while filtering by token DFI'
Jouzo Jul 18, 2021
20c55e1
remove duplicate filter on txtype tests
Jouzo Jul 19, 2021
240b1f5
don't use lambda for top level function
Jouzo Jul 19, 2021
5972a11
fix missing space between function name and parenthesis
Jouzo Jul 19, 2021
e536f40
replace toBeTruthy() by toStrictEqual(true) and toBeFalsy() by toStri…
Jouzo Jul 21, 2021
5a3dd4a
improve code consistency
Jouzo Jul 21, 2021
1565440
Merge branch 'main' of https://github.com/DeFiCh/jellyfish into jouzo…
Jouzo Jul 22, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { BalanceTransferPayload, DfTxType } from '../../../src/category/account'
import { createToken, accountToAccount } from '@defichain/testing'

describe('Account', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)
const burnAddress = 'mfburnZSAM7Gs1hpDeNaMotJXSGA7edosG'
const burnAddressPrivateKey = '93ViFmLeJVgKSPxWGQHmSdT5RbeGDtGW4bsiwQM2qnQyucChMqQ'
let fundedAddress: string

beforeAll(async () => {
await container.start()
await container.waitForReady()
await container.waitForWalletCoinbaseMaturity()

await client.wallet.importPrivKey(burnAddressPrivateKey)
})

afterAll(async () => {
await container.stop()
})

it('should listBurnHistory after test masternode creation fee burn', async () => {
const newAddress = await container.getNewAddress('', 'legacy')
await client.masternode.createMasternode(newAddress)
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(1)
expect(history[0].owner.slice(0, 16)).toStrictEqual('6a1a446654784301')
expect(typeof history[0].blockHash).toStrictEqual('string')
expect(history[0].blockHash.length).toStrictEqual(64)
expect(history[0].type).toStrictEqual('CreateMasternode')
expect(history[0].txn).toStrictEqual(2)
expect(typeof history[0].txid).toStrictEqual('string')
expect(history[0].txid.length).toStrictEqual(64)
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('1.00000000@DFI')
})
Jouzo marked this conversation as resolved.
Show resolved Hide resolved

it('should listBurnHistory after burn token', async () => {
fundedAddress = await container.getNewAddress()
await client.wallet.sendToAddress(fundedAddress, 1)
await container.call('utxostoaccount', [{ [fundedAddress]: '3@0' }])
await container.generate(1)

await createToken(container, 'GOLD', { collateralAddress: fundedAddress })

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(2)
expect(history[0].owner).toStrictEqual('6a19446654785404474f4c4404474f4c4408000000000000000007')
expect(typeof history[0].blockHash).toStrictEqual('string')
expect(history[0].blockHash.length).toStrictEqual(64)
expect(history[0].type).toStrictEqual('CreateToken')
expect(history[0].txn).toStrictEqual(1)
expect(typeof history[0].txid).toStrictEqual('string')
expect(history[0].txid.length).toStrictEqual(64)
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('should listBurnHistory after mint token and send token to burn address', async () => {
await container.call('minttokens', ['100@GOLD'])
await container.generate(1)

await accountToAccount(container, 'GOLD', 100, {
from: fundedAddress, to: burnAddress
})
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(3)
expect(history[0].owner).toStrictEqual(burnAddress)
expect(history[0].type).toStrictEqual('AccountToAccount')
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('100.00000000@GOLD')
})

it('should listBurnHistory after utxostoaccount burn', async () => {
await container.call('utxostoaccount', [{ [burnAddress]: '1@0' }])
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(4)
expect(history[0].owner).toStrictEqual(burnAddress)
expect(history[0].type).toStrictEqual('UtxosToAccount')
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('should listBurnHistory after send to burn address with accountToAccount', async () => {
await accountToAccount(container, '0', 1, {
from: fundedAddress, to: burnAddress
})
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(5)
expect(history[0].owner).toStrictEqual(burnAddress)
expect(history[0].type).toStrictEqual('AccountToAccount')
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('should listBurnHistory after send to burn address with accounttoutxos', async () => {
const payload: BalanceTransferPayload = {}
payload[burnAddress] = '2@0'
await client.account.accountToUtxos(fundedAddress, payload)
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(6)
expect(history[0].owner).toStrictEqual(burnAddress)
expect(history[0].type).toStrictEqual('None')
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('2.00000000@DFI')
})

it('should listBurnHistory after send utxo to burn address', async () => {
await client.wallet.sendToAddress(burnAddress, 10)
await container.generate(1)

const history = await client.account.listBurnHistory()
expect(history.length).toStrictEqual(7)
expect(history[0].owner).toStrictEqual(burnAddress)
expect(history[0].type).toStrictEqual('None')
expect(typeof history[0].amounts).toStrictEqual('object')
expect(history[0].amounts.length).toStrictEqual(1)
expect(history[0].amounts[0]).toStrictEqual('10.00000000@DFI')
})

it('should listBurnHistory with filter on txtype None', async () => {
const history = await client.account.listBurnHistory({
txtype: DfTxType.NONE
})
expect(history.length).toStrictEqual(2)
expect(history.every(({ type }) => type === 'None')).toBeTruthy()
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
})

it('should listBurnHistory with filter on txtype UtxosToAccount', async () => {
const history = await client.account.listBurnHistory({
txtype: DfTxType.UTXOS_TO_ACCOUNT
})
expect(history.length).toStrictEqual(1)
expect(history.every(({ type }) => type === 'UtxosToAccount')).toBeTruthy()
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
})

it('should listBurnHistory with filter on txtype AccountToAccount', async () => {
const history = await client.account.listBurnHistory({
txtype: DfTxType.ACCOUNT_TO_ACCOUNT
})
expect(history.length).toStrictEqual(2)
expect(history.every(({ type }) => type === 'AccountToAccount')).toBeTruthy()
})

it('should listBurnHistory with filter on txtype CreateMasternode', async () => {
const history = await client.account.listBurnHistory({
txtype: DfTxType.CREATE_MASTERNODE
})
expect(history.length).toStrictEqual(1)
expect(history.every(({ type }) => type === 'CreateMasternode')).toBeTruthy()
})

it('should listBurnHistory with filter on txtype CreateToken', async () => {
const history = await client.account.listBurnHistory({
txtype: DfTxType.CREATE_TOKEN
})
expect(history.length).toStrictEqual(1)
expect(history.every(({ type }) => type === 'CreateToken')).toBeTruthy()
})

it('should listBurnHistory with filter on token DFI', async () => {
const history = await client.account.listBurnHistory({
token: 'DFI'
})
expect(history.length).toStrictEqual(6)
expect(history.every(({ amounts }) => amounts[0].includes('DFI'))).toBeTruthy()
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
})

it('should listBurnHistory with filter on token GOLD', async () => {
const history = await client.account.listBurnHistory({
token: 'GOLD'
})
expect(history.length).toStrictEqual(1)
expect(history.every(({ amounts }) => amounts[0].includes('GOLD'))).toBeTruthy()
})
})
41 changes: 40 additions & 1 deletion packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export enum DfTxType {
CREATE_POOL_PAIR = 'p',
UPDATE_POOL_PAIR = 'u',
SET_GOV_VARIABLE = 'G',
AUTO_AUTH_PREP = 'A'
AUTO_AUTH_PREP = 'A',
NONE = '0'
}

export enum SelectionModeType {
Expand Down Expand Up @@ -343,6 +344,25 @@ export class Account {
async listCommunityBalances (): Promise<CommunityBalanceData> {
return await this.client.call('listcommunitybalances', [], 'bignumber')
}

/**
* Returns information about burn history
*
* @param {BurnHistoryOptions} [options]
* @param {number} [options.maxBlockHeight] Optional height to iterate from (down to genesis block), (default = chaintip).
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
* @param {number} [options.depth] Maximum depth, from the genesis block is the default
* @param {string} [options.token] Filter by token
* @param {DfTxType} [options.txtype] Filter by transaction type. See DfTxType.
* @param {number} [options.limit=100] Maximum number of records to return, 100 by default
* @return {Promise<BurnHistory[]>}
*/
async listBurnHistory (
options: BurnHistoryOptions = {
limit: 100
}
): Promise<BurnHistory[]> {
return await this.client.call('listburnhistory', [options], 'number')
}
}

export interface AccountPagination {
Expand Down Expand Up @@ -438,3 +458,22 @@ export interface CommunityBalanceData {
Unallocated?: BigNumber
Unknown?: BigNumber
}

export interface BurnHistoryOptions {
maxBlockHeight?: number
depth?: number
token?: string
txtype?: DfTxType
limit?: number
}

export interface BurnHistory {
owner: string
blockHeight: number
blockHash: string
blockTime: number
type: string
txn: number
txid: string
amounts: string[]
}
58 changes: 56 additions & 2 deletions website/docs/jellyfish/api/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ enum DfTxType {
CREATE_POOL_PAIR = 'p',
UPDATE_POOL_PAIR = 'u',
SET_GOV_VARIABLE = 'G',
AUTO_AUTH_PREP = 'A'
AUTO_AUTH_PREP = 'A',
NONE = '0'
ivan-zynesis marked this conversation as resolved.
Show resolved Hide resolved
}

interface AccountHistory {
Expand Down Expand Up @@ -274,7 +275,8 @@ enum DfTxType {
CREATE_POOL_PAIR = 'p',
UPDATE_POOL_PAIR = 'u',
SET_GOV_VARIABLE = 'G',
AUTO_AUTH_PREP = 'A'
AUTO_AUTH_PREP = 'A',
NONE = '0'
}

interface AccountHistoryCountOptions {
Expand Down Expand Up @@ -334,3 +336,55 @@ interface CommunityBalanceData {
Unknown?: BigNumber
}
```

## listBurnHistory

Returns information about burn history

```ts title="client.account.listBurnHistory()"
interface account {
listBurnHistory(
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
options: BurnHistoryOptions = { limit: 100 }
): Promise<BurnHistory[]>
}

enum DfTxType {
MINT_TOKEN = 'M',
POOL_SWAP = 's',
ADD_POOL_LIQUIDITY = 'l',
REMOVE_POOL_LIQUIDITY = 'r',
UTXOS_TO_ACCOUNT = 'U',
ACCOUNT_TO_UTXOS = 'b',
ACCOUNT_TO_ACCOUNT = 'B',
ANY_ACCOUNTS_TO_ACCOUNTS = 'a',
CREATE_MASTERNODE = 'C',
RESIGN_MASTERNODE = 'R',
CREATE_TOKEN = 'T',
UPDATE_TOKEN = 'N',
UPDATE_TOKEN_ANY = 'n',
CREATE_POOL_PAIR = 'p',
UPDATE_POOL_PAIR = 'u',
SET_GOV_VARIABLE = 'G',
AUTO_AUTH_PREP = 'A',
NONE = '0'
}

interface BurnHistoryOptions {
maxBlockHeight?: number
depth?: number
token?: string
txtype?: DfTxType
limit?: number
}

interface BurnHistory {
owner: string
blockHeight: number
blockHash: string
blockTime: number
type: string
txn: number
txid: string
amounts: string[]
}
```