From 999f0534e07c461d896101270656f9d38e6c749e Mon Sep 17 00:00:00 2001 From: Overtorment Date: Mon, 12 Oct 2020 17:57:03 +0100 Subject: [PATCH] REF: listtransactions from bitcoind --- class/User.js | 37 ++++++++++++++++++++++--------------- doc/schema.md | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/class/User.js b/class/User.js index 6ad9af5..6a787bb 100644 --- a/class/User.js +++ b/class/User.js @@ -390,22 +390,29 @@ export class User { } } - let txs = await this._bitcoindrpc.request('listtransactions', ['*', 100500, 0, true]); - // now, compacting response a bit - let ret = { result: [] }; - for (const tx of txs.result) { - ret.result.push({ - category: tx.category, - amount: tx.amount, - confirmations: tx.confirmations, - address: tx.address, - time: tx.time, - }); + try { + let txs = await this._bitcoindrpc.request('listtransactions', ['*', 100500, 0, true]); + // now, compacting response a bit + let ret = { result: [] }; + for (const tx of txs.result) { + ret.result.push({ + category: tx.category, + amount: tx.amount, + confirmations: tx.confirmations, + address: tx.address, + time: tx.time, + }); + } + _listtransactions_cache = JSON.stringify(ret); + _listtransactions_cache_expiry_ts = +new Date() + 5 * 60 * 1000; // 5 min + this._redis.set('listtransactions', _listtransactions_cache); + return ret; + } catch (error) { + console.warn('listtransactions error:', error); + let _listtransactions_cache = await this._redis.get('listtransactions'); + if (!_listtransactions_cache) return { result: [] }; + return JSON.parse(_listtransactions_cache); } - _listtransactions_cache = JSON.stringify(ret); - _listtransactions_cache_expiry_ts = +new Date() + 5 * 60 * 1000; // 5 min - this._redis.set('listtransactions', _listtransactions_cache); // backup, will use later TODO - return ret; } /** diff --git a/doc/schema.md b/doc/schema.md index 7f9b90e..466c93e 100644 --- a/doc/schema.md +++ b/doc/schema.md @@ -11,6 +11,7 @@ User storage schema * refresh_token_for_{userid} = {access_token} * importing_{txid} = 1 `atomic lock when processing topup tx` * invoice_paying_for_{userid} = 1 `lock for when payinvoice is in progress` +* generating_address_{userid} = 1 `lock for address generation` * preimage_for_{payment_hash_hex} = {preimage_hex} `ttl 1 month`