Compare commits

..

1 Commits

Author SHA1 Message Date
Miguel Medeiros
889816f0db
FIX rename package name. (#19) 2021-04-17 00:19:46 -03:00
83 changed files with 3344 additions and 14579 deletions

2
.gitignore vendored
View File

@ -2,5 +2,3 @@
/lib /lib
/dist/* /dist/*
!.gitkeep !.gitkeep
yarn-error.log

150
README-bisq.md Normal file
View File

@ -0,0 +1,150 @@
# mempool**JS** - Bisq API
Interface to access the Bisq API.
[Back to home](./README-bitcoin.md)
---
## **Features**
- [Bitcoin](./README-bitcoin.md)
- Bisq
- Addresses
- [Get Address](#get-address)
- Blocks
- [Get Block](#get-block)
- [Get Blocks](#get-blocks)
- [Get Block Tip Height](#get-block-tip-height)
- Statistics
- Transactions
- [Get Transaction](#get-transaction)
- [Get Transactions](#get-transactions)
- [Liquid](./README-liquid.md)
---
### **Get Address**
Returns statistics about all Bisq transactions.
[ [NodeJS Example](examples/nodejs/bisq/addresses.ts) ] [ [HTML Example](examples/html/bisq/addresses.html) ] [ [Top](#features) ]
```js
const {
bisq: { addresses },
} = mempoolJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
```
### **Get Block**
Returns all Bisq transactions that exist in a Bitcoin block.
**Parameters:**
- {string} hash
[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ]
```js
const {
bisq: { blocks },
} = mempoolJS();
const hash = '000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const block = await blocks.getBlock({ hash });
console.log(block);
```
### **Get Blocks**
Returns `:length` Bitcoin blocks that contain Bisq transactions, starting from `:index`.
**Parameters:**
- {number} index
- {number} length
[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ]
```js
const {
bisq: { blocks },
} = mempoolJS();
const hash = '000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const myBlocks = await blocks.getBlocks({ index: 0, length: 1 });
console.log(myBlocks);
```
### **Get Blocks Tip Height**
Returns the most recently processed Bitcoin block height processed by Bisq.
[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ]
```js
const {
bisq: { blocks },
} = mempoolJS();
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
```
### **Get Stats**
Returns statistics about all Bisq transactions.
[ [NodeJS Example](examples/nodejs/bisq/statistics.ts) ] [ [HTML Example](examples/html/bisq/statistics.html) ] [ [Top](#features) ]
```js
const {
bisq: { statistics },
} = mempoolJS();
const stats = await statistics.getStats();
console.log(stats);
```
### **Get Transaction**
Returns details about a Bisq transaction.
[ [NodeJS Example](examples/nodejs/bisq/transactions.ts) ] [ [HTML Example](examples/html/bisq/transactions.html) ] [ [Top](#features) ]
```js
const {
bisq: { transactions },
} = mempoolJS();
const txid = '4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5';
const tx = await transactions.getTx({ txid });
console.log(tx);
```
### **Get Transactions**
Returns details about a Bisq transactions.
[ [NodeJS Example](examples/nodejs/bisq/transactions.ts) ] [ [HTML Example](examples/html/bisq/transactions.html) ] [ [Top](#features) ]
```js
const {
bisq: { transactions },
} = mempoolJS();
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
```

View File

@ -1,87 +1,57 @@
# mempool**JS** - Bitcoin API # mempool**JS** - Bitcoin API
Interface to access Bitcoin `mainet`, `testnet`, `testnet4`, `signet` APIs. Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs.
[Back to home](./README.md) [Back to home](#)
--- ---
## **Features** ## **Features**
- Addresses - Bitcoin
- [Get Address](#get-address) - Addresses
- [Get Address Txs](#get-address-txs) - [Get Address](#get-address)
- [Get Address Txs Chain](#get-address-txs-chain) - [Get Address Txs](#get-address-txs)
- [Get Address Txs Mempool](#get-address-txs-mempool) - [Get Address Txs Chain](#get-address-txs-chain)
- [Get Address Txs Utxo](#get-address-txs-utxo) - [Get Address Txs Mempool](#get-address-txs-mempool)
- Assets - [Get Address Txs Utxo](#get-address-txs-utxo)
- [Get Asset](#get-asset) - Assets
- [Get Asset Txs](#get-asset-txs) - [Get Asset](#get-asset)
- [Get Asset Supply](#get-asset-supply) - [Get Asset Txs](#get-asset-txs)
- Blocks - [Get Asset Supply](#get-asset-supply)
- [Get Block](#get-block) - Blocks
- [Get Block Status](#get-block-status) - [Get Block](#get-block)
- [Get Block Txs](#get-block-txs) - [Get Block Status](#get-block-status)
- [Get Block Txids](#get-block-txids) - [Get Block Txs](#get-block-txs)
- [Get Block Txid](#get-block-txid) - [Get Block Txids](#get-block-txids)
- [Get Block Raw](#get-block-raw) - [Get Block Txid](#get-block-txid)
- [Get Blocks Header](#get-blocks-header) - [Get Block Raw](#get-block-raw)
- [Get Blocks Height](#get-blocks-height) - [Get Blocks Height](#get-blocks-height)
- [Get Blocks](#get-blocks) - [Get Blocks](#get-blocks)
- [Get Blocks Tip Height](#get-blocks-tip-height) - [Get Blocks Tip Height](#get-blocks-tip-height)
- [Get Blocks Tip Hash](#get-blocks-tip-hash) - [Get Blocks Tip Hash](#get-blocks-tip-hash)
- Difficulty - Fees
- [Get Difficulty Adjustment](#get-difficulty-adjustment) - [Get Fees Recommended](#get-fees-recommended)
- Fees - [Get Fees Mempool Blocks](#get-fees-mempool-blocks)
- [Get Fees Recommended](#get-fees-recommended) - Mempool
- [Get Fees Mempool Blocks](#get-fees-mempool-blocks) - [Get Mempool](#get-mempool)
- Lightning - [Get Mempool Recent](#get-mempool-recent)
- [Get Network Stats](#get-network-stats) - [Get Mempool Txids](#get-mempool-txids)
- [Get Nodes In Country](#get-nodes-in-country) - Transactions
- [Get Nodes Stats Per Country](#get-nodes-stats-per-country) - [Get Tx](#get-tx)
- [Get Nodes Hosted by ISP](#get-nodes-hosted-by-isp) - [Get Tx Status](#get-tx-status)
- [Get ISP Ranking](#get-isp-ranking) - [Get Tx Hex](#get-tx-hex)
- [Get Liquidity Ranking](#get-liquidity-ranking) - [Get Tx Raw](#get-tx-raw)
- [Get Connectivity Ranking](#get-connectivity-ranking) - [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof)
- [Get Oldest Nodes](#get-oldest-nodes) - [Get Tx Merkle Proof](#get-tx-merkle-proof)
- [Get Node Stats](#get-node-stats) - [Get Tx Outspend](#get-tx-outspend)
- [Get Historical Node Stats](#get-historical-node-stats) - [Get Tx Outspends](#get-tx-outspends)
- [Get Channel](#get-channel) - [Post Tx Outspends]($post-tx-outspends)
- [Get Channels From Transaction IDs](#get-channels-from-transaction-ids) - Websocket
- [Get Channels From Node Public Key](#get-channels-from-node-public-key) - [Websocket Client](#websocket-client)
- [Get Channels Geodata](#get-channels-geodata) - [Websocket Server](#websocket-server)
- [Get Channels Geodata By Public Key](#get-channels-geodata-by-public-key) - [Bisq](./README-bisq.md)
- Mempool - [Liquid](./README-liquid.md)
- [Get Mempool](#get-mempool)
- [Get Mempool Recent](#get-mempool-recent)
- [Get Mempool Txids](#get-mempool-txids)
- Transactions
- [Get Tx](#get-tx)
- [Get Tx Status](#get-tx-status)
- [Get Tx Hex](#get-tx-hex)
- [Get Tx Raw](#get-tx-raw)
- [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof)
- [Get Tx Merkle Proof](#get-tx-merkle-proof)
- [Get Tx Outspend](#get-tx-outspend)
- [Get Tx Outspends](#get-tx-outspends)
- [Post Tx](#post-tx)
- Websocket
- [Init Websocket](#init-websocket)
- [Want Data](#want-data)
- [Stop Want Data](#stop-want-data)
- [Track Address](#track-address)
- [Stop Track Address](#stop-track-address)
- [Track Addresses](#track-addresses)
- [Stop Track Addresses](#stop-track-addresses)
- [Track Transaction](#track-transaction)
- [Stop Track Transaction](#stop-track-transaction)
- [Track Rbf Summary](#track-rbf-summary)
- [Stop Track Rbf Summary](#stop-track-rbf-summary)
- [Track Rbf](#track-rbf)
- [Stop Track Rbf](#stop-track-rbf)
- [Track Mempool Block](#track-mempool-block)
- [Stop Track Mempool Block](#stop-track-mempool-block)
--- ---
@ -314,25 +284,6 @@ const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
``` ```
### **Get Blocks Header**
Returns the hex-encoded block header.
**Parameters:**
- {string} hash
[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { blocks },
} = mempoolJS();
const blockHeader = await blocks.getBlockHeader({ hash: '0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2' });
console.log(blockHeader);
```
### **Get Blocks Height** ### **Get Blocks Height**
Returns the hash of the block currently at `:height`. Returns the hash of the block currently at `:height`.
@ -405,21 +356,6 @@ const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash); console.log(blocksTipHash);
``` ```
### **Get Difficulty Adjustment**
Returns the hash of the last block.
[ [NodeJS Example](examples/nodejs/bitcoin/difficulty.ts) ] [ [HTML Example](examples/html/bitcoin/difficulty.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
```
### **Get Fees Recommended** ### **Get Fees Recommended**
Returns our currently suggested fees for new transactions. Returns our currently suggested fees for new transactions.
@ -450,283 +386,6 @@ const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks); console.log(feesMempoolBlocks);
``` ```
### **Get Network Stats**
Returns network-wide stats such as total number of channels and nodes, total capacity, and average/median fee figures.
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const networkStats = await lightning.getNetworkStats();
console.log(networkStats);
```
### **Get Nodes In Country**
Returns a list of Lightning nodes running on clearnet in the requested `:country`, where `:country` is an ISO Alpha-2 country code.
**Parameters:**
- {string} country
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const nodesInCountry = await lightning.getNodesInCountry({ country: 'US' });
console.log(nodesInCountry);
```
### **Get Nodes Stats Per Country**
Returns aggregate capacity and number of clearnet nodes per country. Capacity figures are in satoshis.
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const nodesStatsPerCountry = await lightning.getNodesStatsPerCountry();
console.log(nodesStatsPerCountry);
```
### **Get Nodes Hosted by ISP**
Returns a list of nodes hosted by a specified `:isp`, where `:isp` is an ISP's ASN.
**Parameters:**
- {number} isp
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const nodesHostedByISP = await lightning.getNodesHostedByISP({ isp: 16509 });
console.log(nodesHostedByISP);
```
### **Get ISP Ranking**
Returns aggregate capacity, number of nodes, and number of channels per ISP. Capacity figures are in satoshis.
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const ispRanking = await lightning.getISPRanking();
console.log(ispRanking);
```
### **Get Liquidity Ranking**
Returns a list of the top 100 nodes by liquidity (aggregate channel capacity).
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const liquidityRanking = await lightning.getLiquidityRanking();
console.log(liquidityRanking);
```
### **Get Connectivity Ranking**
Returns a list of the top 100 nodes by connectivity (number of open channels).
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const connectivityRanking = await lightning.getConnectivityRanking();
console.log(connectivityRanking);
```
### **Get Oldest Nodes**
Returns a list of the top 100 oldest nodes.
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const oldestNodes = await lightning.getOldestNodes();
console.log(oldestNodes);
```
### **Get Node Stats**
Returns details about a node with the given `:public_key`.
**Parameters:**
- {string} public_key
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const nodeStats = await lightning.getNodeStats({ public_key });
console.log(nodeStats);
```
### **Get Historical Node Stats**
Returns historical stats for a node with the given `:public_key`.
**Parameters:**
- {string} public_key
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const historicalNodeStats = await lightning.getHistoricalNodeStats({ public_key });
console.log(historicalNodeStats);
```
### **Get Channel**
Returns details about a channel with the given `:id`.
**Parameters:**
- {string} id
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const channel = await lightning.getChannel({ id });
console.log(channel);
```
### **Get Channels From Transaction IDs**
Returns channels that correspond to the given `:txId` (multiple transaction IDs can be specified).
**Parameters:**
- {[]string} txId
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const channelsFromTransactionIDs = await lightning.getChannelsFromTransactionIDs({ txId });
console.log(channelsFromTransactionIDs);
```
### **Get Channels From Node Public Key**
Returns a list of a node's channels given its `:public_key`. Ten channels are returned at a time. Use `:index` for paging. `:status` can be `open`, `active`, or `closed`.
**Parameters:**
- {string} public_key
- {string} status
- {number} index
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const channelsFromNodePublicKey = await lightning.getChannelsFromNodePublicKey({ public_key, status, index });
console.log(channelsFromNodePublicKey);
```
### **Get Channels Geodata**
Returns a list of channels with corresponding node geodata.
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const channelsGeodata = await lightning.getChannelsGeodata();
console.log(channelsGeodata);
```
### **Get Channels Geodata By Public Key**
Returns a list of channels with corresponding geodata for a node with the given `:public_key`.
**Parameters:**
- {string} public_key
[ [NodeJS Example](examples/nodejs/bitcoin/lightning.ts) ] [ [HTML Example](examples/html/bitcoin/lightning.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { lightning },
} = mempoolJS();
const channelsGeodataByPublicKey = await lightning.getChannelsGeodataByPublicKey({ public_key });
console.log(channelsGeodataByPublicKey);
```
### **Get Children Pay for Parent**
Returns current mempool as projected blocks.
[ [NodeJS Example](examples/nodejs/bitcoin/fees.ts) ] [ [HTML Example](examples/html/bitcoin/fees.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { fees },
} = mempoolJS();
const txid = 'txid';
const feesCPFP = await fees.getCPFP({ txid });
console.log(feesCPFP);
```
### **Get Mempool** ### **Get Mempool**
Returns current mempool backlog statistics. Returns current mempool backlog statistics.
@ -944,13 +603,13 @@ const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends); console.log(txOutspends);
``` ```
### **Post Tx ** ### **Post Tx Outspends**
Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success. Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success.
**Parameters:** **Parameters:**
- {string} txhex - {string} txid
[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] [ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ]
@ -959,163 +618,72 @@ const {
bitcoin: { transactions }, bitcoin: { transactions },
} = mempoolJS(); } = mempoolJS();
const txhex = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const postTx = await transactions.postTx({ txhex }); const postTx = await transactions.postTx({ txid });
console.log(postTx); console.log(postTx);
``` ```
### **Init Websocket** ### **Websocket**
Initializes a websocket connection. Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you want pushed. Available: blocks, mempool-block, live-2h-chart, and stats.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ] Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions.
[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ]
#### **Websocket Server**
```js ```js
const { bitcoin: { websocket } } = mempoolJS(); const {
const ws = websocket.wsInit(); // for in-browser websocket, use websocket.wsInitBrowser bitcoin: { websocket },
ws.addEventListener('message', function incoming({data}) { } = mempoolJS();
console.log(JSON.parse(data.toString()));
const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
}); });
``` ```
### **Want Data** #### **Websocket Client**
Subscribe to `want` data. Available: `blocks`, `mempool-block`, `live-2h-chart`, and `stats`.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js ```js
websocket.wsWantData(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); // for in-browser websocket, use websocket.wsWantDataBrowser const {
``` bitcoin: { websocket },
} = mempoolJS();
### **Stop Want Data**
const ws = websocket.initClient({
Unsubscribe from `want` data. options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
ws.on('message', function incoming(data) {
```js const res = JSON.parse(data.toString());
websocket.wsStopData(ws); // for in-browser websocket, use websocket.wsStopDataBrowser if (res.blocks) {
``` console.log(res.blocks);
}
### **Track Address** if (res.mempoolInfo) {
console.log(res.mempoolInfo);
Subscribe to address updates. }
if (res.transactions) {
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ] console.log(res.transactions);
}
```js if (res.mempoolBlocks) {
websocket.wsTrackAddress(ws, '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'); // for in-browser websocket, use websocket.wsTrackAddressBrowser console.log(res.mempoolBlocks);
``` }
});
### **Stop Track Address**
Unsubscribe from address updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingAddress(ws, '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'); // for in-browser websocket, use websocket.wsStopTrackingAddressBrowser
```
### **Track Addresses**
Subscribe to multiple address updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackAddresses(ws, ['1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC']); // for in-browser websocket, use websocket.wsTrackAddressesBrowser
```
### **Stop Track Addresses**
Unsubscribe from multiple address updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingAddresses(ws); // for in-browser websocket, use websocket.wsStopTrackingAddressesBrowser
```
### **Track Transaction**
Subscribe to transaction updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackTransaction(ws, '01313ca0148a1bbe5676e5dd6a84e76f8b39038658bd8c333d3b2d3f7ea6dd08'); // for in-browser websocket, use websocket.wsTrackTransactionBrowser
```
### **Stop Track Transaction**
Unsubscribe from transaction updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingTransaction(ws); // for in-browser websocket, use websocket.wsStopTrackingTransactionBrowser
```
### **Track Rbf Summary**
Subscribe to RBF summary updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackRbfSummary(ws); // for in-browser websocket, use websocket.wsTrackRbfSummaryBrowser
```
### **Stop Track Rbf Summary**
Unsubscribe from RBF summary updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingRbfSummary(ws); // for in-browser websocket, use websocket.wsStopTrackingRbfSummaryBrowser
```
### **Track Rbf**
Subscribe to RBF updates. Set the second parameter to `true` to track Full RBF.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackRbf(ws, true); // for in-browser websocket, use websocket.wsTrackRbfBrowser
```
### **Stop Track Rbf**
Unsubscribe from RBF updates.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingRbf(ws); // for in-browser websocket, use websocket.wsStopTrackingRbfBrowser
```
### **Track Mempool Block**
Subscribe to mempool blocks.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackMempoolBlock(ws, 1); // for in-browser websocket, use websocket.wsTrackMempoolBlockBrowser
```
### **Stop Track Mempool Block**
Unsubscribe from mempool blocks.
[ [NodeJS Example](examples/nodejs/bitcoin/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingMempoolBlock(ws); // for in-browser websocket, use websocket.wsStopTrackingMempoolBlockBrowser
``` ```

View File

@ -1,6 +1,6 @@
# mempool**JS** - Liquid API # mempool**JS** - Bitcoin API
Interface to access Liquid APIs. Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs.
[Back to home](./README.md) [Back to home](./README.md)
@ -8,57 +8,50 @@ Interface to access Liquid APIs.
## **Features** ## **Features**
- Addresses - [Bitcoin](./README-bitcoin.md)
- [Get Address](#get-address) - [Bisq](./README-bisq.md)
- [Get Address Txs](#get-address-txs) - Liquid
- [Get Address Txs Chain](#get-address-txs-chain) - Addresses
- [Get Address Txs Mempool](#get-address-txs-mempool) - [Get Address](#get-address)
- [Get Address Txs Utxo](#get-address-txs-utxo) - [Get Address Txs](#get-address-txs)
- Assets - [Get Address Txs Chain](#get-address-txs-chain)
- [Get Asset](#get-asset) - [Get Address Txs Mempool](#get-address-txs-mempool)
- [Get Asset Icon](#get-asset-icon) - [Get Address Txs Utxo](#get-address-txs-utxo)
- [Get Asset Txs](#get-asset-txs) - Assets
- [Get Asset Supply](#get-asset-supply) - [Get Asset](#get-asset)
- [Get Assets Icons](#get-assets-icons) - [Get Asset Txs](#get-asset-txs)
- Blocks - [Get Asset Supply](#get-asset-supply)
- [Get Block](#get-block) - Blocks
- [Get Block Status](#get-block-status) - [Get Block](#get-block)
- [Get Block Txs](#get-block-txs) - [Get Block Status](#get-block-status)
- [Get Block Txids](#get-block-txids) - [Get Block Txs](#get-block-txs)
- [Get Block Txid](#get-block-txid) - [Get Block Txids](#get-block-txids)
- [Get Block Raw](#get-block-raw) - [Get Block Txid](#get-block-txid)
- [Get Blocks Height](#get-blocks-height) - [Get Block Raw](#get-block-raw)
- [Get Blocks](#get-blocks) - [Get Blocks Height](#get-blocks-height)
- [Get Blocks Tip Height](#get-blocks-tip-height) - [Get Blocks](#get-blocks)
- [Get Blocks Tip Hash](#get-blocks-tip-hash) - [Get Blocks Tip Height](#get-blocks-tip-height)
- Fees - [Get Blocks Tip Hash](#get-blocks-tip-hash)
- [Get Fees Recommended](#get-fees-recommended) - Fees
- [Get Fees Mempool Blocks](#get-fees-mempool-blocks) - [Get Fees Recommended](#get-fees-recommended)
- Mempool - [Get Fees Mempool Blocks](#get-fees-mempool-blocks)
- [Get Mempool](#get-mempool) - Mempool
- [Get Mempool Recent](#get-mempool-recent) - [Get Mempool](#get-mempool)
- [Get Mempool Txids](#get-mempool-txids) - [Get Mempool Recent](#get-mempool-recent)
- Transactions - [Get Mempool Txids](#get-mempool-txids)
- [Get Tx](#get-tx) - Transactions
- [Get Tx Status](#get-tx-status) - [Get Tx](#get-tx)
- [Get Tx Hex](#get-tx-hex) - [Get Tx Status](#get-tx-status)
- [Get Tx Raw](#get-tx-raw) - [Get Tx Hex](#get-tx-hex)
- [Get Tx Merkle Proof](#get-tx-merkle-proof) - [Get Tx Raw](#get-tx-raw)
- [Get Tx Outspend](#get-tx-outspend) - [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof)
- [Get Tx Outspends](#get-tx-outspends) - [Get Tx Merkle Proof](#get-tx-merkle-proof)
- [Post Tx](#post-tx) - [Get Tx Outspend](#get-tx-outspend)
- Websocket - [Get Tx Outspends](#get-tx-outspends)
- [Init Websocket](#init-websocket) - [Post Tx Outspends]($post-tx-outspends)
- [Want Data](#want-data) - Websocket
- [Stop Want Data](#stop-want-data) - [Websocket Client](#websocket-client)
- [Track Address](#track-address) - [Websocket Server](#websocket-server)
- [Stop Track Address](#stop-track-address)
- [Track Addresses](#track-addresses)
- [Stop Track Addresses](#stop-track-addresses)
- [Track Transaction](#track-transaction)
- [Stop Track Transaction](#stop-track-transaction)
- [Track Mempool Block](#track-mempool-block)
- [Stop Track Mempool Block](#stop-track-mempool-block)
--- ---
@ -77,7 +70,7 @@ const {
liquid: { addresses }, liquid: { addresses },
} = mempoolJS(); } = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address }); const myAddress = await addresses.getAddress({ address });
console.log(myAddress); console.log(myAddress);
@ -98,7 +91,7 @@ const {
liquid: { addresses }, liquid: { addresses },
} = mempoolJS(); } = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const addressTxs = await addresses.getAddressTxs({ address }); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
@ -119,7 +112,7 @@ const {
liquid: { addresses }, liquid: { addresses },
} = mempoolJS(); } = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const addressTxsChain = await addresses.getAddressTxsChain({ address }); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
@ -140,7 +133,7 @@ const {
liquid: { addresses }, liquid: { addresses },
} = mempoolJS(); } = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const addressTxsMempool = await addresses.getAddressTxsMempool({ address }); const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
console.log(addressTxsMempool); console.log(addressTxsMempool);
@ -171,7 +164,7 @@ Returns information about a Liquid asset.
- {string} asset_id - {string} asset_id
[ [NodeJS Example](examples/nodejs/liquid/assets.ts) ] [ [HTML Example](examples/html/liquid/assets.html) ] [ [Top](#features) ] [ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ]
```js ```js
const { const {
@ -194,7 +187,7 @@ Returns transactions associated with the specified Liquid asset. For the network
- {string} asset_id - {string} asset_id
- {boolean} is_mempool - {boolean} is_mempool
[ [NodeJS Example](examples/nodejs/liquid/assets.ts) ] [ [HTML Example](examples/html/liquid/assets.html) ] [ [Top](#features) ] [ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ]
```js ```js
const { const {
@ -217,7 +210,7 @@ Get the current total supply of the specified asset. For the native asset (L-BTC
- {string} asset_id - {string} asset_id
- {boolean} decimal - {boolean} decimal
[ [NodeJS Example](examples/nodejs/liquid/assets.ts) ] [ [HTML Example](examples/html/liquid/assets.html) ] [ [Top](#features) ] [ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ]
```js ```js
const { const {
@ -590,6 +583,27 @@ const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
``` ```
### **Get Tx Merkle Block Proof**
Returns a merkle inclusion proof for the transaction using bitcoind's merkleblock format.
**Parameters:**
- {string} txid
[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ]
```js
const {
liquid: { transactions },
} = mempoolJS();
const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleBlockProof);
```
### **Get Tx Merkle Proof** ### **Get Tx Merkle Proof**
Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format. Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format.
@ -657,13 +671,13 @@ const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends); console.log(txOutspends);
``` ```
### **Post Tx ** ### **Post Tx Outspends**
Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success. Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success.
**Parameters:** **Parameters:**
- {string} txhex - {string} txid
[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] [ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ]
@ -672,123 +686,72 @@ const {
liquid: { transactions }, liquid: { transactions },
} = mempoolJS(); } = mempoolJS();
const txhex = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const postTx = await transactions.postTx({ txhex }); const postTx = await transactions.postTx({ txid });
console.log(postTx); console.log(postTx);
``` ```
### **Init Websocket** ### **Websocket**
Initializes a websocket connection. Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you want pushed. Available: blocks, mempool-block, live-2h-chart, and stats.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ] Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions.
[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ]
#### **Websocket Server**
```js ```js
const { liquid: { websocket } } = mempoolJS( {hostname: 'liquid.network'} ); const {
const ws = websocket.wsInit(); // for in-browser websocket, use websocket.wsInitBrowser liquid: { websocket },
ws.addEventListener('message', function incoming({data}) { } = mempoolJS();
console.log(JSON.parse(data.toString()));
const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
if (res.blocks) {
console.log(res.blocks);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
}); });
``` ```
### **Want Data** #### **Websocket Client**
Subscribe to `want` data. Available: `blocks`, `mempool-block`, `live-2h-chart`, and `stats`.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js ```js
websocket.wsWantData(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); // for in-browser websocket, use websocket.wsWantDataBrowser const {
``` liquid: { websocket },
} = mempoolJS();
### **Stop Want Data**
const ws = websocket.initClient({
Unsubscribe from `want` data. options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
ws.on('message', function incoming(data) {
```js const res = JSON.parse(data.toString());
websocket.wsStopData(ws); // for in-browser websocket, use websocket.wsStopDataBrowser if (res.blocks) {
``` console.log(res.blocks);
}
### **Track Address** if (res.mempoolInfo) {
console.log(res.mempoolInfo);
Subscribe to address updates. }
if (res.transactions) {
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ] console.log(res.transactions);
}
```js if (res.mempoolBlocks) {
websocket.wsTrackAddress(ws, 'GiAi95k5JUPNPoDGNzSUZ8vWMijSiSMTon'); // for in-browser websocket, use websocket.wsTrackAddressBrowser console.log(res.mempoolBlocks);
``` }
});
### **Stop Track Address**
Unsubscribe from address updates.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingAddress(ws); // for in-browser websocket, use websocket.wsStopTrackingAddressBrowser
```
### **Track Addresses**
Subscribe to multiple addresses updates.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackAddresses(ws, ['GiAi95k5JUPNPoDGNzSUZ8vWMijSiSMTon']); // for in-browser websocket, use websocket.wsTrackAddressesBrowser
```
### **Stop Track Addresses**
Unsubscribe from multiple addresses updates.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingAddresses(ws); // for in-browser websocket, use websocket.wsStopTrackingAddressesBrowser
```
### **Track Transaction**
Subscribe to a transaction updates.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackTransaction(ws, '23195d459a70875c3b1f9fb9082acc9f0594f1c63dac71b40f2ff7298630a421'); // for in-browser websocket, use websocket.wsTrackTransactionBrowser()
```
### **Stop Track Transaction**
Unsubscribe from a transaction updates.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingTransaction(ws); // for in-browser websocket, use websocket.wsStopTrackingTransactionBrowser
```
### **Track Mempool Block**
Subscribe to mempool blocks.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsTrackMempoolBlock(ws, 1); // for in-browser websocket, use websocket.wsTrackMempoolBlockBrowser
```
### **Stop Track Mempool Block**
Unsubscribe from mempool blocks.
[ [NodeJS Example](examples/nodejs/liquid/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
```js
websocket.wsStopTrackingMempoolBlock(ws); // for in-browser websocket, use websocket.wsStopTrackingMempoolBlockBrowser
``` ```

View File

@ -2,12 +2,12 @@
[![npm version](https://img.shields.io/npm/v/@mempool/mempool.js.svg?style=flat-square)](https://www.npmjs.org/package/@mempool/mempool.js) [![npm version](https://img.shields.io/npm/v/@mempool/mempool.js.svg?style=flat-square)](https://www.npmjs.org/package/@mempool/mempool.js)
[![NPM](https://img.shields.io/david/mempool/mempool.js.svg?style=flat-square)](https://david-dm.org/mempool/mempool.js#info=dependencies) [![NPM](https://img.shields.io/david/mempool/mempool.js.svg?style=flat-square)](https://david-dm.org/mempool/mempool.js#info=dependencies)
[![Known Vulnerabilities](https://snyk.io/test/github/mempool/mempool.js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/mempool.js) [![Known Vulnerabilities](https://snyk.io/test/github/mempool/mempool-js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/mempool-js)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
NPM package module for Mempool APIs. NPM package module for Mempool APIs.
Documentation: [https://mempool.space/api](https://mempool.space/api) Documentation: [https://mempool.tools/mempool-js](https://mempool.tools/mempool-js)
--- ---
@ -25,32 +25,19 @@ $ npm install @mempool/mempool.js --save
$ yarn add @mempool/mempool.js $ yarn add @mempool/mempool.js
``` ```
Or if you're not into package management, just [download a ZIP](https://github.com/mempool/mempool.js/archive/refs/heads/main.zip) file. Or if you're not into package management, just [download a ZIP](https://github.com/mempool/mempool-js/archive/refs/heads/main.zip) file.
Import the module. Import the module.
```js ```js
import mempoolJS from '@mempool/mempool.js'; import mempoolJS from '@mempool/mempool.js';
// default mempool.space endpointsconst { bitcoin, liquid } = mempoolJS(); // default mempool.space endpoints
const { bitcoin, bisq, liquid } = mempoolJS();
// (optional) your custom endpoints // (alternative) your custom endpoints
const { bitcoin } = mempoolJS({ const { bitcoin, bisq, liquid } = mempoolJS({
protocol: 'https', // optional, defaults to http for localhost, otherwise https homespace: 'mempool.space',
hostname: 'mempool.space',
network: 'testnet4' // 'signet' | 'testnet' | 'testnet4' | 'mainnet',
config: { // optional axios request config to add to requests
headers: {
authorization: 'Basic auth'
}
}
});
// Liquid API
const { liquid } = mempoolJS({
protocol: 'https', // optional, defaults to http for localhost, otherwise https
hostname: 'liquid.network',
network: 'liquid' // 'liquid' | 'liquidtestnet'
}); });
``` ```
@ -62,24 +49,15 @@ Include the line below in the `head` tag of your html file.
<script type="text/javascript" src="https://mempool.space/mempool.js"></script> <script type="text/javascript" src="https://mempool.space/mempool.js"></script>
``` ```
Call `mempoolJS()` function to access the API methods. Call `mempoolJS` function to access the API methods.
```js ```js
// default mempool.space endpoints // default mempool.space endpoints
const { bitcoin } = mempoolJS(); const { bitcoin, bisq, liquid } = mempoolJS();
// (optional) your custom endpoints // (alternative) your custom endpoints
const { bitcoin } = mempoolJS({ const { bitcoin, bisq, liquid } = mempoolJS({
protocol: 'https', // optional, defaults to http for localhost, otherwise https homespace: 'mempool.space',
hostname: 'mempool.space',
network: 'testnet4', // 'signet' | 'testnet' | 'testnet4' | 'mainnet'
});
// Liquid API
const { liquid } = mempoolJS({
protocol: 'https', // optional, defaults to http for localhost, otherwise https
hostname: 'liquid.network',
network: 'liquid' // 'liquid' | 'liquidtestnet'
}); });
``` ```
@ -90,12 +68,16 @@ const { liquid } = mempoolJS({
- [Bitcoin](./README-bitcoin.md) - [Bitcoin](./README-bitcoin.md)
- [Addresses](./README-bitcoin.md#get-address) - [Addresses](./README-bitcoin.md#get-address)
- [Blocks](./README-bitcoin.md#get-blocks) - [Blocks](./README-bitcoin.md#get-blocks)
- [Difficulty Adjustment](./README-bitcoin.md#get-difficulty-adjustment)
- [Fees](./README-bitcoin.md#get-fees) - [Fees](./README-bitcoin.md#get-fees)
- [Lightning](./README-bitcoin.md#get-network-stats)
- [Mempool](./README-bitcoin.md#get-mempool) - [Mempool](./README-bitcoin.md#get-mempool)
- [Transactions](./README-bitcoin.md#get-transactions) - [Transactions](./README-bitcoin.md#get-transactions)
- [Websocket](./README-bitcoin.md#init-websocket) - [Websocket Client](./README-bitcoin.md#Websocket-Client)
- [Websocket Server](./README-bitcoin.md#Websocket-Server)
- [Bisq](./README-bisq.md#get-address)
- [Addresses](./README-bisq.md#get-address)
- [Blocks](./README-bisq.md#get-blocks)
- [Statistics](./README-bisq.md#get-statistics)
- [Transactions](./README-bisq.md#get-transactions)
- [Liquid](./README-liquid.md#get-address) - [Liquid](./README-liquid.md#get-address)
- [Addresses](./README-liquid.md#get-address) - [Addresses](./README-liquid.md#get-address)
- [Assets](./README-liquid.md#get-address) - [Assets](./README-liquid.md#get-address)
@ -103,7 +85,8 @@ const { liquid } = mempoolJS({
- [Fees](./README-liquid.md#get-address) - [Fees](./README-liquid.md#get-address)
- [Mempool](./README-liquid.md#get-address) - [Mempool](./README-liquid.md#get-address)
- [Transactions](./README-liquid.md#get-address) - [Transactions](./README-liquid.md#get-address)
- [Websocket](./README-liquid.md#init-websocket) - [Websocket Client](./README-liquid.md#Websocket-Client)
- [Websocket Server](./README-liquid.md#Websocket-Server)
--- ---

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { addresses },
} = mempoolJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { blocks },
} = mempoolJS();
const hash =
'000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const block = await blocks.getBlock({ hash });
console.log(block);
const myBlocks = await blocks.getBlocks({ index: 0, length: 1 });
console.log(myBlocks);
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { statistics },
} = mempoolJS();
const stats = await statistics.getStats();
console.log(stats);
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { transactions },
} = mempoolJS();
const txid = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -2,35 +2,31 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { addresses },
bitcoin: { addresses }, } = mempoolJS();
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address }); const myAddress = await addresses.getAddress({ address });
console.log(myAddress); console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address }); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address }); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ const addressTxsMempool = await addresses.getAddressTxsMempool({
address, address,
}); });
console.log(addressTxsMempool); console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address }); const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo); console.log(addressTxsUtxo);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,55 +2,48 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { blocks },
bitcoin: { blocks }, } = mempoolJS();
} = mempoolJS();
const hash = const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash }); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash }); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash }); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash }); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeader = await blocks.getBlockHeader({ hash }); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeader); console.log(blockHeight);
const blockHeight = await blocks.getBlockHeight({ height: 0 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(blockHeight); console.log(getBlocks);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(getBlocks); console.log(blocksTipHeight);
const blocksTipHeight = await blocks.getBlocksTipHeight(); const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHeight); console.log(blocksTipHash);
const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>
</head> </head>
<body></body> <body></body>
</html> </html>

View File

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -2,22 +2,18 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { fees },
bitcoin: { fees }, } = mempoolJS();
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks); console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -1,67 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const { bitcoin: { lightning } } = mempoolJS();
const node = '03d607f3e69fd032524a867b288216bfab263b6eaee4e07783799a6fe69bb84fac';
const channel = '768457472831193088';
const networkStats = await lightning.getNetworkStats();
console.log(networkStats);
const nodesInCountry = await lightning.getNodesInCountry({ country: 'fr' });
console.log(nodesInCountry);
const nodesStatsPerCountry = await lightning.getNodesStatsPerCountry();
console.log(nodesStatsPerCountry);
const nodesHostedByISP = await lightning.getNodesHostedByISP({ isp: 16509 });
console.log(nodesHostedByISP);
const ispRanking = await lightning.getISPRanking();
console.log(ispRanking);
const liquidityRanking = await lightning.getLiquidityRanking();
console.log(liquidityRanking);
const connectivityRanking = await lightning.getConnectivityRanking();
console.log(connectivityRanking);
const oldestNodes = await lightning.getOldestNodes();
console.log(oldestNodes);
const nodeStats = await lightning.getNodeStats({ public_key: node });
console.log(nodeStats);
const historicalNodeStats = await lightning.getHistoricalNodeStats({ public_key: node });
console.log(historicalNodeStats);
const channelData = await lightning.getChannel({ id: channel });
console.log(channelData);
const channelsFromTxIds = await lightning.getChannelsFromTxIds({ txId: ['c3173549f502ede6440d5c48ea74af5607d88484c7a912bbef73d430049f8af4', 'd78f0b41a263af3df91fa4171cc2f60c40196aaf8f4bde5d1c8ff4474cfe753b'] });
console.log(channelsFromTxIds);
const channelsFromNodePublicKey = await lightning.getChannelsFromNodePublicKey({ public_key: node, status: 'active'});
console.log(channelsFromNodePublicKey);
const channelsGeodata = await lightning.getChannelsGeodata();
console.log(channelsGeodata);
const channelsGeodataByPublicKey = await lightning.getChannelsGeodataByPublicKey({ public_key: node });
console.log(channelsGeodataByPublicKey);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -2,25 +2,21 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { mempool },
bitcoin: { mempool }, } = mempoolJS();
} = mempoolJS();
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent(); const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent); console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids(); const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids); console.log(getMempoolTxids);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,55 +2,50 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { transactions },
bitcoin: { transactions }, } = mempoolJS();
} = mempoolJS();
const txid = const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid }); const tx = await transactions.getTx({ txid });
console.log(tx); console.log(tx);
const txStatus = await transactions.getTxStatus({ txid }); const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus); console.log(txStatus);
const txHex = await transactions.getTxHex({ txid }); const txHex = await transactions.getTxHex({ txid });
console.log(txHex); console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid }); const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({
txid, txid,
}); });
console.log(txMerkleBlockProof); console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof({ txid }); const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof); console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({ const txOutspend = await transactions.getTxOutspend({
txid, txid,
vout: 3, vout: 3,
}); });
console.log(txOutspend); console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid }); const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends); console.log(txOutspends);
const postTx = await transactions.postTx({ txhex: txHex }); // const postTx = await transactions.postTx({ txid });
console.log(postTx); // console.log(postTx);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>
</head> </head>
<body></body> <body></body>
</html> </html>

View File

@ -2,49 +2,32 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { websocket },
bitcoin: { websocket }, } = mempoolJS();
} = mempoolJS(); // console.log(mempoolJS());
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
const ws = websocket.wsInitBrowser(); ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
ws.addEventListener('message', function incoming({data}) { if (res.blocks) {
console.log(JSON.parse(data.toString())); console.log(res.blocks);
}); }
if (res.mempoolInfo) {
websocket.wsWantDataBrowser(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); console.log(res.mempoolInfo);
}
websocket.wsTrackAddressBrowser(ws, "1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC"); if (res.transactions) {
console.log(res.transactions);
websocket.wsTrackAddressesBrowser(ws, [ }
"1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC", if (res.mempoolBlocks) {
]); console.log(res.mempoolBlocks);
}
websocket.wsTrackTransactionBrowser(ws, "01313ca0148a1bbe5676e5dd6a84e76f8b39038658bd8c333d3b2d3f7ea6dd08"); });
websocket.wsTrackRbfSummaryBrowser(ws);
websocket.wsTrackRbfBrowser(ws, true);
websocket.wsTrackMempoolBlockBrowser(ws, 1);
setTimeout(() => {
websocket.wsStopDataBrowser(ws);
websocket.wsStopTrackingAddressBrowser(ws);
websocket.wsStopTrackingAddressesBrowser(ws);
websocket.wsStopTrackingTransactionBrowser(ws);
websocket.wsStopTrackingRbfSummaryBrowser(ws);
websocket.wsStopTrackingRbfBrowser(ws);
websocket.wsStopTrackingMempoolBlockBrowser(ws);
}, 60000);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,35 +2,31 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { addresses },
liquid: { addresses }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address }); const myAddress = await addresses.getAddress({ address });
console.log(myAddress); console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address }); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address }); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ const addressTxsMempool = await addresses.getAddressTxsMempool({
address, address,
}); });
console.log(addressTxsMempool); console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address }); const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo); console.log(addressTxsUtxo);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,33 +2,29 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { assets },
liquid: { assets }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const asset_id = 'a0c358a0f6947864af3a06f3f6a2aeb304df7fd95c922f2f22d7412399ce7691'; const asset_id = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const asset = await assets.getAsset({ asset_id }); const asset = await assets.getAsset({ asset_id });
console.log(asset); console.log(asset);
const assetTxs = await assets.getAssetTxs({ const assetTxs = await assets.getAssetTxs({
asset_id, asset_id,
is_mempool: false, is_mempool: false,
}); });
console.log(assetTxs); console.log(assetTxs);
const assetSupply = await assets.getAssetSupply({ const assetSupply = await assets.getAssetSupply({
asset_id, asset_id,
decimal: false, decimal: false,
}); });
console.log(assetSupply); console.log(assetSupply);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,49 +2,45 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { blocks },
liquid: { blocks }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const hash = const hash =
'54f02bdec5509ea769c8be82aed51f689969b653d92a2812d5a36266cbfbc55e'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash }); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash }); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash }); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 0 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash }); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight({ height: 0 }); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight); console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(getBlocks); console.log(getBlocks);
const blocksTipHeight = await blocks.getBlocksTipHeight(); const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(blocksTipHeight); console.log(blocksTipHeight);
const blocksTipHash = await blocks.getBlocksTipHash(); const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash); console.log(blocksTipHash);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,22 +2,18 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { fees },
liquid: { fees }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks); console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,25 +2,21 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { mempool },
liquid: { mempool }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent(); const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent); console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids(); const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids); console.log(getMempoolTxids);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -2,46 +2,47 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { transactions },
liquid: { transactions }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const txid = const txid =
'064d1dff90cbb6fce81311f9804a737df9e3873bc4717ff6aae068fffab423ab'; '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid }); const tx = await transactions.getTx({ txid });
console.log(tx); console.log(tx);
const txStatus = await transactions.getTxStatus({ txid }); const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus); console.log(txStatus);
const txHex = await transactions.getTxHex({ txid }); const txHex = await transactions.getTxHex({ txid });
console.log(txHex); console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid }); const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
const txMerkleProof = await transactions.getTxMerkleProof({ txid }); const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({
console.log(txMerkleProof); txid,
});
console.log(txMerkleBlockProof);
const txOutspend = await transactions.getTxOutspend({ const txMerkleProof = await transactions.getTxMerkleProof({ txid });
txid, console.log(txMerkleProof);
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid }); const txOutspend = await transactions.getTxOutspend({
console.log(txOutspends); txid,
vout: 3,
});
console.log(txOutspend);
const postTx = await transactions.postTx({ txhex: txHex }); const txOutspends = await transactions.getTxOutspends({ txid });
console.log(postTx); console.log(txOutspends);
} catch (error) {
console.log(error); // const postTx = await transactions.postTx({ txid });
} // console.log(postTx);
}; };
init(); init();
</script> </script>

View File

@ -2,43 +2,32 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script src="./../../../dist/mempool.js"></script> <script src="https://mempool.space/mempool.js"></script>
<script> <script>
const init = async () => { const init = async () => {
try { const {
const { liquid: { websocket },
liquid: { websocket }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const ws = websocket.wsInitBrowser(); const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('message', function incoming({data}) { ws.on('message', function incoming(data) {
console.log(JSON.parse(data.toString())); const res = JSON.parse(data.toString());
}); if (res.blocks) {
console.log(res.blocks);
websocket.wsWantDataBrowser(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); }
if (res.mempoolInfo) {
websocket.wsTrackAddressBrowser(ws, "GiAi95k5JUPNPoDGNzSUZ8vWMijSiSMTon"); console.log(res.mempoolInfo);
}
websocket.wsTrackAddressesBrowser(ws, [ if (res.transactions) {
"GsDhxpV4Voi3XJA22bnAH4q8117hjZrQMF", console.log(res.transactions);
]); }
if (res.mempoolBlocks) {
websocket.wsTrackTransactionBrowser(ws, "23195d459a70875c3b1f9fb9082acc9f0594f1c63dac71b40f2ff7298630a421"); console.log(res.mempoolBlocks);
}
websocket.wsTrackMempoolBlockBrowser(ws, 1); });
setTimeout(() => {
websocket.wsStopDataBrowser(ws);
websocket.wsStopTrackingAddressBrowser(ws);
websocket.wsStopTrackingAddressesBrowser(ws);
websocket.wsStopTrackingTransactionBrowser(ws);
websocket.wsStopTrackingMempoolBlockBrowser(ws);
}, 60000);
} catch (error) {
console.log(error);
}
}; };
init(); init();
</script> </script>

View File

@ -0,0 +1,13 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { addresses },
} = mempoolJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
};
init();

View File

@ -0,0 +1,23 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { blocks },
} = mempoolJS();
const hash =
'000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const block = await blocks.getBlock({ hash });
console.log(block);
const myBlocks = await blocks.getBlocks({ index: 0, length: 1 });
console.log(myBlocks);
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
};
init();

View File

@ -0,0 +1,11 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { statistics },
} = mempoolJS();
const stats = await statistics.getStats();
console.log(stats);
};
init();

View File

@ -0,0 +1,17 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { transactions },
} = mempoolJS();
const txid =
'4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
};
init();

View File

@ -1,27 +1,25 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { addresses } } = mempoolJS(); bitcoin: { addresses },
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address }); const myAddress = await addresses.getAddress({ address });
console.log(myAddress); console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address }); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address }); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ address }); const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
console.log(addressTxsMempool); console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address }); const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo); console.log(addressTxsUtxo);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,49 +1,41 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { blocks },
bitcoin: { blocks }, } = mempoolJS();
} = mempoolJS();
const hash = const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash }); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash }); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash }); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash }); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeader = await blocks.getBlockHeader({ hash }); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeader); console.log(blockHeight);
const blockHeight = await blocks.getBlockHeight({ height: 0 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(blockHeight); console.log(getBlocks);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(getBlocks); console.log(blocksTipHeight);
const blocksTipHeight = await blocks.getBlocksTipHeight(); const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHeight); console.log(blocksTipHash);
const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,18 +0,0 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
const hashrate = await difficulty.getHashrate({ interval: "1m" });
console.log(hashrate);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -1,23 +1,19 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { fees },
bitcoin: { fees }, } = mempoolJS();
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks); console.log(feesMempoolBlocks);
const txid = '94bb221746f0626caf63c8dd279e07963bfe514fabe596019c95a41c5f5af97c'; const txid = 'txid';
const feesCPFP = await fees.getCPFP({ txid }); const feesCPFP = await fees.getCPFP({ txid });
console.log(feesCPFP); console.log(feesCPFP);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,59 +0,0 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const { bitcoin: { lightning } } = mempoolJS();
const node = '03d607f3e69fd032524a867b288216bfab263b6eaee4e07783799a6fe69bb84fac';
const channel = '768457472831193088';
const networkStats = await lightning.getNetworkStats();
console.log(networkStats);
const nodesInCountry = await lightning.getNodesInCountry({ country: 'fr' });
console.log(nodesInCountry);
const nodesStatsPerCountry = await lightning.getNodesStatsPerCountry();
console.log(nodesStatsPerCountry);
const nodesHostedByISP = await lightning.getNodesHostedByISP({ isp: 16509 });
console.log(nodesHostedByISP);
const ispRanking = await lightning.getISPRanking();
console.log(ispRanking);
const liquidityRanking = await lightning.getLiquidityRanking();
console.log(liquidityRanking);
const connectivityRanking = await lightning.getConnectivityRanking();
console.log(connectivityRanking);
const oldestNodes = await lightning.getOldestNodes();
console.log(oldestNodes);
const nodeStats = await lightning.getNodeStats({ public_key: node });
console.log(nodeStats);
const historicalNodeStats = await lightning.getHistoricalNodeStats({ public_key: node });
console.log(historicalNodeStats);
const channelData = await lightning.getChannel({ id: channel });
console.log(channelData);
const channelsFromTxIds = await lightning.getChannelsFromTxIds({ txId: ['c3173549f502ede6440d5c48ea74af5607d88484c7a912bbef73d430049f8af4', 'd78f0b41a263af3df91fa4171cc2f60c40196aaf8f4bde5d1c8ff4474cfe753b'] });
console.log(channelsFromTxIds);
const channelsFromNodePublicKey = await lightning.getChannelsFromNodePublicKey({ public_key: node, status: 'active'});
console.log(channelsFromNodePublicKey);
const channelsGeodata = await lightning.getChannelsGeodata();
console.log(channelsGeodata);
const channelsGeodataByPublicKey = await lightning.getChannelsGeodataByPublicKey({ public_key: node });
console.log(channelsGeodataByPublicKey);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -1,21 +1,17 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { mempool },
bitcoin: { mempool }, } = mempoolJS();
} = mempoolJS();
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent(); const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent); console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids(); const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids); console.log(getMempoolTxids);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,45 +1,41 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { transactions },
bitcoin: { transactions }, } = mempoolJS();
} = mempoolJS();
const txid = const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid }); const tx = await transactions.getTx({ txid });
console.log(tx); console.log(tx);
const txStatus = await transactions.getTxStatus({ txid }); const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus); console.log(txStatus);
const txHex = await transactions.getTxHex({ txid }); const txHex = await transactions.getTxHex({ txid });
console.log(txHex); console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid }); const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid }); const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleBlockProof); console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof({ txid }); const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof); console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({ const txOutspend = await transactions.getTxOutspend({
txid, txid,
vout: 3, vout: 3,
}); });
console.log(txOutspend); console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid }); const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends); console.log(txOutspends);
// const postTx = await transactions.postTx({ txhex }); // const postTx = await transactions.postTx({ txid });
// console.log(postTx); // console.log(postTx);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,45 +1,28 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { bitcoin: { websocket },
bitcoin: { websocket }, } = mempoolJS();
} = mempoolJS();
const ws = websocket.wsInit(); const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('message', function incoming({data}) { ws.on('message', function incoming(data) {
console.log(JSON.parse(data.toString())); const res = JSON.parse(data.toString());
}); if (res.blocks) {
console.log(res.blocks);
websocket.wsWantData(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); }
if (res.mempoolInfo) {
websocket.wsTrackAddress(ws, "1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC"); console.log(res.mempoolInfo);
}
websocket.wsTrackAddresses(ws, [ if (res.transactions) {
"1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC", console.log(res.transactions);
]); }
if (res.mempoolBlocks) {
websocket.wsTrackTransaction(ws, "01313ca0148a1bbe5676e5dd6a84e76f8b39038658bd8c333d3b2d3f7ea6dd08"); console.log(res.mempoolBlocks);
}
websocket.wsTrackRbfSummary(ws); });
};
websocket.wsTrackRbf(ws, true);
websocket.wsTrackMempoolBlock(ws, 1);
setTimeout(() => {
websocket.wsStopData(ws);
websocket.wsStopTrackingAddress(ws);
websocket.wsStopTrackingAddresses(ws);
websocket.wsStopTrackingTransaction(ws);
websocket.wsStopTrackingRbfSummary(ws);
websocket.wsStopTrackingRbf(ws);
websocket.wsStopTrackingMempoolBlock(ws);
}, 60000);
} catch (error) {
console.log(error);
}
}
init(); init();

View File

@ -1,29 +1,25 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { addresses },
liquid: { addresses }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address }); const myAddress = await addresses.getAddress({ address });
console.log(myAddress); console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address }); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address }); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ address }); const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
console.log(addressTxsMempool); console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address }); const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo); console.log(addressTxsUtxo);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,24 +1,20 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { assets },
liquid: { assets }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const asset_id = const asset_id =
'6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d';
const asset = await assets.getAsset({ asset_id }); const asset = await assets.getAsset({ asset_id });
console.log(asset); console.log(asset);
const assetTxs = await assets.getAssetTxs({ asset_id, is_mempool: false }); const assetTxs = await assets.getAssetTxs({ asset_id, is_mempool: false });
console.log(assetTxs); console.log(assetTxs);
const assetSupply = await assets.getAssetSupply({ asset_id, decimal: false }); const assetSupply = await assets.getAssetSupply({ asset_id, decimal: false });
console.log(assetSupply); console.log(assetSupply);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,45 +1,41 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { blocks },
liquid: { blocks }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const hash = const hash =
'5ec96b63f95aad27391a8a41f1dce2161d48c4f26aeb1f72695a12c98a005e1f'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash }); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash }); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash }); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 1 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash }); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight({ height: 0 }); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight); console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(getBlocks); console.log(getBlocks);
const blocksTipHeight = await blocks.getBlocksTipHeight(); const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(blocksTipHeight); console.log(blocksTipHeight);
const blocksTipHash = await blocks.getBlocksTipHash(); const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash); console.log(blocksTipHash);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,18 +1,14 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { fees },
liquid: { fees }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks); console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,21 +1,17 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { mempool },
liquid: { mempool }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent(); const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent); console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids(); const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids); console.log(getMempoolTxids);
} catch (error) {
console.log(error);
}
}; };
init(); init();

View File

@ -1,42 +1,41 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
const { liquid: { transactions },
liquid: { transactions }, } = mempoolJS();
} = mempoolJS( { hostname: 'liquid.network' } );
const txid = const txid =
'555fbc3ca784903b238fdadc92515577dfa9124185259c5d9a773508bbc365e5'; '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid }); const tx = await transactions.getTx({ txid });
console.log(tx); console.log(tx);
const txStatus = await transactions.getTxStatus({ txid }); const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus); console.log(txStatus);
const txHex = await transactions.getTxHex({ txid }); const txHex = await transactions.getTxHex({ txid });
console.log(txHex); console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid }); const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
const txMerkleProof = await transactions.getTxMerkleProof({ txid }); const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleProof); console.log(txMerkleBlockProof);
const txOutspend = await transactions.getTxOutspend({ const txMerkleProof = await transactions.getTxMerkleProof({ txid });
txid, console.log(txMerkleProof);
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid }); const txOutspend = await transactions.getTxOutspend({
console.log(txOutspends); txid,
vout: 3,
});
console.log(txOutspend);
const postTx = await transactions.postTx({ txhex: txHex }); const txOutspends = await transactions.getTxOutspends({ txid });
console.log(postTx); console.log(txOutspends);
} catch (error) {
console.log(error); // const postTx = await transactions.postTx({ txid });
} // console.log(postTx);
}; };
init(); init();

View File

@ -1,38 +1,28 @@
import mempoolJS from "./../../../src/index"; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
try { const {
liquid: { websocket },
} = mempoolJS();
const { liquid: { websocket } } = mempoolJS( { hostname: 'liquid.network' } ); const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
const ws = websocket.wsInit(); ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString());
ws.addEventListener('message', function incoming({data}) { if (res.blocks) {
console.log(JSON.parse(data.toString())); console.log(res.blocks);
}); }
if (res.mempoolInfo) {
websocket.wsWantData(ws, ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart']); console.log(res.mempoolInfo);
}
websocket.wsTrackAddress(ws, "GiAi95k5JUPNPoDGNzSUZ8vWMijSiSMTon"); if (res.transactions) {
console.log(res.transactions);
websocket.wsTrackAddresses(ws, [ }
"GsDhxpV4Voi3XJA22bnAH4q8117hjZrQMF", if (res.mempoolBlocks) {
]); console.log(res.mempoolBlocks);
}
websocket.wsTrackTransaction(ws, "23195d459a70875c3b1f9fb9082acc9f0594f1c63dac71b40f2ff7298630a421"); });
};
websocket.wsTrackMempoolBlock(ws, 1);
setTimeout(() => {
websocket.wsStopData(ws);
websocket.wsStopTrackingAddress(ws);
websocket.wsStopTrackingAddresses(ws);
websocket.wsStopTrackingTransaction(ws);
websocket.wsStopTrackingMempoolBlock(ws);
}, 60000);
} catch (error) {
console.log(error);
}
}
init(); init();

View File

@ -1,5 +1,5 @@
{ {
"watch": ["src", "examples"], "watch": ["src"],
"ext": "ts,json", "ext": "ts,json",
"ignore": ["src/**/*.spec.ts"], "ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/index.ts" "exec": "ts-node ./src/index.ts"

10234
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,21 @@
{ {
"name": "@mempool/mempool.js", "name": "@mempool/mempool.js",
"version": "3.0.0", "version": "2.2.0",
"description": "NPM package module for Mempool APIs.", "description": "NPM package module for Mempool APIs.",
"main": "lib/index.js", "main": "lib/index.js",
"keywords": [ "keywords": [
"axios", "axios",
"bitcoin", "bitcoin",
"bisq",
"liquid", "liquid",
"mainet", "mainet",
"testnet", "testnet",
"testnet4",
"signet", "signet",
"blockchain", "blockchain",
"html", "html",
"mempool.space", "mempool-space",
"mempool.js", "mempool-js",
"mempool", "mempool",
"websocket",
"nodejs", "nodejs",
"typescript" "typescript"
], ],
@ -25,14 +24,13 @@
"private": false, "private": false,
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/mempool/mempool.js.git" "url": "git://github.com/mempool/mempool-js.git"
}, },
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"scripts": { "scripts": {
"start": "ts-node src/index.ts", "start": "ts-node src/index.ts",
"dev": "nodemon src/index.ts", "dev": "nodemon src/index.ts",
"build": "tsc", "build": "tsc | browserify lib/index.js --standalone mempoolJS > dist/mempool.js | browserify -p tinyify lib/index.js --standalone mempoolJS > dist/mempool.min.js",
"export-mempool-js": "tsc | browserify -p esmify lib/index.js --standalone mempoolJS > dist/mempool.js | browserify -p tinyify -p esmify lib/index.js --standalone mempoolJS > dist/mempool.min.js",
"prepare": "npm run build", "prepare": "npm run build",
"postversion": "git push && git push --tags" "postversion": "git push && git push --tags"
}, },
@ -40,26 +38,20 @@
"lib/**/*" "lib/**/*"
], ],
"dependencies": { "dependencies": {
"axios": "1.13.2", "axios": "^0.21.1",
"ws": "^8.18.3" "ws": "^7.4.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^24.10.1", "@types/node": "^14.14.25",
"@types/websocket": "^1.0.10", "@types/websocket": "^1.0.2",
"@types/ws": "^8.18.1", "@types/ws": "^7.4.1",
"@typescript-eslint/eslint-plugin": "^8.46.4", "@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^8.46.4", "@typescript-eslint/parser": "^4.14.2",
"browserify": "^17.0.1", "browserify": "^17.0.0",
"eslint": "^9.39.1", "eslint": "^7.19.0",
"esmify": "^2.1.1", "nodemon": "^2.0.7",
"nodemon": "^3.1.11", "tinyify": "^3.0.0",
"tinyify": "^4.0.0", "typescript": "^4.1.3"
"ts-node": "^10.9.2",
"typescript": "^5.9.3"
},
"overrides": {
"terser": "^5.14.2",
"babel-traverse": "npm:@babel/traverse@^7.23.2"
}, },
"license": "MIT" "license": "MIT"
} }

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

