From 2e1348550e15327d8c3175719bf3041376ff9cc2 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Sun, 13 Feb 2022 13:52:04 +0100 Subject: [PATCH 1/2] implement /api/mempool --- backend/src/api/bitcoin/bitcoin-api.interface.ts | 1 + backend/src/api/mempool.ts | 2 +- backend/src/routes.ts | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/api/bitcoin/bitcoin-api.interface.ts b/backend/src/api/bitcoin/bitcoin-api.interface.ts index e2b9158bb..6a22af9a0 100644 --- a/backend/src/api/bitcoin/bitcoin-api.interface.ts +++ b/backend/src/api/bitcoin/bitcoin-api.interface.ts @@ -4,6 +4,7 @@ export namespace IBitcoinApi { size: number; // (numeric) Current tx count bytes: number; // (numeric) Sum of all virtual transaction sizes as defined in BIP 141. usage: number; // (numeric) Total memory usage for the mempool + total_fee: number; // (numeric) Total fees of transactions in the mempool maxmempool: number; // (numeric) Maximum memory usage for the mempool mempoolminfee: number; // (numeric) Minimum fee rate in BTC/kB for tx to be accepted. minrelaytxfee: number; // (numeric) Current minimum relay fee for transactions diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index b1bd6a159..3a389c059 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -14,7 +14,7 @@ class Mempool { private static LAZY_DELETE_AFTER_SECONDS = 30; private inSync: boolean = false; private mempoolCache: { [txId: string]: TransactionExtended } = {}; - private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0, + private mempoolInfo: IBitcoinApi.MempoolInfo = { loaded: false, size: 0, bytes: 0, usage: 0, total_fee: 0, maxmempool: 300000000, mempoolminfee: 0.00001000, minrelaytxfee: 0.00001000 }; private mempoolChangedCallback: ((newMempool: {[txId: string]: TransactionExtended; }, newTransactions: TransactionExtended[], deletedTransactions: TransactionExtended[]) => void) | undefined; diff --git a/backend/src/routes.ts b/backend/src/routes.ts index e06177ddd..e03eb3a03 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -699,7 +699,12 @@ class Routes { } public async getMempool(req: Request, res: Response) { - res.status(501).send('Not implemented'); + const info = mempool.getMempoolInfo(); + res.json({ + count: info.size, + vsize: info.bytes, + total_fee: info.total_fee * 1e8 + }); } public async getMempoolTxIds(req: Request, res: Response) { From 3a3392423d07fc28cdb506a4da88be44525c6241 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Sun, 13 Feb 2022 16:13:46 +0100 Subject: [PATCH 2/2] set fee_histogram to [] --- backend/src/routes.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/routes.ts b/backend/src/routes.ts index e03eb3a03..9e25f0d35 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -703,7 +703,8 @@ class Routes { res.json({ count: info.size, vsize: info.bytes, - total_fee: info.total_fee * 1e8 + total_fee: info.total_fee * 1e8, + fee_histogram: [] }); }