Browse Source

improve the transaction cache implemented for bitcoind rpc client

umbrel
kenshin-samourai 5 years ago
parent
commit
4703e04dd2
  1. 8
      lib/bitcoind-rpc/transactions.js

8
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

Loading…
Cancel
Save