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 blockchain.getDifficulty RPC #285

Merged
merged 3 commits into from
May 25, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ describe('masternode', () => {
})
})

describe('getdifficulty', () => {
it('should getDifficulty', async () => {
const difficulty = await client.blockchain.getDifficulty()
expect(difficulty).toBeGreaterThanOrEqual(0)
})
})

describe('getRawMempool', () => {
beforeAll(async () => {
await client.wallet.setWalletFlag(wallet.WalletFlag.AVOID_REUSE)
Expand Down
9 changes: 9 additions & 0 deletions packages/jellyfish-api-core/src/category/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ export class Blockchain {
return await this.client.call('getchaintips', [], 'number')
}

/**
* Get the proof-of-work difficulty as a multiple of the minimum difficulty.
*
* @return {Promise<number>}
*/
async getDifficulty (): Promise<number> {
return await this.client.call('getdifficulty', [], 'number')
}

/**
* Get details of unspent transaction output (UTXO).
*
Expand Down
10 changes: 10 additions & 0 deletions website/docs/jellyfish/api/blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ interface ChainTip {
}
```

## getDifficulty

Return the proof-of-work difficulty as a multiple of the minimum difficulty.

```ts tile="client.blockchain.getDifficulty()"
interface blockchain {
getDifficulty (): Promise<number>
}
```

## getTxOut

Get details of unspent transaction output (UTXO).
Expand Down