@ -12,11 +12,7 @@ export const useAddresses = (api: AxiosInstance): AddressInstance => {
return data; return data;
}; };
const getAddressTxs = async (params: { address: string, after_txid?: string }) => { const getAddressTxs = async (params: { address: string }) => {
if (params.after_txid) {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs?after_txid=${params.after_txid}`);
return data;
}
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`); const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data; return data;
}; };

View File

@ -8,7 +8,7 @@ import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockInstance => { export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (params: { hash: string }) => { const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/v1/block/${params.hash}`); const { data } = await api.get<Block>(`/block/${params.hash}`);
return data; return data;
}; };
@ -44,18 +44,13 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
return data; 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 getBlockHeight = async (params: { height: number }) => {
const { data } = await api.get<string>(`/block-height/${params.height}`); const { data } = await api.get<string>(`/block-height/${params.height}`);
return data; return data;
}; };
const getBlocks = async (params: { start_height?: number }) => { const getBlocks = async (params: { start_height?: number }) => {
const { data } = await api.get<Block[]>(`/v1/blocks/${params.start_height}`); const { data } = await api.get<Block>(`/blocks/${params.start_height}`);
return data; return data;
}; };
@ -77,7 +72,6 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
getBlockTxid, getBlockTxid,
getBlockTxids, getBlockTxids,
getBlockRaw, getBlockRaw,
getBlockHeader,
getBlockHeight, getBlockHeight,
getBlocksTipHash, getBlocksTipHash,
getBlocksTipHeight, getBlocksTipHeight,

View File

@ -1,23 +0,0 @@
import { AxiosInstance } from 'axios';
import {
Adjustment,
DifficultyInstance,
Hashrate,
} from '../../interfaces/bitcoin/difficulty';
export const useDifficulty = (api: AxiosInstance): DifficultyInstance => {
const getDifficultyAdjustment = async () => {
const { data } = await api.get<Adjustment>(`/v1/difficulty-adjustment`);
return data;
};
const getHashrate = async (params: { interval: string }): Promise<Hashrate> => {
const { data } = await api.get<Hashrate>(`/v1/mining/hashrate/${params.interval}`);
return data;
}
return {
getDifficultyAdjustment,
getHashrate,
};
};

View File

@ -1,97 +0,0 @@
import { AxiosInstance } from 'axios';
import { Channel, LightningInstance, NetworkStats, Node, NodeStats } from '../../interfaces/bitcoin/lightning';
export const useLightning = (api: AxiosInstance): LightningInstance => {
const getNetworkStats = async () => {
const { data } = await api.get<NetworkStats>(`/v1/lightning/statistics/latest`);
return data;
}
const getNodesInCountry = async (params: { country: string }) => {
const { data } = await api.get<Node[]>(`/v1/lightning/nodes/country/${params.country}`);
return data;
}
const getNodesStatsPerCountry = async () => {
const { data } = await api.get<any>(`/v1/lightning/nodes/countries`);
return data;
}
const getNodesHostedByISP = async (params: { isp: number }) => {
const { data } = await api.get<Node[]>(`/v1/lightning/nodes/isp/${params.isp}`);
return data;
}
const getISPRanking = async () => {
const { data } = await api.get<any>(`/v1/lightning/nodes/isp-ranking`);
return data;
}
const getLiquidityRanking = async () => {
const { data } = await api.get<Node[]>(`/v1/lightning/nodes/rankings/liquidity`);
return data;
}
const getConnectivityRanking = async () => {
const { data } = await api.get<Node[]>(`/v1/lightning/nodes/rankings/connectivity`);
return data;
}
const getOldestNodes = async () => {
const { data } = await api.get<Node[]>(`/v1/lightning/nodes/rankings/age`);
return data;
}
const getNodeStats = async (params: { public_key: string }) => {
const { data } = await api.get<Node>(`/v1/lightning/nodes/${params.public_key}`);
return data;
}
const getHistoricalNodeStats = async (params: { public_key: string }) => {
const { data } = await api.get<NodeStats[]>(`/v1/lightning/nodes/${params.public_key}/statistics`);
return data;
}
const getChannel = async (params: { id: string }) => {
const { data } = await api.get<Channel>(`/v1/lightning/channels/${params.id}`);
return data;
}
const getChannelsFromTxIds = async (params: { txId: string[] }) => {
const { data } = await api.get<any[]>(`/v1/lightning/channels/txids?txId[]=${params.txId.join('&txId[]=')}`);
return data;
}
const getChannelsFromNodePublicKey = async (params: { public_key: string, status: string, index?: number }) => {
const { data } = await api.get<Channel[]>(`/v1/lightning/channels?public_key=${params.public_key}&status=${params.status}&index=${params?.index}`);
return data;
}
const getChannelsGeodata = async () => {
const { data } = await api.get<any[]>(`/v1/lightning/channels-geo`);
return data;
}
const getChannelsGeodataByPublicKey = async (params: { public_key: string }) => {
const { data } = await api.get<any[]>(`/v1/lightning/channels-geo/${params.public_key}`);
return data;
}
return {
getNetworkStats,
getNodesInCountry,
getNodesStatsPerCountry,
getNodesHostedByISP,
getISPRanking,
getLiquidityRanking,
getConnectivityRanking,
getOldestNodes,
getNodeStats,
getHistoricalNodeStats,
getChannel,
getChannelsFromTxIds,
getChannelsFromNodePublicKey,
getChannelsGeodata,
getChannelsGeodataByPublicKey,
};
};

View File

@ -36,7 +36,7 @@ export const useTransactions = (api: AxiosInstance): TxInstance => {
}; };
const getTxMerkleProof = async (params: { txid: string }) => { const getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<TxMerkleProof>( const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof` `/tx/${params.txid}/merkle-proof`
); );
return data; return data;
@ -56,8 +56,8 @@ export const useTransactions = (api: AxiosInstance): TxInstance => {
return data; return data;
}; };
const postTx = async (params: { txhex: string }) => { const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, params.txhex ); const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data; return data;
}; };

