Add difficulty adjustment endpoints methods.
This commit is contained in:
parent
1c32b05abe
commit
caf8d956b5
@ -2,7 +2,7 @@ import mempoolJS from "@mempool/mempool.js";
|
||||
|
||||
const init = async () => {
|
||||
const { bitcoin } = mempoolJS({
|
||||
hostname:'mempool.ninja'
|
||||
hostname:'localhost:4200'
|
||||
});
|
||||
|
||||
const feesRecommended = await bitcoin.fees.getFeesRecommended();
|
||||
@ -10,8 +10,10 @@ const init = async () => {
|
||||
|
||||
const hash = "0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2";
|
||||
const block = await bitcoin.blocks.getBlockHeader({hash});
|
||||
|
||||
console.log(block);
|
||||
|
||||
const difficultyAdjustment = await bitcoin.difficulty.getDifficultyAdjustment();
|
||||
console.log(difficultyAdjustment);
|
||||
};
|
||||
|
||||
init();
|
16
src/app/bitcoin/difficulty.ts
Normal file
16
src/app/bitcoin/difficulty.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import {
|
||||
Adjustment,
|
||||
DifficultyInstance,
|
||||
} from '../../interfaces/bitcoin/difficulty';
|
||||
|
||||
export const useDifficulty = (api: AxiosInstance): DifficultyInstance => {
|
||||
const getDifficultyAdjustment = async () => {
|
||||
const { data } = await api.get<Adjustment>(`/difficulty-adjustment`);
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getDifficultyAdjustment,
|
||||
};
|
||||
};
|
@ -7,6 +7,7 @@ import {
|
||||
|
||||
import { useAddresses } from './app/bitcoin/addresses';
|
||||
import { useBlocks } from './app/bitcoin/blocks';
|
||||
import { useDifficulty } from './app/bitcoin/difficulty';
|
||||
import { useFees } from './app/bitcoin/fees';
|
||||
import { useMempool } from './app/bitcoin/mempool';
|
||||
import { useTransactions } from './app/bitcoin/transactions';
|
||||
@ -45,6 +46,7 @@ const mempool = (
|
||||
bitcoin: {
|
||||
addresses: useAddresses(apiBitcoin),
|
||||
blocks: useBlocks(apiBitcoin),
|
||||
difficulty: useDifficulty(apiBitcoin),
|
||||
fees: useFees(apiBitcoin),
|
||||
mempool: useMempool(apiBitcoin),
|
||||
transactions: useTransactions(apiBitcoin),
|
||||
|
13
src/interfaces/bitcoin/difficulty.ts
Normal file
13
src/interfaces/bitcoin/difficulty.ts
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
export interface Adjustment {
|
||||
progressPercent: number,
|
||||
difficultyChange: number,
|
||||
estimatedRetargetDate: number,
|
||||
remainingBlocks: number,
|
||||
remainingTime: number,
|
||||
previousRetarget: number,
|
||||
}
|
||||
|
||||
export interface DifficultyInstance {
|
||||
getDifficultyAdjustment: () => Promise<Adjustment>;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { AddressInstance } from './bitcoin/addresses';
|
||||
import { BlockInstance } from './bitcoin/blocks';
|
||||
import { DifficultyInstance } from './bitcoin/difficulty';
|
||||
import { FeeInstance } from './bitcoin/fees';
|
||||
import { MempoolInstance } from './bitcoin/mempool';
|
||||
import { TxInstance } from './bitcoin/transactions';
|
||||
@ -21,6 +22,7 @@ export interface MempoolReturn {
|
||||
bitcoin: {
|
||||
addresses: AddressInstance;
|
||||
blocks: BlockInstance;
|
||||
difficulty: DifficultyInstance;
|
||||
fees: FeeInstance;
|
||||
mempool: MempoolInstance;
|
||||
transactions: TxInstance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user