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 new getMiningInfo for multiple masternode support #229

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions packages/jellyfish-api-core/__tests__/category/mining.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,34 @@ describe('masternode', () => {
expect(result).toBeGreaterThan(0)
})
})

it('should getMiningInfo', async () => {
await waitForExpect(async () => {
const info = await client.mining.getMiningInfo()
await expect(info.blocks).toBeGreaterThan(1)
})

const info = await client.mining.getMiningInfo()
const mn1 = info.masternodes[0]

expect(info.blocks).toBeGreaterThan(0)

expect(info.currentblockweight).toBeGreaterThan(0)
expect(info.currentblocktx).toBe(0)

expect(info.difficulty).toBeDefined()
expect(info.isoperator).toBe(true)

expect(mn1.masternodeid).toBeDefined()
expect(mn1.masternodeoperator).toBeDefined()
expect(mn1.masternodestate).toBe('ENABLED')
expect(mn1.generate).toBe(true)
expect(mn1.mintedblocks).toBe(0)
expect(mn1.lastblockcreationattempt).toBe('0')

expect(info.networkhashps).toBeGreaterThan(0)
expect(info.pooledtx).toBe(0)
expect(info.chain).toBe('regtest')
expect(info.warnings).toBe('')
})
})
37 changes: 37 additions & 0 deletions packages/jellyfish-api-core/src/category/mining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@ export class Mining {
/**
* Get minting-related information
* @return {Promise<MintingInfo>}
* @deprecated Prefer using getMiningInfo.
*/
async getMintingInfo (): Promise<MintingInfo> {
return await this.client.call('getmintinginfo', [], 'number')
}

/**
* Get mining-related information, replaces deprecated getMintingInfo
* @return {Promise<MiningInfo>}
*/
async getMiningInfo (): Promise<MiningInfo> {
return await this.client.call('getmininginfo', [], 'number')
}
}

/**
Expand All @@ -49,3 +58,31 @@ export interface MintingInfo {
chain: 'main' | 'test' | 'regtest' | string
warnings: string
}

/**
* Minting related information
*/
export interface MiningInfo {
blocks: number
currentblockweight?: number
currentblocktx?: number
difficulty: string
isoperator: boolean
masternodes: MasternodeInfo[]
networkhashps: number
pooledtx: number
chain: 'main' | 'test' | 'regtest' | string
warnings: string
}

/**
* Masternode related information
*/
export interface MasternodeInfo {
masternodeid?: string
masternodeoperator?: string
masternodestate?: 'PRE_ENABLED' | 'ENABLED' | 'PRE_RESIGNED' | 'RESIGNED' | 'PRE_BANNED' | 'BANNED'
generate?: boolean
mintedblocks?: number
lastblockcreationattempt?: string
}
40 changes: 39 additions & 1 deletion website/docs/jellyfish/api/mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ interface mining {

## getMintingInfo

Get minting-related information.
Get minting-related information. Deprecated in favour of `mining.getMiningInfo()`.

```ts title="client.mining.getMintingInfo()"
interface mining {
/**
* @deprecated prefer getMiningInfo for multiple masternode support.
*/
getMintingInfo (): Promise<MintingInfo>
}

Expand All @@ -53,3 +56,38 @@ interface MintingInfo {
warnings: string
}
```

## getMiningInfo

Get minting-related information.

```ts title="client.mining.getMiningInfo()"
interface mining {
getMiningInfo (): Promise<MiningInfo>
}

interface MiningInfo {
blocks: number
currentblockweight?: number
currentblocktx?: number
difficulty: string
isoperator: boolean
masternodes: MasternodeInfo[],
networkhashps: number
pooledtx: number
chain: 'main' | 'test' | 'regtest' | string
warnings: string
}

/**
* Masternode related information
*/
interface MasternodeInfo {
masternodeid?: string
masternodeoperator?: string
masternodestate?: 'PRE_ENABLED' | 'ENABLED' | 'PRE_RESIGNED' | 'RESIGNED' | 'PRE_BANNED' | 'BANNED'
generate?: boolean
mintedblocks?: number
lastblockcreationattempt?: string
}
```