View File

@ -1,86 +1,14 @@
import { WsInstance } from '../../interfaces/bitcoin/websockets'; import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import { import wsClient from '../../services/ws/client';
wsInit as wsInitBrowser, import wsServer from '../../services/ws/server';
wsWantData as wsWantDataBrowser,
wsStopData as wsStopDataBrowser,
wsTrackAddress as wsTrackAddressBrowser,
wsStopTrackingAddress as wsStopTrackingAddressBrowser,
wsTrackAddresses as wsTrackAddressesBrowser,
wsStopTrackingAddresses as wsStopTrackingAddressesBrowser,
wsTrackTransaction as wsTrackTransactionBrowser,
wsStopTrackingTransaction as wsStopTrackingTransactionBrowser,
wsTrackRbfSummary as wsTrackRbfSummaryBrowser,
wsStopTrackingRbfSummary as wsStopTrackingRbfSummaryBrowser,
wsTrackRbf as wsTrackRbfBrowser,
wsStopTrackingRbf as wsStopTrackingRbfBrowser,
wsTrackMempoolBlock as wsTrackMempoolBlockBrowser,
wsStopTrackingMempoolBlock as wsStopTrackingMempoolBlockBrowser,
} from '../../services/ws/ws-client-browser';
import {
wsInit,
wsWantData,
wsStopData,
wsTrackAddress,
wsStopTrackingAddress,
wsTrackAddresses,
wsStopTrackingAddresses,
wsTrackTransaction,
wsStopTrackingTransaction,
wsTrackRbfSummary,
wsStopTrackingRbfSummary,
wsTrackRbf,
wsStopTrackingRbf,
wsTrackMempoolBlock,
wsStopTrackingMempoolBlock
} from '../../services/ws/ws-client-node';
import WebSocketServer from 'ws';
export const useWebsocket = (hostname: string, network: string, protocol: string | undefined): WsInstance => { const defaultWs = 'wss://mempool.space/api/v1/ws';
if (!protocol) { export const useWebsocket = (hostname?: string): WsInstance => {
hostname?.includes('localhost') ? protocol = 'ws' : protocol = 'wss';
} else if (protocol === 'http' || protocol === 'ws') {
protocol = 'ws';
} else {
protocol = 'wss';
}
if (network && ['testnet', 'testnet4', 'signet'].includes(network)) {
network = `/${network}`;
} else {
network = '';
}
const wsEndpoint = `${protocol}://${hostname}${network}/api/v1/ws`
return { return {
wsInit: () => wsInit(wsEndpoint), initClient: ({ options }: WsInterface) =>
wsInitBrowser: () => wsInitBrowser(wsEndpoint), wsClient(options, defaultWs, hostname),
wsWantData: (ws: WebSocketServer, options: string[]) => wsWantData(ws, options), initServer: ({ options }: WsInterface) =>
wsWantDataBrowser: (ws: WebSocket, options: string[]) => wsWantDataBrowser(ws, options), wsServer(options, defaultWs, hostname),
wsStopData: (ws: WebSocketServer) => wsStopData(ws),
wsStopDataBrowser: (ws: WebSocket) => wsStopDataBrowser(ws),
wsTrackAddress: (ws: WebSocketServer, address: string) => wsTrackAddress(ws, address),
wsTrackAddressBrowser: (ws: WebSocket, address: string) => wsTrackAddressBrowser(ws, address),
wsStopTrackingAddress: (ws: WebSocketServer) => wsStopTrackingAddress(ws),
wsStopTrackingAddressBrowser: (ws: WebSocket) => wsStopTrackingAddressBrowser(ws),
wsTrackAddresses: (ws: WebSocketServer, addresses: string[]) => wsTrackAddresses(ws, addresses),
wsTrackAddressesBrowser: (ws: WebSocket, addresses: string[]) => wsTrackAddressesBrowser(ws, addresses),
wsStopTrackingAddresses: (ws: WebSocketServer) => wsStopTrackingAddresses(ws),
wsStopTrackingAddressesBrowser: (ws: WebSocket) => wsStopTrackingAddressesBrowser(ws),
wsTrackTransaction: (ws: WebSocketServer, txid: string) => wsTrackTransaction(ws, txid),
wsTrackTransactionBrowser: (ws: WebSocket, txid: string) => wsTrackTransactionBrowser(ws, txid),
wsStopTrackingTransaction: (ws: WebSocketServer) => wsStopTrackingTransaction(ws),
wsStopTrackingTransactionBrowser: (ws: WebSocket) => wsStopTrackingTransactionBrowser(ws),
wsTrackRbfSummary: (ws: WebSocketServer) => wsTrackRbfSummary(ws),
wsTrackRbfSummaryBrowser: (ws: WebSocket) => wsTrackRbfSummaryBrowser(ws),
wsStopTrackingRbfSummary: (ws: WebSocketServer) => wsStopTrackingRbfSummary(ws),
wsStopTrackingRbfSummaryBrowser: (ws: WebSocket) => wsStopTrackingRbfSummaryBrowser(ws),
wsTrackRbf: (ws: WebSocketServer, fullRbf: boolean) => wsTrackRbf(ws, fullRbf),
wsTrackRbfBrowser: (ws: WebSocket, fullRbf: boolean) => wsTrackRbfBrowser(ws, fullRbf),
wsStopTrackingRbf: (ws: WebSocketServer) => wsStopTrackingRbf(ws),
wsStopTrackingRbfBrowser: (ws: WebSocket) => wsStopTrackingRbfBrowser(ws),
wsTrackMempoolBlock: (ws: WebSocketServer, index: number) => wsTrackMempoolBlock(ws, index),
wsTrackMempoolBlockBrowser: (ws: WebSocket, index: number) => wsTrackMempoolBlockBrowser(ws, index),
wsStopTrackingMempoolBlock: (ws: WebSocketServer) => wsStopTrackingMempoolBlock(ws),
wsStopTrackingMempoolBlockBrowser: (ws: WebSocket) => wsStopTrackingMempoolBlockBrowser(ws),
}; };
}; };

