Skip to content

Commit

Permalink
Add getConnectionCount rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyi2811 committed Apr 30, 2021
1 parent 79309a8 commit 49bfd8b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/jellyfish-api-core/__tests__/category/net.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { RegTestContainer, MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../container_adapter_client'

describe('non masternode', () => {
const container = new RegTestContainer()
const client = new ContainerAdapterClient(container)

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

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

it('should getConnectionCount', async () => {
const count = await client.net.getConnectionCount()
expect(count).toBeGreaterThanOrEqual(0)
})
})

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

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

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

it('should getConnectionCount', async () => {
const count = await client.net.getConnectionCount()
expect(count).toBeGreaterThanOrEqual(0)
})
})
21 changes: 21 additions & 0 deletions packages/jellyfish-api-core/src/category/net.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiClient } from '../.'

/**
* Net RPCs for DeFi Blockchain
*/
export class Net {
private readonly client: ApiClient

constructor (client: ApiClient) {
this.client = client
}

/**
* Returns the number of connections to other nodes.
*
* @return {Promise<string>}
*/
async getConnectionCount (): Promise<string> {
return await this.client.call('getconnectioncount', [], 'number')
}
}
3 changes: 3 additions & 0 deletions packages/jellyfish-api-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Precision, PrecisionPath } from '@defichain/jellyfish-json'
import { Blockchain } from './category/blockchain'
import { Mining } from './category/mining'
import { Net } from './category/net'
import { RawTx } from './category/rawtx'
import { Wallet } from './category/wallet'
import { PoolPair } from './category/poolpair'
Expand All @@ -10,6 +11,7 @@ export * from '@defichain/jellyfish-json'

export * as blockchain from './category/blockchain'
export * as mining from './category/mining'
export * as net from './category/net'
export * as rawtx from './category/rawtx'
export * as wallet from './category/wallet'
export * as poolpair from './category/poolpair'
Expand All @@ -21,6 +23,7 @@ export * as token from './category/token'
export abstract class ApiClient {
public readonly blockchain = new Blockchain(this)
public readonly mining = new Mining(this)
public readonly net = new Net(this)
public readonly rawtx = new RawTx(this)
public readonly wallet = new Wallet(this)
public readonly poolpair = new PoolPair(this)
Expand Down
24 changes: 24 additions & 0 deletions website/docs/jellyfish/api/net.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
id: net
title: Net API
sidebar_label: Net API
slug: /jellyfish/api/net
---

```js
import {Client} from '@defichain/jellyfish'
const client = new Client()

// Using client.net.
const something = await client.net.method()
```

## getConnectionCount

Returns the number of connections to other nodes.

```ts title="client.net.getConnectionCount()"
interface net {
getConnectionCount (): Promise<string>
}
```

0 comments on commit 49bfd8b

Please sign in to comment.