v2.2.0 - new major version for mempool-js (#2)
* - Refactoring code. - Refactoring folder structure. - Adding apiEndpoint and websocketEndpoint to Mempool config. - Adding brownserify feature. - Adding MIT LICENSE * - Changing package.json information. - Reorganizing README.md information. - Default export for CommonJs and ES6 Modules. - Changing default variable to mempoolJS. - Organizing the API and WS providers. - Splitting websocket connection types: client and server. * Change version to 2.2.0. Reorder keywords in alphabetical order.
This commit is contained in:
1 parent
3bfae54069
commit
f39361263a
40 files changed
+5581
-1386
No files matched your search
@@ -1,3 +1,2 @@
|
||||
/node_modules
|
||||
.env
|
||||
/lib
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Miguel Medeiros
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
+2482
File diff suppressed because it is too large.
Load diff
Vendored
+1
@@ -0,0 +1 @@
|
||||
!function(){"use strict";var e=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}},t=Object.prototype.toString;function n(e){return"[object Array]"===t.call(e)}function r(e){return void 0===e}function o(e){return null!==e&&"object"==typeof e}function i(e){if("[object Object]"!==t.call(e))return!1;var n=Object.getPrototypeOf(e);return null===n||n===Object.prototype}function a(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),n(e))for(var r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.call(null,e[i],i,e)}var s={isArray:n,isArrayBuffer:function(e){return"[object ArrayBuffer]"===t.call(e)},isBuffer:function(e){return null!==e&&!r(e)&&null!==e.constructor&&!r(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:o,isPlainObject:i,isUndefined:r,isDate:function(e){return"[object Date]"===t.call(e)},isFile:function(e){return"[object File]"===t.call(e)},isBlob:function(e){return"[object Blob]"===t.call(e)},isStream:function(e){return o(e)&&function(e){return"[object Function]"===t.call(e)}(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&"undefined"!=typeof window&&"undefined"!=typeof document},forEach:a,merge:function e(){var t={};function r(r,o){i(t[o])&&i(r)?t[o]=e(t[o],r):i(r)?t[o]=e({},r):n(r)?t[o]=r.slice():t[o]=r}for(var o=0,s=arguments.length;o<s;o++)a(arguments[o],r);return t},extend:function(t,n,r){return a(n,(function(n,o){t[o]=r&&"function"==typeof n?e(n,r):n})),t},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")}};function u(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var c=function(e,t,n){if(!t)return e;var r;if(n)r=n(t);else if(s.isURLSearchParams(t))r=t.toString();else{var o=[];s.forEach(t,(function(e,t){null!=e&&(s.isArray(e)?t+="[]":e=[e],s.forEach(e,(function(e){s.isDate(e)?e=e.toISOString():s.isObject(e)&&(e=JSON.stringify(e)),o.push(u(t)+"="+u(e))})))})),r=o.join("&")}if(r){var i=e.indexOf("#");-1!==i&&(e=e.slice(0,i)),e+=(-1===e.indexOf("?")?"?":"&")+r}return e},f={};function l(){this.handlers=[]}l.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},l.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},l.prototype.forEach=function(e){s.forEach(this.handlers,(function(t){null!==t&&e(t)}))},f=l;var d,h,p,v=function(e,t,n){return s.forEach(n,(function(n){e=n(e,t)})),e},m=function(e){return!(!e||!e.__CANCEL__)},b=function(e,t){s.forEach(e,(function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])}))},g=function(e,t,n,r,o){return function(e,t,n,r,o){return e.config=t,n&&(e.code=n),e.request=r,e.response=o,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e}(new Error(e),t,n,r,o)},y=s.isStandardBrowserEnv()?{write:function(e,t,n,r,o,i){var a=[];a.push(e+"="+encodeURIComponent(t)),s.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),s.isString(r)&&a.push("path="+r),s.isString(o)&&a.push("domain="+o),!0===i&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}},w=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],x=s.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function r(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=r(window.location.href),function(t){var n=s.isStrinLine truncated
|
||||
@@ -1,22 +0,0 @@
|
||||
import { addresses } from '../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const address =
|
||||
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
|
||||
|
||||
const addressTest = await addresses.getAddress({ address });
|
||||
console.log(addressTest);
|
||||
|
||||
const addressTxs = await addresses.getAddressTxs({ address });
|
||||
console.log(addressTxs);
|
||||
|
||||
const addressTxsChain = await addresses.getAddressTxsChain({ address });
|
||||
console.log(addressTxsChain);
|
||||
|
||||
const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
|
||||
console.log(addressTxsMempool);
|
||||
|
||||
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
|
||||
console.log(addressTxsUtxo);
|
||||
};
|
||||
init();
|
||||
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { addresses } = mempoolJS();
|
||||
|
||||
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
|
||||
|
||||
const addressTest = await addresses.getAddress(address);
|
||||
console.log(addressTest);
|
||||
|
||||
const addressTxs = await addresses.getAddressTxs(address);
|
||||
console.log(addressTxs);
|
||||
|
||||
const addressTxsChain = await addresses.getAddressTxsChain(address);
|
||||
console.log(addressTxsChain);
|
||||
|
||||
const addressTxsMempool = await addresses.getAddressTxsMempool(address);
|
||||
console.log(addressTxsMempool);
|
||||
|
||||
const addressTxsUtxo = await addresses.getAddressTxsUtxo(address);
|
||||
console.log(addressTxsUtxo);
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { blocks } = mempoolJS();
|
||||
|
||||
const hash =
|
||||
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
|
||||
|
||||
const block = await blocks.getBlock(hash);
|
||||
console.log(block);
|
||||
|
||||
const blockStatus = await blocks.getBlockStatus(hash);
|
||||
console.log(blockStatus);
|
||||
|
||||
const blockTxs = await blocks.getBlockTxs({ hash });
|
||||
console.log(blockTxs);
|
||||
|
||||
const blockTxids = await blocks.getBlockTxids(hash);
|
||||
console.log(blockTxids);
|
||||
|
||||
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
|
||||
console.log(blockTxid);
|
||||
|
||||
const blockRaw = await blocks.getBlockRaw(hash);
|
||||
console.log(blockRaw);
|
||||
|
||||
const blockHeight = await blocks.getBlockHeight(9999);
|
||||
console.log(blockHeight);
|
||||
|
||||
const getBlocks = await blocks.getBlocks({ start_height: 9999 });
|
||||
console.log(getBlocks);
|
||||
|
||||
const blocksTipHeight = await blocks.getBlocksTipHeight();
|
||||
console.log(blocksTipHeight);
|
||||
|
||||
const blocksTipHash = await blocks.getBlocksTipHash();
|
||||
console.log(blocksTipHash);
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { fees } = mempoolJS();
|
||||
|
||||
const feesRecommended = await fees.getFeesRecommended();
|
||||
console.log(feesRecommended);
|
||||
|
||||
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
|
||||
console.log(feesMempoolBlocks);
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { mempool } = mempoolJS();
|
||||
|
||||
const getMempool = await mempool.getMempool();
|
||||
console.log(getMempool);
|
||||
|
||||
const getMempoolRecent = await mempool.getMempoolRecent();
|
||||
console.log(getMempoolRecent);
|
||||
|
||||
const getMempoolTxids = await mempool.getMempoolTxids();
|
||||
console.log(getMempoolTxids);
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { transactions } = mempoolJS();
|
||||
|
||||
const txid =
|
||||
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
|
||||
|
||||
const tx = await transactions.getTx(txid);
|
||||
console.log(tx);
|
||||
|
||||
const txStatus = await transactions.getTxStatus(txid);
|
||||
console.log(txStatus);
|
||||
|
||||
const txHex = await transactions.getTxHex(txid);
|
||||
console.log(txHex);
|
||||
|
||||
const txRaw = await transactions.getTxRaw(txid);
|
||||
console.log(txRaw);
|
||||
|
||||
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof(
|
||||
txid
|
||||
);
|
||||
console.log(txMerkleBlockProof);
|
||||
|
||||
const txMerkleProof = await transactions.getTxMerkleProof(txid);
|
||||
console.log(txMerkleProof);
|
||||
|
||||
const txOutspend = await transactions.getTxOutspend({
|
||||
txid,
|
||||
vout: 3,
|
||||
});
|
||||
console.log(txOutspend);
|
||||
|
||||
const txOutspends = await transactions.getTxOutspends(txid);
|
||||
console.log(txOutspends);
|
||||
|
||||
// const postTx = await transactions.postTx(txid);
|
||||
// console.log(postTx);
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Page Title</title>
|
||||
<script src="./../../dist/mempool.js"></script>
|
||||
<script>
|
||||
const init = async () => {
|
||||
const { websocket } = mempoolJS();
|
||||
|
||||
const ws = await websocket.initClient({
|
||||
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
|
||||
});
|
||||
|
||||
ws.addEventListener('message', function incoming({ data }) {
|
||||
const res = JSON.parse(data);
|
||||
if (res.blocks) {
|
||||
res.blocks.forEach((block) => {
|
||||
console.log(block.height);
|
||||
});
|
||||
}
|
||||
if (res.mempoolInfo) {
|
||||
console.log(res.mempoolInfo);
|
||||
}
|
||||
if (res.transactions) {
|
||||
console.log(res.transactions);
|
||||
}
|
||||
if (res.mempoolBlocks) {
|
||||
console.log(res.mempoolBlocks);
|
||||
}
|
||||
});
|
||||
};
|
||||
init();
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const { addresses } = mempoolJS();
|
||||
|
||||
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
|
||||
|
||||
const addressTest = await addresses.getAddress(address);
|
||||
console.log(addressTest);
|
||||
|
||||
const addressTxs = await addresses.getAddressTxs(address);
|
||||
console.log(addressTxs);
|
||||
|
||||
const addressTxsChain = await addresses.getAddressTxsChain(address);
|
||||
console.log(addressTxsChain);
|
||||
|
||||
const addressTxsMempool = await addresses.getAddressTxsMempool(address);
|
||||
console.log(addressTxsMempool);
|
||||
|
||||
const addressTxsUtxo = await addresses.getAddressTxsUtxo(address);
|
||||
console.log(addressTxsUtxo);
|
||||
};
|
||||
init();
|
||||
@@ -1,33 +1,33 @@
|
||||
import { blocks } from '../src/index';
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const { blocks } = mempoolJS();
|
||||
|
||||
const hash =
|
||||
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
|
||||
|
||||
const block = await blocks.getBlock({ hash });
|
||||
const block = await blocks.getBlock(hash);
|
||||
console.log(block);
|
||||
|
||||
const blockStatus = await blocks.getBlockStatus({ hash });
|
||||
const blockStatus = await blocks.getBlockStatus(hash);
|
||||
console.log(blockStatus);
|
||||
|
||||
const blockTxs = await blocks.getBlockTxs({ hash });
|
||||
console.log(blockTxs);
|
||||
|
||||
const blockTxids = await blocks.getBlockTxids({ hash });
|
||||
const blockTxids = await blocks.getBlockTxids(hash);
|
||||
console.log(blockTxids);
|
||||
|
||||
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
|
||||
console.log(blockTxid);
|
||||
|
||||
const blockRaw = await blocks.getBlockRaw({ hash });
|
||||
const blockRaw = await blocks.getBlockRaw(hash);
|
||||
console.log(blockRaw);
|
||||
|
||||
const blockHeight = await blocks.getBlockHeight({
|
||||
start_height: 66666,
|
||||
});
|
||||
const blockHeight = await blocks.getBlockHeight(9999);
|
||||
console.log(blockHeight);
|
||||
|
||||
const getBlocks = await blocks.getBlocks({ start_height: 66666 });
|
||||
const getBlocks = await blocks.getBlocks({ start_height: 9999 });
|
||||
console.log(getBlocks);
|
||||
|
||||
const blocksTipHeight = await blocks.getBlocksTipHeight();
|
||||
@@ -1,6 +1,8 @@
|
||||
import { fees } from './../src/index';
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const { fees } = mempoolJS();
|
||||
|
||||
const feesRecommended = await fees.getFeesRecommended();
|
||||
console.log(feesRecommended);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { mempool } from '../src/index';
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const { mempool } = mempoolJS();
|
||||
|
||||
const getMempool = await mempool.getMempool();
|
||||
console.log(getMempool);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const { transactions } = mempoolJS();
|
||||
|
||||
const txid =
|
||||
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
|
||||
|
||||
const tx = await transactions.getTx(txid);
|
||||
console.log(tx);
|
||||
|
||||
const txStatus = await transactions.getTxStatus(txid);
|
||||
console.log(txStatus);
|
||||
|
||||
const txHex = await transactions.getTxHex(txid);
|
||||
console.log(txHex);
|
||||
|
||||
const txRaw = await transactions.getTxRaw(txid);
|
||||
console.log(txRaw);
|
||||
|
||||
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof(txid);
|
||||
console.log(txMerkleBlockProof);
|
||||
|
||||
const txMerkleProof = await transactions.getTxMerkleProof(txid);
|
||||
console.log(txMerkleProof);
|
||||
|
||||
const txOutspend = await transactions.getTxOutspend({
|
||||
txid,
|
||||
vout: 3,
|
||||
});
|
||||
console.log(txOutspend);
|
||||
|
||||
const txOutspends = await transactions.getTxOutspends(txid);
|
||||
console.log(txOutspends);
|
||||
|
||||
// const postTx = await transactions.postTx(txid);
|
||||
// console.log(postTx);
|
||||
};
|
||||
init();
|
||||
@@ -1,14 +1,17 @@
|
||||
import { websocket } from '../src/index';
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import mempoolJS from '../../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const ws = await websocket.init({
|
||||
const { websocket } = mempoolJS();
|
||||
|
||||
const ws = websocket.initServer({
|
||||
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
|
||||
});
|
||||
|
||||
ws.on('message', function incoming(data: any) {
|
||||
const res = JSON.parse(data);
|
||||
ws.on('message', function incoming(data) {
|
||||
const res = JSON.parse(data.toString());
|
||||
if (res.blocks) {
|
||||
res.blocks.forEach((block: any) => {
|
||||
res.blocks.forEach((block: { height: any }) => {
|
||||
console.log(block.height);
|
||||
});
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import { transactions } from '../src/index';
|
||||
|
||||
const init = async () => {
|
||||
const txid =
|
||||
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
|
||||
|
||||
const tx = await transactions.getTx({ txid });
|
||||
console.log(tx);
|
||||
|
||||
const txStatus = await transactions.getTxStatus({ txid });
|
||||
console.log(txStatus);
|
||||
|
||||
const txHex = await transactions.getTxHex({ txid });
|
||||
console.log(txHex);
|
||||
|
||||
const txRaw = await transactions.getTxRaw({ txid });
|
||||
console.log(txRaw);
|
||||
|
||||
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({
|
||||
txid,
|
||||
});
|
||||
console.log(txMerkleBlockProof);
|
||||
|
||||
const txMerkleProof = await transactions.getTxMerkleProof({ txid });
|
||||
console.log(txMerkleProof);
|
||||
|
||||
const txOutspend = await transactions.getTxOutspend({
|
||||
txid,
|
||||
vout: 3,
|
||||
});
|
||||
console.log(txOutspend);
|
||||
|
||||
const txOutspends = await transactions.getTxOutspends({ txid });
|
||||
console.log(txOutspends);
|
||||
|
||||
const postTx = await transactions.postTx({ txid });
|
||||
console.log(postTx);
|
||||
};
|
||||
init();
|
||||
+29
-20
@@ -1,43 +1,52 @@
|
||||
{
|
||||
"name": "mempool-space-js",
|
||||
"version": "1.1.2",
|
||||
"description": "NPM Package for Mempool.Space API.",
|
||||
"name": "@mempool/mempool-js",
|
||||
"version": "2.2.0",
|
||||
"description": "NPM Package for Mempool JS API.",
|
||||
"main": "lib/index.js",
|
||||
"author": "MiguelMedeiros\\Miguel Medeiros <miguel@miguelmedeiros.com.br>",
|
||||
"email": "miguel@miguelmedeiros.com.br",
|
||||
"url": "http://miguelmedeiros.com.br",
|
||||
"keywords": [
|
||||
"axios",
|
||||
"bitcoin",
|
||||
"blockchain",
|
||||
"html",
|
||||
"mempool-space",
|
||||
"mempool-js",
|
||||
"mempool",
|
||||
"nodejs",
|
||||
"typescript"
|
||||
],
|
||||
"author": "Miguel Medeiros <contact@miguelmedeiros.com.br> (miguelmedeiros.com.br)",
|
||||
"url": "https://mempool.space/",
|
||||
"private": false,
|
||||
"license": "MIT",
|
||||
"repository": "github:MiguelMedeiros/mempool-space-js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mempool/mempool-js.git"
|
||||
},
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"start": "ts-node 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 -o dist/mempool.min.js ",
|
||||
"prepare": "npm run build",
|
||||
"postversion": "git push && git push --tags"
|
||||
},
|
||||
"files": [
|
||||
"lib/**/*"
|
||||
],
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"mempool-space",
|
||||
"mempool",
|
||||
"blockchain",
|
||||
"typescript",
|
||||
"axios"
|
||||
],
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"typescript": "^4.1.3",
|
||||
"ws": "^7.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.25",
|
||||
"@types/websocket": "^1.0.2",
|
||||
"@types/ws": "^7.4.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
||||
"@typescript-eslint/parser": "^4.14.2",
|
||||
"browserify": "^17.0.0",
|
||||
"eslint": "^7.19.0",
|
||||
"nodemon": "^2.0.7"
|
||||
}
|
||||
"nodemon": "^2.0.7",
|
||||
"tinyify": "^3.0.0",
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
import api from './api';
|
||||
|
||||
const getAddress = async (params: { address: string }) => {
|
||||
return api
|
||||
.get(`/address/${params.address}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
address: string;
|
||||
chain_stats: {
|
||||
funded_txo_count: number;
|
||||
funded_txo_sum: number;
|
||||
spent_txo_count: number;
|
||||
spent_txo_sum: number;
|
||||
tx_count: number;
|
||||
};
|
||||
mempool_stats: {
|
||||
funded_txo_count: number;
|
||||
funded_txo_sum: number;
|
||||
spent_txo_count: number;
|
||||
spent_txo_sum: number;
|
||||
tx_count: number;
|
||||
};
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getAddressTxs = async (params: { address: string }) => {
|
||||
return api
|
||||
.get(`/address/${params.address}/txs`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
version: number;
|
||||
locktime: number;
|
||||
vin: Record<string, unknown>[];
|
||||
vout: Record<string, unknown>[];
|
||||
size: number;
|
||||
weight: number;
|
||||
fee: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getAddressTxsChain = async (params: { address: string }) => {
|
||||
return api
|
||||
.get(`/address/${params.address}/txs/chain`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
version: number;
|
||||
locktime: number;
|
||||
vin: Record<string, unknown>[];
|
||||
vout: Record<string, unknown>[];
|
||||
size: number;
|
||||
weight: number;
|
||||
fee: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getAddressTxsMempool = async (params: { address: string }) => {
|
||||
return api
|
||||
.get(`/address/${params.address}/txs/mempool`)
|
||||
.then((res: { data: any }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getAddressTxsUtxo = async (params: { address: string }) => {
|
||||
return api
|
||||
.get(`/address/${params.address}/utxo`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
vout: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
value: number;
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
getAddress,
|
||||
getAddressTxs,
|
||||
getAddressTxsChain,
|
||||
getAddressTxsMempool,
|
||||
getAddressTxsUtxo,
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
import axios from 'axios';
|
||||
export default axios.create({
|
||||
baseURL: 'https://mempool.space/api/',
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { Address, AddressTxsUtxo, Tx, AddressInstance } from '../interfaces';
|
||||
|
||||
export const useAddresses = (api: AxiosInstance): AddressInstance => {
|
||||
const getAddress = async (address: string) => {
|
||||
const { data } = await api.get<Address>(`/address/${address}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAddressTxs = async (address: string) => {
|
||||
const { data } = await api.get<Tx[]>(`/address/${address}/txs`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAddressTxsChain = async (address: string) => {
|
||||
const { data } = await api.get<Tx[]>(`/address/${address}/txs/chain`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAddressTxsMempool = async (address: string) => {
|
||||
const { data } = await api.get<Tx[]>(`/address/${address}/txs/mempool`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getAddressTxsUtxo = async (address: string) => {
|
||||
const { data } = await api.get<AddressTxsUtxo[]>(
|
||||
`/address/${address}/utxo`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getAddress,
|
||||
getAddressTxs,
|
||||
getAddressTxsChain,
|
||||
getAddressTxsMempool,
|
||||
getAddressTxsUtxo,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,74 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { Block, BlockStatus, BlockInstance, Tx } from '../interfaces';
|
||||
|
||||
export const useBlocks = (api: AxiosInstance): BlockInstance => {
|
||||
const getBlock = async (hash: string) => {
|
||||
const { data } = await api.get<Block>(`/block/${hash}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockStatus = async (hash: string) => {
|
||||
const { data } = await api.get<BlockStatus>(`/block/${hash}/status`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockTxs = async (params: {
|
||||
hash: string;
|
||||
start_index?: number;
|
||||
}) => {
|
||||
const { data } = await api.get<Tx>(
|
||||
`/block/${params.hash}/txs/${params.start_index}`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockTxids = async (hash: string) => {
|
||||
const { data } = await api.get<string[]>(`/block/${hash}/txids`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockTxid = async (params: { hash: string; index: number }) => {
|
||||
const { data } = await api.get<string>(
|
||||
`/block/${params.hash}/txid/${params.index}`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockRaw = async (hash: string) => {
|
||||
const { data } = await api.get<string>(`/block/${hash}/raw`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlockHeight = async (height: number) => {
|
||||
const { data } = await api.get<string>(`/block-height/${height}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlocks = async (params: { start_height?: number }) => {
|
||||
const { data } = await api.get<Block>(`/blocks/${params.start_height}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlocksTipHeight = async () => {
|
||||
const { data } = await api.get<number>(`/blocks/tip/height`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getBlocksTipHash = async () => {
|
||||
const { data } = await api.get<string>(`/blocks/tip/hash`);
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getBlock,
|
||||
getBlocks,
|
||||
getBlockStatus,
|
||||
getBlockTxs,
|
||||
getBlockTxid,
|
||||
getBlockTxids,
|
||||
getBlockRaw,
|
||||
getBlockHeight,
|
||||
getBlocksTipHash,
|
||||
getBlocksTipHeight,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { FeesRecommended, FeesMempoolBlocks, FeeInstance } from '../interfaces';
|
||||
|
||||
export const useFees = (api: AxiosInstance): FeeInstance => {
|
||||
const getFeesRecommended = async () => {
|
||||
const { data } = await api.get<FeesRecommended>(`/v1/fees/recommended`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getFeesMempoolBlocks = async () => {
|
||||
const { data } = await api.get<FeesMempoolBlocks[]>(
|
||||
`/v1/fees/mempool-blocks`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getFeesRecommended,
|
||||
getFeesMempoolBlocks,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import { Mempool, MempoolRecent, MempoolInstance } from '../interfaces';
|
||||
|
||||
export const useMempool = (api: AxiosInstance): MempoolInstance => {
|
||||
const getMempool = async () => {
|
||||
const { data } = await api.get<Mempool[]>(`/mempool`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getMempoolTxids = async () => {
|
||||
const { data } = await api.get<string[]>(`/mempool/txids`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getMempoolRecent = async () => {
|
||||
const { data } = await api.get<MempoolRecent[]>(`/mempool/recent`);
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getMempool,
|
||||
getMempoolTxids,
|
||||
getMempoolRecent,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
import { AxiosInstance } from 'axios';
|
||||
import {
|
||||
Tx,
|
||||
TxStatus,
|
||||
TxMerkleProof,
|
||||
TxOutspend,
|
||||
TxInstance,
|
||||
} from '../interfaces';
|
||||
|
||||
export const useTransactions = (api: AxiosInstance): TxInstance => {
|
||||
const getTx = async (txid: string) => {
|
||||
const { data } = await api.get<Tx>(`/tx/${txid}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxStatus = async (txid: string) => {
|
||||
const { data } = await api.get<TxStatus>(`/tx/${txid}/status`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxHex = async (txid: string) => {
|
||||
const { data } = await api.get<string>(`/tx/${txid}/hex`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxRaw = async (txid: string) => {
|
||||
const { data } = await api.get<string>(`/tx/${txid}/raw`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxMerkleBlockProof = async (txid: string) => {
|
||||
const { data } = await api.get<string>(`/tx/${txid}/merkleblock-proof`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxMerkleProof = async (txid: string) => {
|
||||
const { data } = await api.get<Array<TxMerkleProof>>(
|
||||
`/tx/${txid}/merkle-proof`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxOutspend = async (params: { txid: string; vout: number }) => {
|
||||
const { data } = await api.get<TxOutspend>(
|
||||
`/tx/${params.txid}/outspend/${params.vout}`
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
const getTxOutspends = async (txid: string) => {
|
||||
const { data } = await api.get<Array<TxOutspend>>(`/tx/${txid}/outspends`);
|
||||
return data;
|
||||
};
|
||||
|
||||
const postTx = async (txid: string) => {
|
||||
const { data } = await api.post<string>(`/tx`, { txid: txid });
|
||||
return data;
|
||||
};
|
||||
|
||||
return {
|
||||
getTx,
|
||||
getTxStatus,
|
||||
getTxHex,
|
||||
getTxRaw,
|
||||
getTxMerkleBlockProof,
|
||||
getTxMerkleProof,
|
||||
getTxOutspend,
|
||||
getTxOutspends,
|
||||
postTx,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { WsInterface, WsInstance } from '../interfaces';
|
||||
import wsClient from '../services/wsClient';
|
||||
import wsServer from '../services/wsServer';
|
||||
|
||||
const defaultWs = 'wss://mempool.space/api/v1/ws';
|
||||
|
||||
export const useWebsocket = (websocketEndpoint?: string): WsInstance => {
|
||||
return {
|
||||
initClient: ({ options }: WsInterface) =>
|
||||
wsClient(options, defaultWs, websocketEndpoint),
|
||||
initServer: ({ options }: WsInterface) =>
|
||||
wsServer(options, defaultWs, websocketEndpoint),
|
||||
};
|
||||
};
|
||||
-247
@@ -1,247 +0,0 @@
|
||||
import api from './api';
|
||||
|
||||
const getBlock = async (params: { hash: string }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
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;
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockStatus = async (params: { hash: string }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}/status`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
in_best_chain: boolean;
|
||||
height: number;
|
||||
next_best: string;
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockTxs = async (params: { hash: string; start_index?: number }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}/txs/${params.start_index}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
version: number;
|
||||
locktime: number;
|
||||
vin: Record<string, unknown>[];
|
||||
vout: Record<string, unknown>[][];
|
||||
size: number;
|
||||
weight: number;
|
||||
fee: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockTxids = async (params: { hash: string }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}/txids`)
|
||||
.then((res: { data: string[] }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockTxid = async (params: { hash: string; index: number }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}/txid/${params.index}`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockRaw = async (params: { hash: string }) => {
|
||||
return api
|
||||
.get(`/block/${params.hash}/raw`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlockHeight = async (params: { height: number }) => {
|
||||
return api
|
||||
.get(`/block-height/${params.height}`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlocks = async (params: { start_height?: number }) => {
|
||||
return api
|
||||
.get(`/blocks/${params.start_height}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
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;
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlocksTipHeight = async () => {
|
||||
return api
|
||||
.get(`/blocks/tip/height`)
|
||||
.then((res: { data: number }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getBlocksTipHash = async () => {
|
||||
return api
|
||||
.get(`/blocks/tip/hash`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
getBlock,
|
||||
getBlocks,
|
||||
getBlockStatus,
|
||||
getBlockTxs,
|
||||
getBlockTxid,
|
||||
getBlockTxids,
|
||||
getBlockRaw,
|
||||
getBlockHeight,
|
||||
getBlocksTipHash,
|
||||
getBlocksTipHeight,
|
||||
};
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
import api from './api';
|
||||
|
||||
const getFeesRecommended = async () => {
|
||||
return await api
|
||||
.get(`/v1/fees/recommended`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
fastestFee: number;
|
||||
halfHourFee: number;
|
||||
hourFee: number;
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getFeesMempoolBlocks = async () => {
|
||||
return await api
|
||||
.get(`/v1/fees/mempool-blocks`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
blockSize: number;
|
||||
blockVSize: number;
|
||||
nTx: number;
|
||||
totalFees: number;
|
||||
medianFee: number;
|
||||
feeRange: number[];
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
getFeesRecommended,
|
||||
getFeesMempoolBlocks,
|
||||
};
|
||||
+30
-19
@@ -1,22 +1,33 @@
|
||||
import fees from './fees';
|
||||
import mempool from './mempool';
|
||||
import blocks from './blocks';
|
||||
import transactions from './transactions';
|
||||
import addresses from './addresses';
|
||||
import websocket from './websocket';
|
||||
import { MempoolConfig, MempoolReturn } from './interfaces';
|
||||
import { makeAPI } from './services/api';
|
||||
|
||||
export { default as fees } from './fees';
|
||||
export { default as mempool } from './mempool';
|
||||
export { default as blocks } from './blocks';
|
||||
export { default as transactions } from './transactions';
|
||||
export { default as addresses } from './addresses';
|
||||
export { default as websocket } from './websocket';
|
||||
import { useAddresses } from './app/addresses';
|
||||
import { useBlocks } from './app/blocks';
|
||||
import { useFees } from './app/fees';
|
||||
import { useMempool } from './app/mempool';
|
||||
import { useTransactions } from './app/transactions';
|
||||
import { useWebsocket } from './app/websocket';
|
||||
|
||||
export default {
|
||||
fees,
|
||||
mempool,
|
||||
blocks,
|
||||
transactions,
|
||||
addresses,
|
||||
websocket,
|
||||
const apiEndpointDefault = 'https://mempool.space/api/';
|
||||
const websocketEndpointDefault = 'wss://mempool.space/api/v1/ws';
|
||||
|
||||
const mempool = (
|
||||
{ apiEndpoint, websocketEndpoint }: MempoolConfig = {
|
||||
apiEndpoint: apiEndpointDefault,
|
||||
websocketEndpoint: websocketEndpointDefault,
|
||||
}
|
||||
): MempoolReturn => {
|
||||
const { api } = makeAPI(apiEndpoint);
|
||||
|
||||
return {
|
||||
addresses: useAddresses(api),
|
||||
blocks: useBlocks(api),
|
||||
fees: useFees(api),
|
||||
mempool: useMempool(api),
|
||||
transactions: useTransactions(api),
|
||||
websocket: useWebsocket(websocketEndpoint),
|
||||
};
|
||||
};
|
||||
|
||||
mempool.default = mempool;
|
||||
export = mempool;
|
||||
@@ -0,0 +1,213 @@
|
||||
import WebSocketServer from 'ws';
|
||||
export interface Address {
|
||||
address: string;
|
||||
chain_stats: {
|
||||
funded_txo_count: number;
|
||||
funded_txo_sum: number;
|
||||
spent_txo_count: number;
|
||||
spent_txo_sum: number;
|
||||
tx_count: number;
|
||||
};
|
||||
mempool_stats: {
|
||||
funded_txo_count: number;
|
||||
funded_txo_sum: number;
|
||||
spent_txo_count: number;
|
||||
spent_txo_sum: number;
|
||||
tx_count: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface AddressInstance {
|
||||
getAddress: (address: string) => Promise<Address>;
|
||||
getAddressTxs: (address: string) => Promise<Tx[]>;
|
||||
getAddressTxsChain: (address: string) => Promise<Tx[]>;
|
||||
getAddressTxsMempool: (address: string) => Promise<Tx[]>;
|
||||
getAddressTxsUtxo: (address: string) => Promise<AddressTxsUtxo[]>;
|
||||
}
|
||||
|
||||
export interface AddressTxsUtxo {
|
||||
txid: string;
|
||||
vout: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
value: number;
|
||||
}
|
||||
export interface Block {
|
||||
id: string;
|
||||
height: number;
|
||||
version: number;
|
||||
timestamp: number;
|
||||
tx_count: number;
|
||||
size: number;
|
||||
weight: number;
|
||||
merkle_root: string;
|
||||
previousblockhash: string;
|
||||
mediantime: number;
|
||||
nonce: number;
|
||||
bits: number;
|
||||
difficulty: number;
|
||||
}
|
||||
|
||||
export interface BlockInstance {
|
||||
getBlock: (hash: string) => Promise<Block>;
|
||||
getBlocks: (params: { start_height?: number }) => Promise<Block>;
|
||||
getBlockStatus: (hash: string) => Promise<BlockStatus>;
|
||||
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
|
||||
getBlockTxids: (hash: string) => Promise<string[]>;
|
||||
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
|
||||
getBlockRaw: (hash: string) => Promise<string>;
|
||||
getBlockHeight: (height: number) => Promise<string>;
|
||||
getBlocksTipHeight: () => Promise<number>;
|
||||
getBlocksTipHash: () => Promise<string>;
|
||||
}
|
||||
|
||||
export interface BlockStatus {
|
||||
in_best_chain: boolean;
|
||||
height: number;
|
||||
next_best: string;
|
||||
}
|
||||
|
||||
export interface FeeInstance {
|
||||
getFeesRecommended: () => Promise<FeesRecommended>;
|
||||
getFeesMempoolBlocks: () => Promise<FeesMempoolBlocks[]>;
|
||||
}
|
||||
|
||||
export interface FeesMempoolBlocks {
|
||||
blockSize: number;
|
||||
blockVSize: number;
|
||||
nTx: number;
|
||||
totalFees: number;
|
||||
medianFee: number;
|
||||
feeRange: number[];
|
||||
}
|
||||
|
||||
export interface FeesRecommended {
|
||||
fastestFee: number;
|
||||
halfHourFee: number;
|
||||
hourFee: number;
|
||||
minimumFee: number;
|
||||
}
|
||||
|
||||
export interface Mempool {
|
||||
count: number;
|
||||
vsize: number;
|
||||
total_fee: number;
|
||||
fee_histogram: number[];
|
||||
}
|
||||
|
||||
export interface MempoolConfig {
|
||||
apiEndpoint?: string;
|
||||
websocketEndpoint?: string;
|
||||
}
|
||||
|
||||
export interface MempoolInstance {
|
||||
getMempool: () => Promise<Mempool[]>;
|
||||
getMempoolTxids: () => Promise<string[]>;
|
||||
getMempoolRecent: () => Promise<MempoolRecent[]>;
|
||||
}
|
||||
|
||||
export interface MempoolReturn {
|
||||
addresses: AddressInstance;
|
||||
blocks: BlockInstance;
|
||||
fees: FeeInstance;
|
||||
mempool: MempoolInstance;
|
||||
transactions: TxInstance;
|
||||
websocket: WsInstance;
|
||||
}
|
||||
|
||||
export interface MempoolRecent {
|
||||
txid: string;
|
||||
fee: number;
|
||||
vsize: number;
|
||||
value: number;
|
||||
}
|
||||
|
||||
export interface Tx {
|
||||
txid: string;
|
||||
version: number;
|
||||
locktime: number;
|
||||
vin: {
|
||||
txid: string;
|
||||
vout: number;
|
||||
prevout: {
|
||||
scriptpubkey: string;
|
||||
scriptpubkey_asm: string;
|
||||
scriptpubkey_type: string;
|
||||
scriptpubkey_address: string;
|
||||
value: number;
|
||||
};
|
||||
scriptsig: string;
|
||||
scriptsig_asm: string;
|
||||
is_coinbase: boolean;
|
||||
sequence: string;
|
||||
}[];
|
||||
vout: {
|
||||
scriptpubkey: string;
|
||||
scriptpubkey_asm: string;
|
||||
scriptpubkey_type: string;
|
||||
scriptpubkey_address: string;
|
||||
value: number;
|
||||
}[];
|
||||
size: number;
|
||||
weight: number;
|
||||
fee: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TxStatus {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
}
|
||||
|
||||
export interface TxMerkleProof {
|
||||
block_height: number;
|
||||
merkle: string[];
|
||||
pos: number;
|
||||
}
|
||||
|
||||
export interface TxOutspend {
|
||||
spent: boolean;
|
||||
txid: string;
|
||||
vin: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TxInstance {
|
||||
getTx: (txid: string) => Promise<Tx>;
|
||||
getTxStatus: (txid: string) => Promise<TxStatus>;
|
||||
getTxHex: (txid: string) => Promise<string>;
|
||||
getTxRaw: (txid: string) => Promise<string>;
|
||||
getTxMerkleBlockProof: (txid: string) => Promise<string>;
|
||||
getTxMerkleProof: (txid: string) => Promise<Array<TxMerkleProof>>;
|
||||
getTxOutspend: (params: {
|
||||
txid: string;
|
||||
vout: number;
|
||||
}) => Promise<TxOutspend>;
|
||||
getTxOutspends: (txid: string) => Promise<Array<TxOutspend>>;
|
||||
postTx: (txid: string) => Promise<unknown>;
|
||||
}
|
||||
|
||||
export interface WsInterface {
|
||||
options: string[];
|
||||
}
|
||||
|
||||
export interface WsInstance {
|
||||
initClient: ({ options }: WsInterface) => WebSocket;
|
||||
initServer: ({ options }: WsInterface) => WebSocketServer;
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import api from './api';
|
||||
|
||||
const getMempool = async () => {
|
||||
return api
|
||||
.get(`/mempool`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
count: number;
|
||||
vsize: number;
|
||||
total_fee: number;
|
||||
fee_histogram: number[];
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getMempoolTxids = async () => {
|
||||
return api
|
||||
.get(`/mempool/txids`)
|
||||
.then((res: { data: string[] }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getMempoolRecent = async () => {
|
||||
return api
|
||||
.get(`/mempool/recent`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
fee: number;
|
||||
vsize: number;
|
||||
value: number;
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
getMempool,
|
||||
getMempoolTxids,
|
||||
getMempoolRecent,
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
|
||||
export const makeAPI = (apiEndpoint?: string): { api: AxiosInstance } => {
|
||||
const api = axios.create({
|
||||
baseURL: apiEndpoint,
|
||||
});
|
||||
return {
|
||||
api,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
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' }));
|
||||
setInterval(function timeout() {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
action: 'want',
|
||||
data: options,
|
||||
})
|
||||
);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
export default browserWS;
|
||||
@@ -0,0 +1,26 @@
|
||||
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' }));
|
||||
setInterval(function timeout() {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
action: 'want',
|
||||
data: options,
|
||||
})
|
||||
);
|
||||
}, 500);
|
||||
};
|
||||
export default serverWS;
|
||||
@@ -1,250 +0,0 @@
|
||||
import api from './api';
|
||||
|
||||
const getTx = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
txid: string;
|
||||
version: number;
|
||||
locktime: number;
|
||||
vin: {
|
||||
txid: string;
|
||||
vout: number;
|
||||
prevout: {
|
||||
scriptpubkey: string;
|
||||
scriptpubkey_asm: string;
|
||||
scriptpubkey_type: string;
|
||||
scriptpubkey_address: string;
|
||||
value: number;
|
||||
};
|
||||
scriptsig: string;
|
||||
scriptsig_asm: string;
|
||||
is_coinbase: boolean;
|
||||
sequence: string;
|
||||
}[];
|
||||
vout: {
|
||||
scriptpubkey: string;
|
||||
scriptpubkey_asm: string;
|
||||
scriptpubkey_type: string;
|
||||
scriptpubkey_address: string;
|
||||
value: number;
|
||||
}[];
|
||||
size: number;
|
||||
weight: number;
|
||||
fee: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxStatus = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/status`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxHex = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/hex`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxRaw = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/raw`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxMerkleBlockProof = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/merkleblock-proof`)
|
||||
.then((res: { data: string }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxMerkleProof = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/merkle-proof`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
block_height: number;
|
||||
merkle: string[];
|
||||
pos: number;
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxOutspend = async (params: { txid: string; vout: number }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/outspend/${params.vout}`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
spent: boolean;
|
||||
txid: string;
|
||||
vin: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
};
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const getTxOutspends = async (params: { txid: string }) => {
|
||||
return api
|
||||
.get(`/tx/${params.txid}/outspends`)
|
||||
.then(
|
||||
(res: {
|
||||
data: {
|
||||
spent: boolean;
|
||||
txid: string;
|
||||
vin: number;
|
||||
status: {
|
||||
confirmed: boolean;
|
||||
block_height: number;
|
||||
block_hash: string;
|
||||
block_time: number;
|
||||
};
|
||||
}[];
|
||||
}) => {
|
||||
return res.data;
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const postTx = async (params: { txid: string }) => {
|
||||
return api
|
||||
.post(`/tx`, { txid: params.txid })
|
||||
.then((res: { data: any }) => {
|
||||
return res.data;
|
||||
})
|
||||
.catch(
|
||||
(err: {
|
||||
response: {
|
||||
data: string;
|
||||
};
|
||||
}) => {
|
||||
throw err.response.data;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default {
|
||||
getTx,
|
||||
getTxStatus,
|
||||
getTxHex,
|
||||
getTxRaw,
|
||||
getTxMerkleBlockProof,
|
||||
getTxMerkleProof,
|
||||
getTxOutspend,
|
||||
getTxOutspends,
|
||||
postTx,
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
const WebSocket = require('ws');
|
||||
|
||||
const ws = new WebSocket('wss://mempool.space/api/v1/ws');
|
||||
|
||||
const init = (params: { options: string[] }) => {
|
||||
ws.on('open', function open() {
|
||||
ws.send(JSON.stringify({ action: 'init' }));
|
||||
setInterval(function timeout() {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
action: 'want',
|
||||
data: params.options,
|
||||
})
|
||||
);
|
||||
}, 500);
|
||||
});
|
||||
return ws;
|
||||
};
|
||||
|
||||
export default {
|
||||
init,
|
||||
};
|
||||
+4
-1
@@ -2,9 +2,12 @@
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES6", "DOM"],
|
||||
"declaration": true,
|
||||
"outDir": "./lib",
|
||||
"strict": true
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "**/__tests__/*"]
|
||||
|
||||
Reference in new issue
Block a user