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

added estimateSmartFee rpc #254

Merged
merged 17 commits into from
May 20, 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
21 changes: 21 additions & 0 deletions packages/jellyfish-api-core/src/category/mining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ export class Mining {
async getMiningInfo (): Promise<MiningInfo> {
return await this.client.call('getmininginfo', [], 'number')
}

/**
*
* @param {number} confirmationTarget in blocks (1 - 1008)
* @param {EstimateMode} [estimateMode='CONSERVATIVE'] estimateMode of fees.
fuxingloh marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<SmartFeeEstimation>}
*/
async estimateSmartFee (confirmationTarget: number, estimateMode: EstimateMode = 'CONSERVATIVE'): Promise<SmartFeeEstimation> {
return await this.client.call('estimatesmartfee', [confirmationTarget, estimateMode], 'number')
}
}

export type EstimateMode = 'UNSET' | 'ECONOMICAL' | 'CONSERVATIVE'

/**
* Minting related information
*/
Expand Down Expand Up @@ -86,3 +98,12 @@ export interface MasternodeInfo {
mintedblocks?: number
lastblockcreationattempt?: string
}

/**
* @description return type of rpc `estimatesmartfee`
*/
fuxingloh marked this conversation as resolved.
Show resolved Hide resolved
export interface SmartFeeEstimation {
feerate?: number
errors?: string[]
blocks: number
}
18 changes: 18 additions & 0 deletions website/docs/jellyfish/api/mining.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,21 @@ interface MasternodeInfo {
lastblockcreationattempt?: string
}
```

## estimateSmartFee

Estimates the approximate fee per kilobyte needed for a transaction

```ts title="client.mining.estimateSmartFee()"
interface mining {
estimateSmartFee (confirmationTarget: number, estimateMode: EstimateMode = 'CONSERVATIVE'): Promise<SmartFeeEstimation>
fuxingloh marked this conversation as resolved.
Show resolved Hide resolved
}

interface SmartFeeEstimation {
feerate?: number
errors?: string[]
blocks: number
}

type EstimateMode = 'UNSET' | 'ECONOMICAL' | 'CONSERVATIVE';
```