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 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
Expand Up @@ -249,6 +249,27 @@ describe('masternode', () => {
})
})

// getDifficulty of masternode & non masternode
izzycsy marked this conversation as resolved.
Show resolved Hide resolved
describe('getdifficulty', () => {
// const container = new DifficultyRegTest()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForReady()
// await container.waitForWalletCoinbaseMaturity()
})

afterAll(async () => {
await container.stop()
})

izzycsy marked this conversation as resolved.
Show resolved Hide resolved
it('should getDifficulty', async () => {
const getdifficulty = await client.blockchain.getDifficulty()
expect(getdifficulty).toBeGreaterThanOrEqual(0)
izzycsy marked this conversation as resolved.
Show resolved Hide resolved
})
})

describe('getRawMempool', () => {
beforeAll(async () => {
await client.wallet.setWalletFlag(wallet.WalletFlag.AVOID_REUSE)
Expand Down
8 changes: 8 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,14 @@ export class Blockchain {
return await this.client.call('getchaintips', [], 'number')
}

/**
* Get difficulty of everything.
* Return difficulty as number.
*/
izzycsy marked this conversation as resolved.
Show resolved Hide resolved
async getDifficulty (): Promise<number> {
return await this.client.call('getdifficulty', [], 'number')
}

/**
* Get details of unspent transaction output (UTXO).
*
Expand Down
8 changes: 8 additions & 0 deletions website/docs/jellyfish/api/blockchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ interface ChainTip {
status: string
}
```
## getDifficulty
Return the proof-of-work difficulty as a multiple of the minimum difficulty.
```ts tile="client.blockchain.getDifficulty()"
interface difficulty {
getDifficulty (): Promise<number>
}
```

izzycsy marked this conversation as resolved.
Show resolved Hide resolved

## getTxOut

Expand Down