From 4703e04dd25876450047bc8ea3ea8fe0989fa262 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 22 Nov 2019 15:31:09 +0100 Subject: [PATCH] improve the transaction cache implemented for bitcoind rpc client --- lib/bitcoind-rpc/transactions.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/bitcoind-rpc/transactions.js b/lib/bitcoind-rpc/transactions.js index 275dab8..0990a64 100644 --- a/lib/bitcoind-rpc/transactions.js +++ b/lib/bitcoind-rpc/transactions.js @@ -53,9 +53,11 @@ class Transactions { * @returns {Promise} */ async getTransaction(txid, fees) { + const keyCache = `${txid}-${fees ? '1' : '0'}` + // Return transaction from cache when possible - if (this.txCache.has(txid)) - return this.txCache.get(txid) + if (this.txCache.has(keyCache)) + return this.txCache.get(keyCache) try { const tx = await this.rpcClient.getrawtransaction(txid, true) @@ -107,7 +109,7 @@ class Transactions { // Store in cache if (ret.block && ret.block.hash) - this.txCache.set(txid, ret) + this.txCache.set(keyCache, ret) return ret