* FIX: getBlocks optional params

* v2.3.0 - new minor version for mempool-js
- Add support for Bisq API
- Add support for Liquid API
- Change the main object to export network objects.
- Change README.md instructions.

Co-authored-by: softsimon <softsimon@users.noreply.github.com>
This commit is contained in:
Miguel Medeiros
2021-04-14 17:27:28 -03:00
committed by GitHub
parent 70d31f2062
commit c80f82a0b1
78 changed files with 3394 additions and 1160 deletions

View File

@@ -1,39 +0,0 @@
import { AxiosInstance } from 'axios';
import { Address, AddressTxsUtxo, Tx, AddressInstance } from '../interfaces';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (address: string) => {
const { data } = await api.get<Address>(`/address/${address}`);
return data;
};
const getAddressTxs = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs`);
return data;
};
const getAddressTxsChain = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs/chain`);
return data;
};
const getAddressTxsMempool = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs/mempool`);
return data;
};
const getAddressTxsUtxo = async (address: string) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

13
src/app/bisq/addresses.ts Normal file
View File

@@ -0,0 +1,13 @@
import { AxiosInstance } from 'axios';
import { Address, AddressesInstance } from '../../interfaces/bisq/addresses';
export const useAddresses = (api: AxiosInstance): AddressesInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/block/${params.address}`);
return data;
};
return {
getAddress,
};
};

27
src/app/bisq/blocks.ts Normal file
View File

@@ -0,0 +1,27 @@
import { AxiosInstance } from 'axios';
import { Block, BlocksInstance } from '../../interfaces/bisq/blocks';
export const useBlocks = (api: AxiosInstance): BlocksInstance => {
const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${params.hash}`);
return data;
};
const getBlocks = async (params: { index: number; length: number }) => {
const { data } = await api.get<Block>(
`/blocks/${params.index}/${params.length}`
);
return data;
};
const getBlocksTipHeight = async () => {
const { data } = await api.get<number>(`/blocks/tip/height`);
return data;
};
return {
getBlock,
getBlocks,
getBlocksTipHeight,
};
};

View File

@@ -0,0 +1,13 @@
import { AxiosInstance } from 'axios';
import { Stats, StatsInstance } from '../../interfaces/bisq/statistics';
export const useStatistics = (api: AxiosInstance): StatsInstance => {
const getStats = async () => {
const { data } = await api.get<Stats>(`/stats`);
return data;
};
return {
getStats,
};
};

View File

@@ -0,0 +1,21 @@
import { AxiosInstance } from 'axios';
import { Tx, TransactionsInstance } from '../../interfaces/bisq/transactions';
export const useTransactions = (api: AxiosInstance): TransactionsInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxs = async (params: { index: number; length: number }) => {
const { data } = await api.get<Tx[]>(
`/txs/${params.index}/${params.length}`
);
return data;
};
return {
getTx,
getTxs,
};
};

View File

@@ -0,0 +1,48 @@
import { AxiosInstance } from 'axios';
import {
Address,
AddressTxsUtxo,
AddressInstance,
} from '../../interfaces/bitcoin/addresses';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/address/${params.address}`);
return data;
};
const getAddressTxs = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data;
};
const getAddressTxsChain = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/chain`
);
return data;
};
const getAddressTxsMempool = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/mempool`
);
return data;
};
const getAddressTxsUtxo = async (params: { address: string }) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${params.address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

View File

@@ -1,14 +1,19 @@
import { AxiosInstance } from 'axios';
import { Block, BlockStatus, BlockInstance, Tx } from '../interfaces';
import {
Block,
BlockStatus,
BlockInstance,
} from '../../interfaces/bitcoin/blocks';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (hash: string) => {
const { data } = await api.get<Block>(`/block/${hash}`);
const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${params.hash}`);
return data;
};
const getBlockStatus = async (hash: string) => {
const { data } = await api.get<BlockStatus>(`/block/${hash}/status`);
const getBlockStatus = async (params: { hash: string }) => {
const { data } = await api.get<BlockStatus>(`/block/${params.hash}/status`);
return data;
};
@@ -22,8 +27,8 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
return data;
};
const getBlockTxids = async (hash: string) => {
const { data } = await api.get<string[]>(`/block/${hash}/txids`);
const getBlockTxids = async (params: { hash: string }) => {
const { data } = await api.get<string[]>(`/block/${params.hash}/txids`);
return data;
};
@@ -34,13 +39,13 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
return data;
};
const getBlockRaw = async (hash: string) => {
const { data } = await api.get<string>(`/block/${hash}/raw`);
const getBlockRaw = async (params: { hash: string }) => {
const { data } = await api.get<string>(`/block/${params.hash}/raw`);
return data;
};
const getBlockHeight = async (height: number) => {
const { data } = await api.get<string>(`/block-height/${height}`);
const getBlockHeight = async (params: { height: number }) => {
const { data } = await api.get<string>(`/block-height/${params.height}`);
return data;
};

View File

@@ -1,5 +1,9 @@
import { AxiosInstance } from 'axios';
import { FeesRecommended, FeesMempoolBlocks, FeeInstance } from '../interfaces';
import {
FeesRecommended,
FeesMempoolBlocks,
FeeInstance,
} from '../../interfaces/bitcoin/fees';
export const useFees = (api: AxiosInstance): FeeInstance => {
const getFeesRecommended = async () => {
@@ -14,8 +18,16 @@ export const useFees = (api: AxiosInstance): FeeInstance => {
return data;
};
const getCPFP = async (params: { txid: string }) => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/cpfp/${params.txid}`
);
return data;
};
return {
getFeesRecommended,
getFeesMempoolBlocks,
getCPFP,
};
};

