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 getNodeAddress RPC #1872

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { TestingGroup } from '@defichain/jellyfish-testing'
import { ContainerAdapterClient } from '../../container_adapter_client'

describe('Network on masternode', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)
const group = TestingGroup.create(2)

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

afterAll(async () => {
await container.stop()
await group.stop()
})
shohamc1 marked this conversation as resolved.
Show resolved Hide resolved

it('should get something in the array', async () => {
const address = await container.getNewAddress()
await container.addNode(address)

const info = await client.net.getNodeAddresses(1)
console.log(info)
shohamc1 marked this conversation as resolved.
Show resolved Hide resolved
})
})
16 changes: 16 additions & 0 deletions packages/jellyfish-api-core/src/category/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export class Net {
async setNetworkActive (state: boolean): Promise<boolean> {
return await this.client.call('setnetworkactive', [state], 'number')
}

/**
* Return known addresses which can potentially be used to find new nodes in the network.
*
* @return {Promise<AddressesInfo[]>}
*/
async getNodeAddresses (count: number): Promise<AddressInfo[]> {
return await this.client.call('getnodeaddresses', [count], 'number')
}
}

export interface PeerInfo {
Expand Down Expand Up @@ -109,6 +118,13 @@ export interface NetworkInfo {
warnings: string
}

export interface AddressInfo {
time: number
services: number
address: string
port: number
}

export interface Network {
name: string
limited: boolean
Expand Down