View File

@ -12,11 +12,7 @@ export const useAddresses = (api: AxiosInstance): AddressInstance => {
return data; return data;
}; };
const getAddressTxs = async (params: { address: string, after_txid?: string }) => { const getAddressTxs = async (params: { address: string }) => {
if (params.after_txid) {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs?after_txid=${params.after_txid}`);
return data;
}
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`); const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data; return data;
}; };

View File

@ -7,11 +7,6 @@ export const useAssets = (api: AxiosInstance): AssetsInstance => {
return data; return data;
}; };
const getAssetIcon = async (params: { asset_id: string }) => {
const { data } = await api.get(`/v1/asset/${params.asset_id}/icon`);
return data;
};
const getAssetTxs = async (params: { const getAssetTxs = async (params: {
asset_id: string; asset_id: string;
is_mempool: boolean; is_mempool: boolean;
@ -34,16 +29,9 @@ export const useAssets = (api: AxiosInstance): AssetsInstance => {
return data; return data;
}; };
const getAssetsIcons = async () => {
const { data } = await api.get<string[]>(`/v1/assets/icons`);
return data;
};
return { return {
getAsset, getAsset,
getAssetIcon,
getAssetTxs, getAssetTxs,
getAssetSupply, getAssetSupply,
getAssetsIcons,
}; };
}; };

View File

@ -2,13 +2,13 @@ import { AxiosInstance } from 'axios';
import { import {
Block, Block,
BlockStatus, BlockStatus,
BlockLiquidInstance, BlockInstance,
} from '../../interfaces/liquid/blocks'; } from '../../interfaces/bitcoin/blocks';
import { Tx } from '../../interfaces/bitcoin/transactions'; import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockLiquidInstance => { export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (params: { hash: string }) => { const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/v1/block/${params.hash}`); const { data } = await api.get<Block>(`/block/${params.hash}`);
return data; return data;
}; };
@ -50,7 +50,7 @@ export const useBlocks = (api: AxiosInstance): BlockLiquidInstance => {
}; };
const getBlocks = async (params: { start_height?: number }) => { const getBlocks = async (params: { start_height?: number }) => {
const { data } = await api.get<Block[]>(`/v1/blocks/${params.start_height}`); const { data } = await api.get<Block>(`/blocks/${params.start_height}`);
return data; return data;
}; };

View File

@ -4,10 +4,10 @@ import {
TxStatus, TxStatus,
TxMerkleProof, TxMerkleProof,
TxOutspend, TxOutspend,
TxLiquidInstance, TxInstance,
} from '../../interfaces/liquid/transactions'; } from '../../interfaces/bitcoin/transactions';
export const useTransactions = (api: AxiosInstance): TxLiquidInstance => { export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (params: { txid: string }) => { const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`); const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data; return data;
@ -28,8 +28,15 @@ export const useTransactions = (api: AxiosInstance): TxLiquidInstance => {
return data; 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 getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<TxMerkleProof>( const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof` `/tx/${params.txid}/merkle-proof`
); );
return data; return data;
@ -49,8 +56,8 @@ export const useTransactions = (api: AxiosInstance): TxLiquidInstance => {
return data; return data;
}; };
const postTx = async (params: { txhex: string }) => { const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, params.txhex ); const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data; return data;
}; };
@ -59,6 +66,7 @@ export const useTransactions = (api: AxiosInstance): TxLiquidInstance => {
getTxStatus, getTxStatus,
getTxHex, getTxHex,
getTxRaw, getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof, getTxMerkleProof,
getTxOutspend, getTxOutspend,
getTxOutspends, getTxOutspends,

View File

@ -1,69 +1,14 @@
import { WsLiquidInstance } from '../../interfaces/liquid/websockets'; import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import { import wsClient from '../../services/ws/client';
wsInit as wsInitBrowser, import wsServer from '../../services/ws/server';
wsWantData as wsWantDataBrowser,
wsStopData as wsStopDataBrowser,
wsTrackAddress as wsTrackAddressBrowser,
wsStopTrackingAddress as wsStopTrackingAddressBrowser,
wsTrackAddresses as wsTrackAddressesBrowser,
wsStopTrackingAddresses as wsStopTrackingAddressesBrowser,
wsTrackTransaction as wsTrackTransactionBrowser,
wsStopTrackingTransaction as wsStopTrackingTransactionBrowser,
wsTrackMempoolBlock as wsTrackMempoolBlockBrowser,
wsStopTrackingMempoolBlock as wsStopTrackingMempoolBlockBrowser,
} from '../../services/ws/ws-client-browser';
import {
wsInit,
wsWantData,
wsStopData,
wsTrackAddress,
wsStopTrackingAddress,
wsTrackAddresses,
wsStopTrackingAddresses,
wsTrackTransaction,
wsStopTrackingTransaction,
wsTrackMempoolBlock,
wsStopTrackingMempoolBlock
} from '../../services/ws/ws-client-node';
import WebSocketServer from 'ws';
export const useWebsocket = (hostname: string, network: string, protocol: string | undefined): WsLiquidInstance => { const defaultWs = 'wss://mempool.space/liquid/api/v1/ws';
if (!protocol) { export const useWebsocket = (hostname?: string): WsInstance => {
hostname?.includes('localhost') ? protocol = 'ws' : protocol = 'wss';
} else if (protocol === 'http' || protocol === 'ws') {
protocol = 'ws';
} else {
protocol = 'wss';
}
if (network && ['testnet', 'liquidtestnet'].includes(network)) {
network = `/liquidtestnet`;
} else {
network = '/liquid';
}
const wsEndpoint = `${protocol}://${hostname}${network}/api/v1/ws`
return { return {
wsInit: () => wsInit(wsEndpoint), initClient: ({ options }: WsInterface) =>
wsInitBrowser: () => wsInitBrowser(wsEndpoint), wsClient(options, defaultWs, hostname),
wsWantData: (ws: WebSocketServer, options: string[]) => wsWantData(ws, options), initServer: ({ options }: WsInterface) =>
wsWantDataBrowser: (ws: WebSocket, options: string[]) => wsWantDataBrowser(ws, options), wsServer(options, defaultWs, hostname),
wsStopData: (ws: WebSocketServer) => wsStopData(ws), };
wsStopDataBrowser: (ws: WebSocket) => wsStopDataBrowser(ws),
wsTrackAddress: (ws: WebSocketServer, address: string) => wsTrackAddress(ws, address),
wsTrackAddressBrowser: (ws: WebSocket, address: string) => wsTrackAddressBrowser(ws, address),
wsStopTrackingAddress: (ws: WebSocketServer) => wsStopTrackingAddress(ws),
wsStopTrackingAddressBrowser: (ws: WebSocket) => wsStopTrackingAddressBrowser(ws),
wsTrackAddresses: (ws: WebSocketServer, addresses: string[]) => wsTrackAddresses(ws, addresses),
wsTrackAddressesBrowser: (ws: WebSocket, addresses: string[]) => wsTrackAddressesBrowser(ws, addresses),
wsStopTrackingAddresses: (ws: WebSocketServer) => wsStopTrackingAddresses(ws),
wsStopTrackingAddressesBrowser: (ws: WebSocket) => wsStopTrackingAddressesBrowser(ws),
wsTrackTransaction: (ws: WebSocketServer, txid: string) => wsTrackTransaction(ws, txid),
wsTrackTransactionBrowser: (ws: WebSocket, txid: string) => wsTrackTransactionBrowser(ws, txid),
wsStopTrackingTransaction: (ws: WebSocketServer) => wsStopTrackingTransaction(ws),
wsStopTrackingTransactionBrowser: (ws: WebSocket) => wsStopTrackingTransactionBrowser(ws),
wsTrackMempoolBlock: (ws: WebSocketServer, index: number) => wsTrackMempoolBlock(ws, index),
wsTrackMempoolBlockBrowser: (ws: WebSocket, index: number) => wsTrackMempoolBlockBrowser(ws, index),
wsStopTrackingMempoolBlock: (ws: WebSocketServer) => wsStopTrackingMempoolBlock(ws),
wsStopTrackingMempoolBlockBrowser: (ws: WebSocket) => wsStopTrackingMempoolBlockBrowser(ws), };
}; };

View File

@ -1,15 +1,22 @@
import { MempoolConfig, MempoolReturn } from './interfaces/index'; import { MempoolConfig, MempoolReturn } from './interfaces/index';
import { makeBitcoinAPI, makeLiquidAPI } from './services/api/index'; import {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
} from './services/api/index';
import { useAddresses } from './app/bitcoin/addresses'; import { useAddresses } from './app/bitcoin/addresses';
import { useBlocks } from './app/bitcoin/blocks'; import { useBlocks } from './app/bitcoin/blocks';
import { useDifficulty } from './app/bitcoin/difficulty';
import { useFees } from './app/bitcoin/fees'; import { useFees } from './app/bitcoin/fees';
import { useLightning } from './app/bitcoin/lightning';
import { useMempool } from './app/bitcoin/mempool'; import { useMempool } from './app/bitcoin/mempool';
import { useTransactions } from './app/bitcoin/transactions'; import { useTransactions } from './app/bitcoin/transactions';
import { useWebsocket } from './app/bitcoin/websocket'; import { useWebsocket } from './app/bitcoin/websocket';
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 { useAssets as useAssetsLiquid } from './app/liquid/assets';
import { useAddresses as useAddressesLiquid } from './app/liquid/addresses'; import { useAddresses as useAddressesLiquid } from './app/liquid/addresses';
import { useBlocks as useBlocksLiquid } from './app/liquid/blocks'; import { useBlocks as useBlocksLiquid } from './app/liquid/blocks';
@ -22,7 +29,7 @@ const hostnameEndpointDefault = 'mempool.space';
const networkEndpointDefault = 'main'; const networkEndpointDefault = 'main';
const mempool = ( const mempool = (
{ hostname, network, protocol, config }: MempoolConfig = { { hostname, network }: MempoolConfig = {
hostname: hostnameEndpointDefault, hostname: hostnameEndpointDefault,
network: networkEndpointDefault, network: networkEndpointDefault,
} }
@ -30,28 +37,24 @@ const mempool = (
if (!hostname) hostname = hostnameEndpointDefault; if (!hostname) hostname = hostnameEndpointDefault;
if (!network) network = networkEndpointDefault; if (!network) network = networkEndpointDefault;
const { api: apiBitcoin } = makeBitcoinAPI({ const { api: apiBitcoin } = makeBitcoinAPI({ hostname, network });
hostname, const { api: apiBisq } = makeBisqAPI(hostname);
network, const { api: apiLiquid } = makeLiquidAPI(hostname);
protocol,
config,
});
const { api: apiLiquid } = makeLiquidAPI({
hostname,
network,
protocol,
config,
});
return { return {
bitcoin: { bitcoin: {
addresses: useAddresses(apiBitcoin), addresses: useAddresses(apiBitcoin),
blocks: useBlocks(apiBitcoin), blocks: useBlocks(apiBitcoin),
difficulty: useDifficulty(apiBitcoin),
fees: useFees(apiBitcoin), fees: useFees(apiBitcoin),
lightning: useLightning(apiBitcoin),
mempool: useMempool(apiBitcoin), mempool: useMempool(apiBitcoin),
transactions: useTransactions(apiBitcoin), transactions: useTransactions(apiBitcoin),
websocket: useWebsocket(hostname, network, protocol), websocket: useWebsocket(hostname),
},
bisq: {
statistics: useStatisticsBisq(apiBisq),
addresses: useAddressesBisq(apiBisq),
blocks: useBlocksBisq(apiBisq),
transactions: useTransactionsBisq(apiBisq),
}, },
liquid: { liquid: {
addresses: useAddressesLiquid(apiLiquid), addresses: useAddressesLiquid(apiLiquid),
@ -60,7 +63,7 @@ const mempool = (
fees: useFeesLiquid(apiLiquid), fees: useFeesLiquid(apiLiquid),
mempool: useMempoolLiquid(apiLiquid), mempool: useMempoolLiquid(apiLiquid),
transactions: useTransactionsLiquid(apiLiquid), transactions: useTransactionsLiquid(apiLiquid),
websocket: useWebsocketLiquid(hostname, network, protocol), websocket: useWebsocketLiquid(hostname),
}, },
}; };
}; };

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

@ -23,7 +23,7 @@ export interface AddressTxsUtxo {
export interface AddressInstance { export interface AddressInstance {
getAddress: (params: { address: string }) => Promise<Address>; getAddress: (params: { address: string }) => Promise<Address>;
getAddressTxs: (params: { address: string, after_txid?: string }) => Promise<Tx[]>; getAddressTxs: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsChain: (params: { address: string }) => Promise<Tx[]>; getAddressTxsChain: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsMempool: (params: { address: string }) => Promise<Tx[]>; getAddressTxsMempool: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsUtxo: (params: { address: string }) => Promise<AddressTxsUtxo[]>; getAddressTxsUtxo: (params: { address: string }) => Promise<AddressTxsUtxo[]>;

View File

@ -14,7 +14,6 @@ export interface Block {
nonce: number; nonce: number;
bits: number; bits: number;
difficulty: number; difficulty: number;
extras: any;
} }
export interface BlockStatus { export interface BlockStatus {
@ -25,13 +24,12 @@ export interface BlockStatus {
export interface BlockInstance { export interface BlockInstance {
getBlock: (params: { hash: string }) => Promise<Block>; getBlock: (params: { hash: string }) => Promise<Block>;
getBlocks: (params: { start_height?: number }) => Promise<Block[]>; getBlocks: (params: { start_height?: number }) => Promise<Block>;
getBlockStatus: (params: { hash: string }) => Promise<BlockStatus>; getBlockStatus: (params: { hash: string }) => Promise<BlockStatus>;
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>; getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
getBlockTxids: (params: { hash: string }) => Promise<string[]>; getBlockTxids: (params: { hash: string }) => Promise<string[]>;
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>; getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
getBlockRaw: (params: { hash: string }) => Promise<string>; getBlockRaw: (params: { hash: string }) => Promise<string>;
getBlockHeader: (params: { hash: string }) => Promise<string>;
getBlockHeight: (params: { height: number }) => Promise<string>; getBlockHeight: (params: { height: number }) => Promise<string>;
getBlocksTipHeight: () => Promise<number>; getBlocksTipHeight: () => Promise<number>;
getBlocksTipHash: () => Promise<string>; getBlocksTipHash: () => Promise<string>;

View File

@ -1,37 +0,0 @@
export interface Adjustment {
progressPercent: number,
difficultyChange: number,
estimatedRetargetDate: number,
remainingBlocks: number,
remainingTime: number,
previousRetarget: number,
nextRetargetHeight: number,
timeAvg: number,
timeOffset: number,
expectedBlocks: number,
}
export interface Hashrate {
hashrates: HashRateData[],
difficulty: DifficultyData[],
currentHashrate: number,
currentDifficulty: number,
}
export interface HashRateData {
timestamp: number,
avgHashrate: number
}
export interface DifficultyData {
time: number,
height: number,
difficulty: number,
adjustment: number
}
export interface DifficultyInstance {
getDifficultyAdjustment: () => Promise<Adjustment>;
getHashrate: (params: { interval: string }) => Promise<Hashrate>;
}

View File

@ -1,98 +0,0 @@
import { Tx, TxStatus } from './transactions';
export interface NetworkStatsEntry {
added: string;
avg_base_fee_mtokens: number;
avg_capacity: number;
avg_fee_rate: number;
channel_count: number;
clearnet_nodes: number;
clearnet_tor_nodes: number;
id: number;
med_base_fee_mtokens: number;
med_capacity: number;
med_fee_rate: number;
node_count: number;
tor_nodes: number;
total_capacity: number;
unannounced_nodes: number;
}
export interface NetworkStats {
latest: NetworkStatsEntry;
previous: NetworkStatsEntry;
}
export interface Node {
alias: string;
public_key: string;
channels: number;
capacity: number;
updatedAt: string;
base_fee_mtokens?: number;
cltv_delta?: number;
fee_rate?: number;
is_disabled?: boolean;
max_htlc_mtokens?: number;
min_htlc_mtokens?: number;
longitude?: number;
latitude?: number;
funding_balance?: number;
closing_balance?: number;
city?: any;
country?: any;
iso_code?: any;
subdivision?: any;
first_seen?: number;
isp?: string;
features?: any[];
featuresBit?: string;
active_channel_count?: number;
opened_channel_count?: number;
closed_channel_count?: number;
}
export interface NodeStats {
added: number;
capacity: number;
channels: number;
}
export interface Channel {
id: number;
short_id: string;
capacity: number;
transaction_id: string;
transaction_vout: number;
closing_transaction_id: string;
closing_reason: number;
closing_fee: number;
updated_at: string;
closing_date?: string;
created: string;
status: number;
funding_ratio?: number;
closed_by?: string;
single_funded?: boolean;
node_left: Node,
node_right: Node,
}
export interface LightningInstance {
getNetworkStats: () => Promise<NetworkStats>;
getNodesInCountry: (params: { country: string }) => Promise<Node[]>;
getNodesStatsPerCountry: () => Promise<any>;
getNodesHostedByISP: (params: { isp: number }) => Promise<Node[]>;
getISPRanking: () => Promise<any>;
getLiquidityRanking: () => Promise<Node[]>;
getConnectivityRanking: () => Promise<Node[]>;
getOldestNodes: () => Promise<Node[]>;
getNodeStats: (params: { public_key: string }) => Promise<Node>;
getHistoricalNodeStats: (params: { public_key: string }) => Promise<NodeStats[]>;
getChannel: (params: { id: string }) => Promise<Channel>;
getChannelsFromTxIds: (params: { txId: string[] }) => Promise<any[]>;
getChannelsFromNodePublicKey: (params: { public_key: string, status: string, index?: number }) => Promise<Channel[]>;
getChannelsGeodata: () => Promise<any>;
getChannelsGeodataByPublicKey: (params: { public_key: string }) => Promise<any[]>;
}

View File

@ -52,11 +52,11 @@ export interface TxInstance {
getTxHex: (params: { txid: string }) => Promise<string>; getTxHex: (params: { txid: string }) => Promise<string>;
getTxRaw: (params: { txid: string }) => Promise<string>; getTxRaw: (params: { txid: string }) => Promise<string>;
getTxMerkleBlockProof: (params: { txid: string }) => Promise<string>; getTxMerkleBlockProof: (params: { txid: string }) => Promise<string>;
getTxMerkleProof: (params: { txid: string }) => Promise<TxMerkleProof>; getTxMerkleProof: (params: { txid: string }) => Promise<Array<TxMerkleProof>>;
getTxOutspend: (params: { getTxOutspend: (params: {
txid: string; txid: string;
vout: number; vout: number;
}) => Promise<TxOutspend>; }) => Promise<TxOutspend>;
getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>; getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>;
postTx: (params: { txhex: string }) => Promise<unknown>; postTx: (params: { txid: string }) => Promise<unknown>;
} }

View File

@ -1,34 +1,10 @@
export interface WsInterface {
options: string[];
}
import WebSocketServer from 'ws'; import WebSocketServer from 'ws';
export interface WsInstance { export interface WsInstance {
wsInit: () => WebSocketServer; initClient: ({ options }: WsInterface) => WebSocket;
wsInitBrowser: () => WebSocket; initServer: ({ options }: WsInterface) => WebSocketServer;
wsWantData: (ws: WebSocketServer, options: string[]) => void;
wsWantDataBrowser: (ws: WebSocket, options: string[]) => void;
wsStopData: (ws: WebSocketServer) => void;
wsStopDataBrowser: (ws: WebSocket) => void;
wsTrackAddress: (ws: WebSocketServer, address: string) => void;
wsTrackAddressBrowser: (ws: WebSocket, address: string) => void;
wsStopTrackingAddress: (ws: WebSocketServer) => void;
wsStopTrackingAddressBrowser: (ws: WebSocket) => void;
wsTrackAddresses: (ws: WebSocketServer, addresses: string[]) => void;
wsTrackAddressesBrowser: (ws: WebSocket, addresses: string[]) => void;
wsStopTrackingAddresses: (ws: WebSocketServer) => void;
wsStopTrackingAddressesBrowser: (ws: WebSocket) => void;
wsTrackTransaction: (ws: WebSocketServer, txid: string) => void;
wsTrackTransactionBrowser: (ws: WebSocket, txid: string) => void;
wsStopTrackingTransaction: (ws: WebSocketServer) => void;
wsStopTrackingTransactionBrowser: (ws: WebSocket) => void;
wsTrackRbfSummary: (ws: WebSocketServer) => void;
wsTrackRbfSummaryBrowser: (ws: WebSocket) => void;
wsStopTrackingRbfSummary: (ws: WebSocketServer) => void;
wsStopTrackingRbfSummaryBrowser: (ws: WebSocket) => void;
wsTrackRbf: (ws: WebSocketServer, fullRbf: boolean) => void;
wsTrackRbfBrowser: (ws: WebSocket, fullRbf: boolean) => void;
wsStopTrackingRbf: (ws: WebSocketServer) => void;
wsStopTrackingRbfBrowser: (ws: WebSocket) => void;
wsTrackMempoolBlock: (ws: WebSocketServer, index: number) => void;
wsTrackMempoolBlockBrowser: (ws: WebSocket, index: number) => void;
wsStopTrackingMempoolBlock: (ws: WebSocketServer) => void;
wsStopTrackingMempoolBlockBrowser: (ws: WebSocket) => void;
} }

View File

@ -1,42 +1,44 @@
import { AddressInstance } from './bitcoin/addresses'; import { AddressInstance } from './bitcoin/addresses';
import { BlockInstance } from './bitcoin/blocks'; import { BlockInstance } from './bitcoin/blocks';
import { DifficultyInstance } from './bitcoin/difficulty';
import { FeeInstance } from './bitcoin/fees'; import { FeeInstance } from './bitcoin/fees';
import { LightningInstance } from './bitcoin/lightning';
import { MempoolInstance } from './bitcoin/mempool'; import { MempoolInstance } from './bitcoin/mempool';
import { TxInstance } from './bitcoin/transactions'; import { TxInstance } from './bitcoin/transactions';
import { WsInstance } from './bitcoin/websockets'; 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'; import { AssetsInstance } from './liquid/assets';
import { BlockLiquidInstance } from './liquid/blocks';
import { TxLiquidInstance } from './liquid/transactions';
import { WsLiquidInstance } from './liquid/websockets';
import { AxiosRequestConfig } from 'axios';
export interface MempoolConfig { export interface MempoolConfig {
protocol?: 'http' | 'https';
hostname?: string; hostname?: string;
network?: string; network?: string;
config?: AxiosRequestConfig;
} }
export interface MempoolReturn { export interface MempoolReturn {
bitcoin: { bitcoin: {
addresses: AddressInstance; addresses: AddressInstance;
blocks: BlockInstance; blocks: BlockInstance;
difficulty: DifficultyInstance;
fees: FeeInstance; fees: FeeInstance;
lightning: LightningInstance
mempool: MempoolInstance; mempool: MempoolInstance;
transactions: TxInstance; transactions: TxInstance;
websocket: WsInstance; websocket: WsInstance;
}; };
bisq: {
addresses: AddressesInstance;
blocks: BlocksInstance;
statistics: StatsInstance;
transactions: TransactionsInstance;
};
liquid: { liquid: {
assets: AssetsInstance; assets: AssetsInstance;
addresses: AddressInstance; addresses: AddressInstance;
blocks: BlockLiquidInstance; blocks: BlockInstance;
fees: FeeInstance; fees: FeeInstance;
mempool: MempoolInstance; mempool: MempoolInstance;
transactions: TxLiquidInstance; transactions: TxInstance;
websocket: WsLiquidInstance; websocket: WsInstance;
}; };
} }

View File

@ -16,7 +16,6 @@ interface AssetStats {
export interface AssetsInstance { export interface AssetsInstance {
getAsset: (params: { asset_id: string }) => Promise<Asset>; getAsset: (params: { asset_id: string }) => Promise<Asset>;
getAssetIcon: (params: { asset_id: string }) => Promise<unknown>;
getAssetTxs: (params: { getAssetTxs: (params: {
asset_id: string; asset_id: string;
is_mempool: boolean; is_mempool: boolean;
@ -25,5 +24,4 @@ export interface AssetsInstance {
asset_id: string; asset_id: string;
decimal: boolean; decimal: boolean;
}) => Promise<Asset>; }) => Promise<Asset>;
getAssetsIcons: () => Promise<string[]>
} }

View File

@ -1,37 +0,0 @@
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;
extras: any;
}
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>;
}

View File

@ -1,61 +0,0 @@
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 TxLiquidInstance {
getTx: (params: { txid: string }) => Promise<Tx>;
getTxStatus: (params: { txid: string }) => Promise<TxStatus>;
getTxHex: (params: { txid: string }) => Promise<string>;
getTxRaw: (params: { txid: string }) => Promise<string>;
getTxMerkleProof: (params: { txid: string }) => Promise<TxMerkleProof>;
getTxOutspend: (params: {
txid: string;
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>;
postTx: (params: { txhex: string }) => Promise<unknown>;
}

View File

@ -1,26 +0,0 @@
import WebSocketServer from 'ws';
export interface WsLiquidInstance {
wsInit: () => WebSocketServer;
wsInitBrowser: () => WebSocket;
wsWantData: (ws: WebSocketServer, options: string[]) => void;
wsWantDataBrowser: (ws: WebSocket, options: string[]) => void;
wsStopData: (ws: WebSocketServer) => void;
wsStopDataBrowser: (ws: WebSocket) => void;
wsTrackAddress: (ws: WebSocketServer, address: string) => void;
wsTrackAddressBrowser: (ws: WebSocket, address: string) => void;
wsStopTrackingAddress: (ws: WebSocketServer) => void;
wsStopTrackingAddressBrowser: (ws: WebSocket) => void;
wsTrackAddresses: (ws: WebSocketServer, addresses: string[]) => void;
wsTrackAddressesBrowser: (ws: WebSocket, addresses: string[]) => void;
wsStopTrackingAddresses: (ws: WebSocketServer) => void;
wsStopTrackingAddressesBrowser: (ws: WebSocket) => void;
wsTrackTransaction: (ws: WebSocketServer, txid: string) => void;
wsTrackTransactionBrowser: (ws: WebSocket, txid: string) => void;
wsStopTrackingTransaction: (ws: WebSocketServer) => void;
wsStopTrackingTransactionBrowser: (ws: WebSocket) => void;
wsTrackMempoolBlock: (ws: WebSocketServer, index: number) => void;
wsTrackMempoolBlockBrowser: (ws: WebSocket, index: number) => void;
wsStopTrackingMempoolBlock: (ws: WebSocketServer) => void;
wsStopTrackingMempoolBlockBrowser: (ws: WebSocket) => void;
}

View File

@ -1,46 +1,35 @@
import axios, { AxiosInstance } from 'axios'; import axios, { AxiosInstance } from 'axios';
import { MempoolConfig } from '../../interfaces'; import { MempoolConfig } from './../../interfaces/index';
export const makeBitcoinAPI = ({ export const makeBitcoinAPI = ({
hostname, hostname,
network, network,
protocol,
config,
}: MempoolConfig): { api: AxiosInstance } => { }: MempoolConfig): { api: AxiosInstance } => {
if (!protocol) { if (network && ['testnet', 'signet'].includes(network)) {
hostname?.includes('localhost') ? protocol = 'http' : protocol = 'https';
}
if (network && ['testnet', 'testnet4', 'signet'].includes(network)) {
network = `/${network}`; network = `/${network}`;
} else { } else {
network = ''; network = '';
} }
const api = axios.create({ const api = axios.create({
baseURL: `${protocol}://${hostname}${network}/api/`, baseURL: `https://${hostname}${network}/api/`,
...config,
}); });
return { return {
api, api,
}; };
}; };
export const makeLiquidAPI = ({ export const makeBisqAPI = (hostname?: string): { api: AxiosInstance } => {
hostname,
network,
protocol,
config,
}: MempoolConfig): { api: AxiosInstance } => {
if (!protocol) {
hostname?.includes('localhost') ? protocol = 'http' : protocol = 'https';
}
if (network && ['testnet', 'liquidtestnet'].includes(network)) {
network = `/liquidtestnet`;
} else {
network = '/liquid';
}
const api = axios.create({ const api = axios.create({
baseURL: `${protocol}://${hostname}${network}/api/`, baseURL: `https://${hostname}/bisq/api/`,
...config, });
return {
api,
};
};
export const makeLiquidAPI = (hostname?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://${hostname}/liquid/api/`,
}); });
return { return {
api, api,
@ -49,5 +38,6 @@ export const makeLiquidAPI = ({
export default { export default {
makeBitcoinAPI, makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI, makeLiquidAPI,
}; };

23
src/services/ws/client.ts Normal file
View File

@ -0,0 +1,23 @@
const browserWS = (
options: string[],
defaultWs: string,
websocketEndpoint?: string
): WebSocket => {
const ws = new WebSocket(websocketEndpoint || defaultWs);
ws.addEventListener('open', function open() {
handleMessage(ws, options);
});
return ws;
};
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
};
export default browserWS;

24
src/services/ws/server.ts Normal file
View File

@ -0,0 +1,24 @@
import WebSocket from 'ws';
const serverWS = (
options: string[],
defaultWs: string,
websocketEndpoint?: string
): WebSocket => {
const ws = new WebSocket(websocketEndpoint || defaultWs);
ws.on('open', function open() {
handleMessage(ws, options);
});
return ws;
};
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
};
export default serverWS;

View File

@ -1,88 +0,0 @@
const TIMEOUT_DURATION = 5000;
const MAX_RETRY_COUNT = 3;
const wsActionWrapper = (ws: WebSocket, action: any): void => {
let retryCount = 0;
const sendData = () => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(action));
} else if (retryCount < MAX_RETRY_COUNT) {
retryCount++;
console.log("WebSocket connection is not open. Retrying...");
setTimeout(sendData, TIMEOUT_DURATION);
} else {
console.log("WebSocket connection is not open. Max retry count reached.");
}
};
sendData();
}
export const wsInit = (endpoint: string): WebSocket => {
const ws = new WebSocket(endpoint);
ws.addEventListener("open", function open() {
ws.send(JSON.stringify({ action: "init" }));
});
return ws;
}
export const wsWantData = (ws: WebSocket, options: string[]): void => {
wsActionWrapper(ws, { action: "want", data: options });
}
export const wsStopData = (ws: WebSocket): void => {
wsActionWrapper(ws, { action: "want", data: [] });
}
export const wsTrackAddress = (ws: WebSocket, address: string): void => {
wsActionWrapper(ws, { 'track-address': address });
}
export const wsStopTrackingAddress = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-address': 'stop' });
}
export const wsTrackAddresses = (ws: WebSocket, addresses: string[]): void => {
wsActionWrapper(ws, { 'track-addresses': addresses });
}
export const wsStopTrackingAddresses = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-addresses': [] });
}
export const wsTrackTransaction = (ws: WebSocket, txid: string): void => {
wsActionWrapper(ws, { 'track-tx': txid });
}
export const wsStopTrackingTransaction = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-tx': 'stop' });
}
export const wsTrackRbfSummary = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf-summary': true });
}
export const wsStopTrackingRbfSummary = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf-summary': false });
}
export const wsTrackRbf = (ws: WebSocket, fullRbf: boolean): void => {
if (!fullRbf) {
wsActionWrapper(ws, { 'track-rbf': 'all' });
} else {
wsActionWrapper(ws, { 'track-rbf': 'fullRbf' });
}
}
export const wsStopTrackingRbf = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf': 'stop' });
}
export const wsTrackMempoolBlock = (ws: WebSocket, index: number): void => {
wsActionWrapper(ws, { 'track-mempool-block': index });
}
export const wsStopTrackingMempoolBlock = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-mempool-block': -1 });
}

View File

@ -1,90 +0,0 @@
import WebSocket from "ws";
const TIMEOUT_DURATION = 5000;
const MAX_RETRY_COUNT = 3;
const wsActionWrapper = (ws: WebSocket, action: any): void => {
let retryCount = 0;
const sendData = () => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(action));
} else if (retryCount < MAX_RETRY_COUNT) {
retryCount++;
console.log("WebSocket connection is not open. Retrying...");
setTimeout(sendData, TIMEOUT_DURATION);
} else {
console.log("WebSocket connection is not open. Max retry count reached.");
}
};
sendData();
}
export const wsInit = (endpoint: string): WebSocket => {
const ws = new WebSocket(endpoint);
ws.addEventListener("open", function open() {
ws.send(JSON.stringify({ action: "init" }));
});
return ws;
}
export const wsWantData = (ws: WebSocket, options: string[]): void => {
wsActionWrapper(ws, { action: "want", data: options });
}
export const wsStopData = (ws: WebSocket): void => {
wsActionWrapper(ws, { action: "want", data: [] });
}
export const wsTrackAddress = (ws: WebSocket, address: string): void => {
wsActionWrapper(ws, { 'track-address': address });
}
export const wsStopTrackingAddress = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-address': 'stop' });
}
export const wsTrackAddresses = (ws: WebSocket, addresses: string[]): void => {
wsActionWrapper(ws, { 'track-addresses': addresses });
}
export const wsStopTrackingAddresses = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-addresses': [] });
}
export const wsTrackTransaction = (ws: WebSocket, txid: string): void => {
wsActionWrapper(ws, { 'track-tx': txid });
}
export const wsStopTrackingTransaction = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-tx': 'stop' });
}
export const wsTrackRbfSummary = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf-summary': true });
}
export const wsStopTrackingRbfSummary = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf-summary': false });
}
export const wsTrackRbf = (ws: WebSocket, fullRbf: boolean): void => {
if (!fullRbf) {
wsActionWrapper(ws, { 'track-rbf': 'all' });
} else {
wsActionWrapper(ws, { 'track-rbf': 'fullRbf' });
}
}
export const wsStopTrackingRbf = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-rbf': 'stop' });
}
export const wsTrackMempoolBlock = (ws: WebSocket, index: number): void => {
wsActionWrapper(ws, { 'track-mempool-block': index });
}
export const wsStopTrackingMempoolBlock = (ws: WebSocket): void => {
wsActionWrapper(ws, { 'track-mempool-block': -1 });
}

3644
yarn.lock

File diff suppressed because it is too large Load Diff