View File

@@ -1,5 +1,9 @@
import { AxiosInstance } from 'axios';
import { Mempool, MempoolRecent, MempoolInstance } from '../interfaces';
import {
Mempool,
MempoolRecent,
MempoolInstance,
} from '../../interfaces/bitcoin/mempool';
export const useMempool = (api: AxiosInstance): MempoolInstance => {
const getMempool = async () => {

View File

@@ -0,0 +1,75 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../../interfaces/bitcoin/transactions';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxStatus = async (params: { txid: string }) => {
const { data } = await api.get<TxStatus>(`/tx/${params.txid}/status`);
return data;
};
const getTxHex = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/hex`);
return data;
};
const getTxRaw = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (params: { txid: string }) => {
const { data } = await api.get<string>(
`/tx/${params.txid}/merkleblock-proof`
);
return data;
};
const getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxOutspend>>(
`/tx/${params.txid}/outspends`
);
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -0,0 +1,14 @@
import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import wsClient from '../../services/ws/client';
import wsServer from '../../services/ws/server';
const defaultWs = 'wss://mempool.space/api/v1/ws';
export const useWebsocket = (hostname?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, hostname),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, hostname),
};
};

View File

@@ -0,0 +1,48 @@
import { AxiosInstance } from 'axios';
import {
Address,
AddressTxsUtxo,
AddressInstance,
} from '../../interfaces/bitcoin/addresses';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/address/${params.address}`);
return data;
};
const getAddressTxs = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data;
};
const getAddressTxsChain = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/chain`
);
return data;
};
const getAddressTxsMempool = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/mempool`
);
return data;
};
const getAddressTxsUtxo = async (params: { address: string }) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${params.address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

37
src/app/liquid/assets.ts Normal file
View File

@@ -0,0 +1,37 @@
import { AxiosInstance } from 'axios';
import { Asset, AssetsInstance } from '../../interfaces/liquid/assets';
export const useAssets = (api: AxiosInstance): AssetsInstance => {
const getAsset = async (params: { asset_id: string }) => {
const { data } = await api.get<Asset>(`/asset/${params.asset_id}`);
return data;
};
const getAssetTxs = async (params: {
asset_id: string;
is_mempool: boolean;
}) => {
const paramsMempools = params.is_mempool === true ? '/mempool' : '/chain';
const { data } = await api.get<Asset>(
`/asset/${params.asset_id}/txs${paramsMempools}`
);
return data;
};
const getAssetSupply = async (params: {
asset_id: string;
decimal: boolean;
}) => {
const paramDecimal = params.decimal === true ? '/decimal' : '';
const { data } = await api.get<Asset>(
`/asset/${params.asset_id}/supply${paramDecimal}`
);
return data;
};
return {
getAsset,
getAssetTxs,
getAssetSupply,
};
};

79
src/app/liquid/blocks.ts Normal file
View File

@@ -0,0 +1,79 @@
import { AxiosInstance } from 'axios';
import {
Block,
BlockStatus,
BlockInstance,
} from '../../interfaces/bitcoin/blocks';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${params.hash}`);
return data;
};
const getBlockStatus = async (params: { hash: string }) => {
const { data } = await api.get<BlockStatus>(`/block/${params.hash}/status`);
return data;
};
const getBlockTxs = async (params: {
hash: string;
start_index?: number;
}) => {
const { data } = await api.get<Tx>(
`/block/${params.hash}/txs/${params.start_index}`
);
return data;
};
const getBlockTxids = async (params: { hash: string }) => {
const { data } = await api.get<string[]>(`/block/${params.hash}/txids`);
return data;
};
const getBlockTxid = async (params: { hash: string; index: number }) => {
const { data } = await api.get<string>(
`/block/${params.hash}/txid/${params.index}`
);
return data;
};
const getBlockRaw = async (params: { hash: string }) => {
const { data } = await api.get<string>(`/block/${params.hash}/raw`);
return data;
};
const getBlockHeight = async (params: { height: number }) => {
const { data } = await api.get<string>(`/block-height/${params.height}`);
return data;
};
const getBlocks = async (params: { start_height?: number }) => {
const { data } = await api.get<Block>(`/blocks/${params.start_height}`);
return data;
};
const getBlocksTipHeight = async () => {
const { data } = await api.get<number>(`/blocks/tip/height`);
return data;
};
const getBlocksTipHash = async () => {
const { data } = await api.get<string>(`/blocks/tip/hash`);
return data;
};
return {
getBlock,
getBlocks,
getBlockStatus,
getBlockTxs,
getBlockTxid,
getBlockTxids,
getBlockRaw,
getBlockHeight,
getBlocksTipHash,
getBlocksTipHeight,
};
};

33
src/app/liquid/fees.ts Normal file
View File

@@ -0,0 +1,33 @@
import { AxiosInstance } from 'axios';
import {
FeesRecommended,
FeesMempoolBlocks,
FeeInstance,
} from '../../interfaces/bitcoin/fees';
export const useFees = (api: AxiosInstance): FeeInstance => {
const getFeesRecommended = async () => {
const { data } = await api.get<FeesRecommended>(`/v1/fees/recommended`);
return data;
};
const getFeesMempoolBlocks = async () => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/fees/mempool-blocks`
);
return data;
};
const getCPFP = async (params: { txid: string }) => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/cpfp/${params.txid}`
);
return data;
};
return {
getFeesRecommended,
getFeesMempoolBlocks,
getCPFP,
};
};

29
src/app/liquid/mempool.ts Normal file
View File

@@ -0,0 +1,29 @@
import { AxiosInstance } from 'axios';
import {
Mempool,
MempoolRecent,
MempoolInstance,
} from '../../interfaces/bitcoin/mempool';
export const useMempool = (api: AxiosInstance): MempoolInstance => {
const getMempool = async () => {
const { data } = await api.get<Mempool[]>(`/mempool`);
return data;
};
const getMempoolTxids = async () => {
const { data } = await api.get<string[]>(`/mempool/txids`);
return data;
};
const getMempoolRecent = async () => {
const { data } = await api.get<MempoolRecent[]>(`/mempool/recent`);
return data;
};
return {
getMempool,
getMempoolTxids,
getMempoolRecent,
};
};

View File

@@ -0,0 +1,75 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../../interfaces/bitcoin/transactions';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxStatus = async (params: { txid: string }) => {
const { data } = await api.get<TxStatus>(`/tx/${params.txid}/status`);
return data;
};
const getTxHex = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/hex`);
return data;
};
const getTxRaw = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (params: { txid: string }) => {
const { data } = await api.get<string>(
`/tx/${params.txid}/merkleblock-proof`
);
return data;
};
const getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxOutspend>>(
`/tx/${params.txid}/outspends`
);
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -0,0 +1,14 @@
import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import wsClient from '../../services/ws/client';
import wsServer from '../../services/ws/server';
const defaultWs = 'wss://mempool.space/liquid/api/v1/ws';
export const useWebsocket = (hostname?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, hostname),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, hostname),
};
};

View File

@@ -1,71 +0,0 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../interfaces';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (txid: string) => {
const { data } = await api.get<Tx>(`/tx/${txid}`);
return data;
};
const getTxStatus = async (txid: string) => {
const { data } = await api.get<TxStatus>(`/tx/${txid}/status`);
return data;
};
const getTxHex = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/hex`);
return data;
};
const getTxRaw = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/merkleblock-proof`);
return data;
};
const getTxMerkleProof = async (txid: string) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (txid: string) => {
const { data } = await api.get<Array<TxOutspend>>(`/tx/${txid}/outspends`);
return data;
};
const postTx = async (txid: string) => {
const { data } = await api.post<string>(`/tx`, { txid: txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -1,14 +0,0 @@
import { WsInterface, WsInstance } from '../interfaces';
import wsClient from '../services/wsClient';
import wsServer from '../services/wsServer';
const defaultWs = 'wss://mempool.space/api/v1/ws';
export const useWebsocket = (websocketEndpoint?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, websocketEndpoint),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, websocketEndpoint),
};
};