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

Add getConnectionCount rpc #176

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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> {
canonbrother marked this conversation as resolved.
Show resolved Hide resolved
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
canonbrother marked this conversation as resolved.
Show resolved Hide resolved
---

```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>
}
```