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 9 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,207 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { BalanceTransferPayload, DfTxType, BurnHistory } 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
let history: BurnHistory[]

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

await client.wallet.importPrivKey(burnAddressPrivateKey)

await createHistory()

history = await client.account.listBurnHistory()
// reverse history to test correct order of transaction
history.reverse()
})

const createHistory = async (): Promise<void> => {
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
// test masternode creation fee burn
const newAddress = await container.getNewAddress('', 'legacy')
await client.masternode.createMasternode(newAddress)
await container.generate(1)

// creates funded account address
fundedAddress = await container.getNewAddress()
await client.wallet.sendToAddress(fundedAddress, 1)
await container.call('utxostoaccount', [{ [fundedAddress]: '3@0' }])
await container.generate(1)

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

// mint token and send token to burn address
await container.call('minttokens', ['100@GOLD'])
await container.generate(1)

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

// utxostoaccount burn
await container.call('utxostoaccount', [{ [burnAddress]: '1@0' }])
await container.generate(1)

// send to burn address with accountToAccount
await accountToAccount(container, '0', 1, {
from: fundedAddress, to: burnAddress
})
await container.generate(1)

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

// send utxo to burn address
await client.wallet.sendToAddress(burnAddress, 10)
await container.generate(1)
}

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

it('should listBurnHistory', async () => {
expect(history.length).toStrictEqual(7)
for (let i = 0; i < history.length; i += 1) {
const burnHistory = history[i]
expect(typeof burnHistory.owner).toStrictEqual('string')
expect(typeof burnHistory.blockHeight).toStrictEqual('number')
expect(typeof burnHistory.blockHash).toStrictEqual('string')
expect(typeof burnHistory.blockTime).toStrictEqual('number')
expect(typeof burnHistory.type).toStrictEqual('string')
expect(typeof burnHistory.txn).toStrictEqual('number')
expect(typeof burnHistory.txid).toStrictEqual('string')
expect(burnHistory.amounts.length).toBeGreaterThan(0)
expect(typeof burnHistory.amounts[0]).toStrictEqual('string')
}
})
Jouzo marked this conversation as resolved.
Show resolved Hide resolved

it('first transaction should be masternode creation fee burn', async () => {
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')
})

it('second transaction should be after burn token', async () => {
expect(history[1].owner).toStrictEqual('6a19446654785404474f4c4404474f4c4408000000000000000007')
expect(typeof history[1].blockHash).toStrictEqual('string')
expect(history[1].blockHash.length).toStrictEqual(64)
expect(history[1].type).toStrictEqual('CreateToken')
expect(history[1].txn).toStrictEqual(1)
expect(typeof history[1].txid).toStrictEqual('string')
expect(history[1].txid.length).toStrictEqual(64)
expect(typeof history[1].amounts).toStrictEqual('object')
expect(history[1].amounts.length).toStrictEqual(1)
expect(history[1].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('third transaction should be send token to burn address', async () => {
expect(history[2].owner).toStrictEqual(burnAddress)
expect(history[2].type).toStrictEqual('AccountToAccount')
expect(typeof history[2].amounts).toStrictEqual('object')
expect(history[2].amounts.length).toStrictEqual(1)
expect(history[2].amounts[0]).toStrictEqual('100.00000000@GOLD')
})

it('fourth transaction should be utxostoaccount burn', async () => {
expect(history[3].owner).toStrictEqual(burnAddress)
expect(history[3].type).toStrictEqual('UtxosToAccount')
expect(typeof history[3].amounts).toStrictEqual('object')
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
expect(history[3].amounts.length).toStrictEqual(1)
expect(history[3].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('fifth transaction should be send to burn address with accountToAccount', async () => {
expect(history[4].owner).toStrictEqual(burnAddress)
expect(history[4].type).toStrictEqual('AccountToAccount')
expect(typeof history[4].amounts).toStrictEqual('object')
expect(history[4].amounts.length).toStrictEqual(1)
expect(history[4].amounts[0]).toStrictEqual('1.00000000@DFI')
})

it('sixth transaction should be send to burn address with accounttoutxos', async () => {
expect(history[5].owner).toStrictEqual(burnAddress)
expect(history[5].type).toStrictEqual('None')
expect(typeof history[5].amounts).toStrictEqual('object')
expect(history[5].amounts.length).toStrictEqual(1)
expect(history[5].amounts[0]).toStrictEqual('2.00000000@DFI')
})

it('last transaction should be send utxo to burn address', async () => {
expect(history[6].owner).toStrictEqual(burnAddress)
expect(history[6].type).toStrictEqual('None')
expect(typeof history[6].amounts).toStrictEqual('object')
expect(history[6].amounts.length).toStrictEqual(1)
expect(history[6].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.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.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.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.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.every(({ type }) => type === 'CreateToken')).toBeTruthy()
})

it('should listBurnHistory with filter on token DFI', async () => {
const history = await client.account.listBurnHistory({
token: 'DFI'
})
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.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] The block height to iterate from.
* @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
Jouzo marked this conversation as resolved.
Show resolved Hide resolved
* @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[]
}
```