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 getBurnInfo RPC #540

Merged
merged 2 commits into from
Aug 2, 2021
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
6 changes: 5 additions & 1 deletion .idea/dictionaries/fuxing.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import BigNumber from 'bignumber.js'
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { createToken } from '@defichain/testing'
import { ContainerAdapterClient } from '../../container_adapter_client'

const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)
const burnAddress = 'mfburnZSAM7Gs1hpDeNaMotJXSGA7edosG'

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

// Masternode
await client.masternode.createMasternode(await container.getNewAddress('', 'legacy'))
await container.generate(1)

// burn gold token
const fundedAddress = await container.getNewAddress()
await createToken(container, 'GOLD', { collateralAddress: fundedAddress })
await client.token.mintTokens('100@GOLD')
await container.generate(1)
await client.account.sendTokensToAddress({}, { [burnAddress]: ['50@GOLD'] })

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

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

it('should getBurnInfo', async () => {
const info = await client.account.getBurnInfo()

expect(info).toStrictEqual({
address: burnAddress,
amount: new BigNumber('10'),
tokens: ['50.00000000@GOLD'],
feeburn: new BigNumber('2'),
emissionburn: new BigNumber('6274')
})
})
30 changes: 30 additions & 0 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,16 @@ export class Account {
): Promise<BurnHistory[]> {
return await this.client.call('listburnhistory', [options], 'number')
}

/**
* Returns burn address and burnt coin and token information.
* Requires full acindex for correct amount, tokens and feeburn values.
*
* @return {Promise<BurnInfo>}
*/
async getBurnInfo (): Promise<BurnInfo> {
return await this.client.call('getburninfo', [], 'bignumber')
}
}

export interface AccountPagination {
Expand Down Expand Up @@ -477,3 +487,23 @@ export interface BurnHistory {
txid: string
amounts: string[]
}

export interface BurnInfo {
address: string
/**
* Amount send to burn address
*/
amount: BigNumber
/**
* Token amount send to burn address
*/
tokens: Array<{ name: string, amount: BigNumber }>
/**
* Amount collected via fee burn
*/
feeburn: BigNumber
/**
* Amount collected via emission burn
*/
emissionburn: BigNumber
}
31 changes: 31 additions & 0 deletions website/docs/jellyfish/api/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,34 @@ interface BurnHistory {
amounts: string[]
}
```

## getBurnInfo

Returns burn address and burnt coin and token information.
Requires full acindex for correct amount, tokens and feeburn values.

```ts title="client.account.getBurnInfo()"
interface account {
getBurnInfo (): Promise<BurnInfo>
}

export interface BurnInfo {
address: string
/**
* Amount send to burn address
*/
amount: BigNumber
/**
* Token amount send to burn address
*/
tokens: Array<{ name: string, amount: BigNumber }>
/**
* Amount collected via fee burn
*/
feeburn: BigNumber
/**
* Amount collected via emission burn
*/
emissionburn: BigNumber
}
```