Browse Source
Merge pull request #94 from Samourai-Wallet/fix_txs_cache
improve the transaction cache implemented for bitcoind rpc client
umbrel
kenshin samourai
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
5 additions and
3 deletions
-
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 |
|
|
|
|
|
|
|