Add getBlockHeader method.
This commit is contained in:
parent
f244ad191e
commit
47fa100786
17
examples/nodejs/index.ts
Normal file
17
examples/nodejs/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import mempoolJS from "@mempool/mempool.js";
|
||||
|
||||
const init = async () => {
|
||||
const { bitcoin } = mempoolJS({
|
||||
hostname:'mempool.ninja'
|
||||
});
|
||||
|
||||
const feesRecommended = await bitcoin.fees.getFeesRecommended();
|
||||
console.log(feesRecommended);
|
||||
|
||||
const hash = "0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2";
|
||||
const block = await bitcoin.blocks.getBlockHeader({hash});
|
||||
|
||||
console.log(block);
|
||||
};
|
||||
|
||||
init();
|
10644
package-lock.json
generated
Normal file
10644
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -31,8 +31,9 @@
|
||||
"scripts": {
|
||||
"start": "ts-node src/index.ts",
|
||||
"dev": "nodemon src/index.ts",
|
||||
"examples-nodemon": "nodemon --watch 'examples/nodejs/**' --ext 'ts,json' --ignore 'src/**/*.spec.ts' --exec 'ts-node examples/nodejs/index.ts'",
|
||||
"build": "tsc",
|
||||
"build-js": "tsc | browserify lib/index.js --standalone mempoolJS > dist/mempool.js | browserify -p tinyify lib/index.js --standalone mempoolJS > dist/mempool.min.js",
|
||||
"export-js": "tsc | browserify lib/index.js --standalone mempoolJS > dist/mempool.js | browserify -p tinyify lib/index.js --standalone mempoolJS > dist/mempool.min.js",
|
||||
"prepare": "npm run build",
|
||||
"postversion": "git push && git push --tags"
|
||||
},
|
||||
|
@ -44,6 +44,11 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockHeader = async (params: { hash: string }) => {
|
||||
const { data } = await api.get<string>(`/block/${params.hash}/header`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockHeight = async (params: { height: number }) => {
|
||||
const { data } = await api.get<string>(`/block-height/${params.height}`);
|
||||
return data;
|
||||
@ -72,6 +77,7 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
|
||||
getBlockTxid,
|
||||
getBlockTxids,
|
||||
getBlockRaw,
|
||||
getBlockHeader,
|
||||
getBlockHeight,
|
||||
getBlocksTipHash,
|
||||
getBlocksTipHeight,
|
||||
|
@ -2,11 +2,11 @@ import { AxiosInstance } from 'axios';
|
||||
import {
|
||||
Block,
|
||||
BlockStatus,
|
||||
BlockInstance,
|
||||
} from '../../interfaces/bitcoin/blocks';
|
||||
BlockLiquidInstance,
|
||||
} from '../../interfaces/liquid/block';
|
||||
import { Tx } from '../../interfaces/bitcoin/transactions';
|
||||
|
||||
export const useBlocks = (api: AxiosInstance): BlockInstance => {
|
||||
export const useBlocks = (api: AxiosInstance): BlockLiquidInstance => {
|
||||
const getBlock = async (params: { hash: string }) => {
|
||||
const { data } = await api.get<Block>(`/block/${params.hash}`);
|
||||
return data;
|
||||
|
@ -30,6 +30,7 @@ export interface BlockInstance {
|
||||
getBlockTxids: (params: { hash: string }) => Promise<string[]>;
|
||||
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
|
||||
getBlockRaw: (params: { hash: string }) => Promise<string>;
|
||||
getBlockHeader: (params: { hash: string }) => Promise<string>;
|
||||
getBlockHeight: (params: { height: number }) => Promise<string>;
|
||||
getBlocksTipHeight: () => Promise<number>;
|
||||
getBlocksTipHash: () => Promise<string>;
|
||||
|
@ -11,7 +11,7 @@ import { StatsInstance } from './bisq/statistics';
|
||||
import { TransactionsInstance } from './bisq/transactions';
|
||||
|
||||
import { AssetsInstance } from './liquid/assets';
|
||||
|
||||
import { BlockLiquidInstance } from './liquid/block';
|
||||
export interface MempoolConfig {
|
||||
hostname?: string;
|
||||
network?: string;
|
||||
@ -35,7 +35,7 @@ export interface MempoolReturn {
|
||||
liquid: {
|
||||
assets: AssetsInstance;
|
||||
addresses: AddressInstance;
|
||||
blocks: BlockInstance;
|
||||
blocks: BlockLiquidInstance;
|
||||
fees: FeeInstance;
|
||||
mempool: MempoolInstance;
|
||||
transactions: TxInstance;
|
||||
|
36
src/interfaces/liquid/block.ts
Normal file
36
src/interfaces/liquid/block.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Tx } from '../bitcoin/transactions';
|
||||
|
||||
export interface Block {
|
||||
id: string;
|
||||
height: number;
|
||||
version: number;
|
||||
timestamp: number;
|
||||
tx_count: number;
|
||||
size: number;
|
||||
weight: number;
|
||||
merkle_root: string;
|
||||
previousblockhash: string;
|
||||
mediantime: number;
|
||||
nonce: number;
|
||||
bits: number;
|
||||
difficulty: number;
|
||||
}
|
||||
|
||||
export interface BlockStatus {
|
||||
in_best_chain: boolean;
|
||||
height: number;
|
||||
next_best: string;
|
||||
}
|
||||
|
||||
export interface BlockLiquidInstance {
|
||||
getBlock: (params: { hash: string }) => Promise<Block>;
|
||||
getBlocks: (params: { start_height?: number }) => Promise<Block>;
|
||||
getBlockStatus: (params: { hash: string }) => Promise<BlockStatus>;
|
||||
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
|
||||
getBlockTxids: (params: { hash: string }) => Promise<string[]>;
|
||||
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
|
||||
getBlockRaw: (params: { hash: string }) => Promise<string>;
|
||||
getBlockHeight: (params: { height: number }) => Promise<string>;
|
||||
getBlocksTipHeight: () => Promise<number>;
|
||||
getBlocksTipHash: () => Promise<string>;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user