Skip to content

Commit

Permalink
feat(jellyfish-api-core): add blockchain getTxOutSetInfo RPC (#1775)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:
/kind feature

#### Which issue(s) does this PR fixes?:
<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->
Fixes part of #48 
- Implements `gettxoutsetinfo` type for RPC.
  • Loading branch information
infinia-yzl authored Sep 27, 2022
1 parent 9e80daa commit 1761d40
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
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.waitForBlockHeight(1)
})

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

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

expect(txOutSetInfo).toStrictEqual({
height: 2,
bestblock: expect.any(String),
transactions: expect.any(Number),
txouts: expect.any(Number),
bogosize: expect.any(Number),
hash_serialized_2: expect.any(String),
disk_size: expect.any(Number),
total_amount: expect.any(BigNumber)
})
})
})
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

0 comments on commit 1761d40

Please sign in to comment.