Skip to content

Commit

Permalink
Add new getMiningInfo for multiple masternode support
Browse files Browse the repository at this point in the history
  • Loading branch information
benzumbrunn committed May 16, 2021
1 parent 904edd3 commit f7f8553
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
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
}
35 changes: 35 additions & 0 deletions website/docs/jellyfish/api/mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,39 @@ interface MintingInfo {
chain: 'main' | 'test' | 'regtest' | string
warnings: string
}

```
## getMiningInfo

Get minting-related information.

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

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

0 comments on commit f7f8553

Please sign in to comment.