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 blockchain getTxOutSetInfo RPC #1775

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions docs/node/CATEGORIES/01-blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,28 @@ interface ScriptPubKey {
}
```

## getTxOutSetInfo

Returns statistics about the unspent transaction output set.
Note this call may take some time.

```ts title="client.blockchain.getTxOutSetInfo()"
interface blockchain {
getTxOutSetInfo (): Promise<TxOutSetInfo>
}

interface TxOutSetInfo {
height: number
bestblock: string
transactions: Number
txouts: Number
bogosize: Number
hash_serialized_2: string
disk_size: Number
total_amount: BigNumber
}
```

## getRawMempool

Get all transaction ids in memory pool as string[] if verbose is false else as json object
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import BigNumber from 'bignumber.js'

describe('TxOutSetInfo', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.generate(1)
infinia-yzl marked this conversation as resolved.
Show resolved Hide resolved
})

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

it('should getTxOutSetInfo', async () => {
const txOutSetInfo = await client.blockchain.getTxOutSetInfo()

expect(txOutSetInfo).toStrictEqual({
height: 1,
bestblock: expect.any(String),
transactions: 10,
txouts: 15,
bogosize: 1117,
hash_serialized_2: expect.any(String),
disk_size: 0,
total_amount: new BigNumber(400000259.8)
})
infinia-yzl marked this conversation as resolved.
Show resolved Hide resolved
})
})
23 changes: 23 additions & 0 deletions packages/jellyfish-api-core/src/category/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ export class Blockchain {
})
}

/**
* Returns statistics about the unspent transaction output set.
* Note this call may take some time.
*
* @return {Promise<TxOutSetInfo>}
*/
async getTxOutSetInfo (): Promise<TxOutSetInfo> {
return await this.client.call('gettxoutsetinfo', [], {
total_amount: 'bignumber'
})
}

/**
* Get all transaction ids in memory pool as string
*
Expand Down Expand Up @@ -343,6 +355,17 @@ export interface UTXODetails {
coinbase: boolean
}

export interface TxOutSetInfo {
height: number
bestblock: string
transactions: Number
txouts: Number
bogosize: Number
hash_serialized_2: string
disk_size: Number
total_amount: BigNumber
}

export interface ScriptPubKey {
asm: string
hex: string
Expand Down