* 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),
};
};

View File

@@ -1,31 +1,70 @@
import { MempoolConfig, MempoolReturn } from './interfaces';
import { makeAPI } from './services/api';
import { MempoolConfig, MempoolReturn } from './interfaces/index';
import {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
} from './services/api/index';
import { useAddresses } from './app/addresses';
import { useBlocks } from './app/blocks';
import { useFees } from './app/fees';
import { useMempool } from './app/mempool';
import { useTransactions } from './app/transactions';
import { useWebsocket } from './app/websocket';
import { useAddresses } from './app/bitcoin/addresses';
import { useBlocks } from './app/bitcoin/blocks';
import { useFees } from './app/bitcoin/fees';
import { useMempool } from './app/bitcoin/mempool';
import { useTransactions } from './app/bitcoin/transactions';
import { useWebsocket } from './app/bitcoin/websocket';
const apiEndpointDefault = 'https://mempool.space/api/';
const websocketEndpointDefault = 'wss://mempool.space/api/v1/ws';
import { useAddresses as useAddressesBisq } from './app/bisq/addresses';
import { useBlocks as useBlocksBisq } from './app/bisq/blocks';
import { useStatistics as useStatisticsBisq } from './app/bisq/statistics';
import { useTransactions as useTransactionsBisq } from './app/bisq/transactions';
import { useAssets as useAssetsLiquid } from './app/liquid/assets';
import { useAddresses as useAddressesLiquid } from './app/liquid/addresses';
import { useBlocks as useBlocksLiquid } from './app/liquid/blocks';
import { useFees as useFeesLiquid } from './app/liquid/fees';
import { useMempool as useMempoolLiquid } from './app/liquid/mempool';
import { useTransactions as useTransactionsLiquid } from './app/liquid/transactions';
import { useWebsocket as useWebsocketLiquid } from './app/liquid/websocket';
const hostnameEndpointDefault = 'mempool.space';
const networkEndpointDefault = 'main';
const mempool = (
{ apiEndpoint, websocketEndpoint }: MempoolConfig = {
apiEndpoint: apiEndpointDefault,
websocketEndpoint: websocketEndpointDefault,
{ hostname, network }: MempoolConfig = {
hostname: hostnameEndpointDefault,
network: networkEndpointDefault,
}
): MempoolReturn => {
const { api } = makeAPI(apiEndpoint);
if (!hostname) hostname = hostnameEndpointDefault;
if (!network) network = networkEndpointDefault;
const { api: apiBitcoin } = makeBitcoinAPI({ hostname, network });
const { api: apiBisq } = makeBisqAPI(hostname);
const { api: apiLiquid } = makeLiquidAPI(hostname);
return {
addresses: useAddresses(api),
blocks: useBlocks(api),
fees: useFees(api),
mempool: useMempool(api),
transactions: useTransactions(api),
websocket: useWebsocket(websocketEndpoint),
bitcoin: {
addresses: useAddresses(apiBitcoin),
blocks: useBlocks(apiBitcoin),
fees: useFees(apiBitcoin),
mempool: useMempool(apiBitcoin),
transactions: useTransactions(apiBitcoin),
websocket: useWebsocket(hostname),
},
bisq: {
statistics: useStatisticsBisq(apiBisq),
addresses: useAddressesBisq(apiBisq),
blocks: useBlocksBisq(apiBisq),
transactions: useTransactionsBisq(apiBisq),
},
liquid: {
addresses: useAddressesLiquid(apiLiquid),
assets: useAssetsLiquid(apiLiquid),
blocks: useBlocksLiquid(apiLiquid),
fees: useFeesLiquid(apiLiquid),
mempool: useMempoolLiquid(apiLiquid),
transactions: useTransactionsLiquid(apiLiquid),
websocket: useWebsocketLiquid(hostname),
},
};
};

View File

@@ -1,213 +0,0 @@
import WebSocketServer from 'ws';
export interface Address {
address: string;
chain_stats: {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
};
mempool_stats: {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
};
}
export interface AddressInstance {
getAddress: (address: string) => Promise<Address>;
getAddressTxs: (address: string) => Promise<Tx[]>;
getAddressTxsChain: (address: string) => Promise<Tx[]>;
getAddressTxsMempool: (address: string) => Promise<Tx[]>;
getAddressTxsUtxo: (address: string) => Promise<AddressTxsUtxo[]>;
}
export interface AddressTxsUtxo {
txid: string;
vout: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
value: number;
}
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 BlockInstance {
getBlock: (hash: string) => Promise<Block>;
getBlocks: (params: { start_height?: number }) => Promise<Block>;
getBlockStatus: (hash: string) => Promise<BlockStatus>;
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
getBlockTxids: (hash: string) => Promise<string[]>;
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
getBlockRaw: (hash: string) => Promise<string>;
getBlockHeight: (height: number) => Promise<string>;
getBlocksTipHeight: () => Promise<number>;
getBlocksTipHash: () => Promise<string>;
}
export interface BlockStatus {
in_best_chain: boolean;
height: number;
next_best: string;
}
export interface FeeInstance {
getFeesRecommended: () => Promise<FeesRecommended>;
getFeesMempoolBlocks: () => Promise<FeesMempoolBlocks[]>;
}
export interface FeesMempoolBlocks {
blockSize: number;
blockVSize: number;
nTx: number;
totalFees: number;
medianFee: number;
feeRange: number[];
}
export interface FeesRecommended {
fastestFee: number;
halfHourFee: number;
hourFee: number;
minimumFee: number;
}
export interface Mempool {
count: number;
vsize: number;
total_fee: number;
fee_histogram: number[];
}
export interface MempoolConfig {
apiEndpoint?: string;
websocketEndpoint?: string;
}
export interface MempoolInstance {
getMempool: () => Promise<Mempool[]>;
getMempoolTxids: () => Promise<string[]>;
getMempoolRecent: () => Promise<MempoolRecent[]>;
}
export interface MempoolReturn {
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
}
export interface MempoolRecent {
txid: string;
fee: number;
vsize: number;
value: number;
}
export interface Tx {
txid: string;
version: number;
locktime: number;
vin: {
txid: string;
vout: number;
prevout: {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
};
scriptsig: string;
scriptsig_asm: string;
is_coinbase: boolean;
sequence: string;
}[];
vout: {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
}[];
size: number;
weight: number;
fee: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
}
export interface TxStatus {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
}
export interface TxMerkleProof {
block_height: number;
merkle: string[];
pos: number;
}
export interface TxOutspend {
spent: boolean;
txid: string;
vin: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
}
export interface TxInstance {
getTx: (txid: string) => Promise<Tx>;
getTxStatus: (txid: string) => Promise<TxStatus>;
getTxHex: (txid: string) => Promise<string>;
getTxRaw: (txid: string) => Promise<string>;
getTxMerkleBlockProof: (txid: string) => Promise<string>;
getTxMerkleProof: (txid: string) => Promise<Array<TxMerkleProof>>;
getTxOutspend: (params: {
txid: string;
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (txid: string) => Promise<Array<TxOutspend>>;
postTx: (txid: string) => Promise<unknown>;
}
export interface WsInterface {
options: string[];
}
export interface WsInstance {
initClient: ({ options }: WsInterface) => WebSocket;
initServer: ({ options }: WsInterface) => WebSocketServer;
}

View File

@@ -0,0 +1,13 @@
import { Tx } from './transactions';
export interface Address {
height: number;
time: number;
hash: string;
previousBlockHash: string;
txs: Tx[];
}
export interface AddressesInstance {
getAddress: (params: { address: string }) => Promise<Address>;
}

View File

@@ -0,0 +1,18 @@
import { Tx } from './transactions';
export interface Block {
height: number;
time: number;
hash: string;
previousBlockHash: string;
txs: Tx[];
}
export interface BlocksInstance {
getBlock: (params: { hash: string }) => Promise<Block>;
getBlocks: (params: { index: number; length: number }) => Promise<Block>;
getBlocksTipHeight: (params: {
index: number;
length: number;
}) => Promise<number>;
}

View File

@@ -0,0 +1,11 @@
export interface Stats {
address: number;
minted: number;
burnt: number;
spent_txos: number;
unspent_txos: number;
}
export interface StatsInstance {
getStats: () => Promise<Stats>;
}

View File

@@ -0,0 +1,46 @@
export interface Tx {
txVersion: string;
id: string;
blockHeight: number;
blockHash: string;
time: number;
inputs: [];
outputs: [
{
txVersion: string;
txId: string;
index: number;
bsqAmount: number;
btcAmount: number;
height: number;
isVerified: true;
burntFee: number;
invalidatedBsq: number;
address: string;
scriptPubKey: {
addresses: [string];
asm: string;
hex: string;
reqSigs: number;
type: string;
};
time: number;
txType: string;
txTypeDisplayString: string;
txOutputType: string;
txOutputTypeDisplayString: string;
lockTime: number;
isUnspent: true;
}
];
txType: string;
txTypeDisplayString: string;
burntFee: number;
invalidatedBsq: number;
unlockBlockHeight: number;
}
export interface TransactionsInstance {
getTx: (params: { txid: string }) => Promise<Tx>;
getTxs: (params: { index: number; length: number }) => Promise<Tx[]>;
}

View File

@@ -0,0 +1,30 @@
import { Tx, TxStatus } from './transactions';
export interface Address {
address: string;
chain_stats: StatsInfo;
mempool_stats: StatsInfo;
}
export interface StatsInfo {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
}
export interface AddressTxsUtxo {
txid: string;
vout: number;
status: TxStatus;
value: number;
}
export interface AddressInstance {
getAddress: (params: { address: string }) => Promise<Address>;
getAddressTxs: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsChain: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsMempool: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsUtxo: (params: { address: string }) => Promise<AddressTxsUtxo[]>;
}

View File

@@ -0,0 +1,36 @@
import { Tx } from './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 BlockInstance {
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>;
}

View File

@@ -0,0 +1,21 @@
export interface FeesMempoolBlocks {
blockSize: number;
blockVSize: number;
nTx: number;
totalFees: number;
medianFee: number;
feeRange: number[];
}
export interface FeesRecommended {
fastestFee: number;
halfHourFee: number;
hourFee: number;
minimumFee: number;
}
export interface FeeInstance {
getFeesRecommended: () => Promise<FeesRecommended>;
getFeesMempoolBlocks: () => Promise<FeesMempoolBlocks[]>;
getCPFP: (params: { txid: string }) => Promise<FeesMempoolBlocks[]>;
}

View File

@@ -0,0 +1,19 @@
export interface Mempool {
count: number;
vsize: number;
total_fee: number;
fee_histogram: number[];
}
export interface MempoolInstance {
getMempool: () => Promise<Mempool[]>;
getMempoolTxids: () => Promise<string[]>;
getMempoolRecent: () => Promise<MempoolRecent[]>;
}
export interface MempoolRecent {
txid: string;
fee: number;
vsize: number;
value: number;
}

View File

@@ -0,0 +1,62 @@
export interface Tx {
txid: string;
version: number;
locktime: number;
vin: {
txid: string;
vout: number;
prevout: Vout;
scriptsig: string;
scriptsig_asm: string;
is_coinbase: boolean;
sequence: string;
}[];
vout: Vout[];
size: number;
weight: number;
fee: number;
status: TxStatus;
}
export interface Vout {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
}
export interface TxStatus {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
}
export interface TxMerkleProof {
block_height: number;
merkle: string[];
pos: number;
}
export interface TxOutspend {
spent: boolean;
txid: string;
vin: number;
status: TxStatus;
}
export interface TxInstance {
getTx: (params: { txid: string }) => Promise<Tx>;
getTxStatus: (params: { txid: string }) => Promise<TxStatus>;
getTxHex: (params: { txid: string }) => Promise<string>;
getTxRaw: (params: { txid: string }) => Promise<string>;
getTxMerkleBlockProof: (params: { txid: string }) => Promise<string>;
getTxMerkleProof: (params: { txid: string }) => Promise<Array<TxMerkleProof>>;
getTxOutspend: (params: {
txid: string;
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>;
postTx: (params: { txid: string }) => Promise<unknown>;
}

View File

@@ -0,0 +1,10 @@
export interface WsInterface {
options: string[];
}
import WebSocketServer from 'ws';
export interface WsInstance {
initClient: ({ options }: WsInterface) => WebSocket;
initServer: ({ options }: WsInterface) => WebSocketServer;
}

44
src/interfaces/index.ts Normal file
View File

@@ -0,0 +1,44 @@
import { AddressInstance } from './bitcoin/addresses';
import { BlockInstance } from './bitcoin/blocks';
import { FeeInstance } from './bitcoin/fees';
import { MempoolInstance } from './bitcoin/mempool';
import { TxInstance } from './bitcoin/transactions';
import { WsInstance } from './bitcoin/websockets';
import { AddressesInstance } from './bisq/addresses';
import { BlocksInstance } from './bisq/blocks';
import { StatsInstance } from './bisq/statistics';
import { TransactionsInstance } from './bisq/transactions';
import { AssetsInstance } from './liquid/assets';
export interface MempoolConfig {
hostname?: string;
network?: string;
}
export interface MempoolReturn {
bitcoin: {
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
};
bisq: {
addresses: AddressesInstance;
blocks: BlocksInstance;
statistics: StatsInstance;
transactions: TransactionsInstance;
};
liquid: {
assets: AssetsInstance;
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
};
}

View File

@@ -0,0 +1,27 @@
export interface Asset {
asset_id: string;
chain_stats: AssetStats;
mempool_stats: AssetStats;
}
interface AssetStats {
tx_count: number;
peg_in_count: number;
peg_in_amount: number;
peg_out_count: number;
peg_out_amount: number;
burn_count: number;
burned_amount: number;
}
export interface AssetsInstance {
getAsset: (params: { asset_id: string }) => Promise<Asset>;
getAssetTxs: (params: {
asset_id: string;
is_mempool: boolean;
}) => Promise<Asset>;
getAssetSupply: (params: {
asset_id: string;
decimal: boolean;
}) => Promise<Asset>;
}

View File

@@ -1,10 +0,0 @@
import axios, { AxiosInstance } from 'axios';
export const makeAPI = (apiEndpoint?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: apiEndpoint,
});
return {
api,
};
};

43
src/services/api/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import axios, { AxiosInstance } from 'axios';
import { MempoolConfig } from './../../interfaces/index';
export const makeBitcoinAPI = ({
hostname,
network,
}: MempoolConfig): { api: AxiosInstance } => {
if (network && ['testnet', 'signet'].includes(network)) {
network = `/${network}`;
} else {
network = '';
}
const api = axios.create({
baseURL: `https://${hostname}${network}/api/`,
});
return {
api,
};
};
export const makeBisqAPI = (hostname?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://${hostname}/bisq/api/`,
});
return {
api,
};
};
export const makeLiquidAPI = (hostname?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://${hostname}/liquid/api/`,
});
return {
api,
};
};
export default {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
};

View File

@@ -12,14 +12,12 @@ const browserWS = (
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() {
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
}, 500);
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
};
export default browserWS;

View File

@@ -14,13 +14,11 @@ const serverWS = (
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() {
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
}, 500);
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
};
export default serverWS;