REF: listtransactions from bitcoind

This commit is contained in:
Overtorment 2020-10-12 17:57:03 +01:00
parent ff23e41be7
commit 999f0534e0
2 changed files with 23 additions and 15 deletions

View File

@ -390,22 +390,29 @@ export class User {
} }
} }
let txs = await this._bitcoindrpc.request('listtransactions', ['*', 100500, 0, true]); try {
// now, compacting response a bit let txs = await this._bitcoindrpc.request('listtransactions', ['*', 100500, 0, true]);
let ret = { result: [] }; // now, compacting response a bit
for (const tx of txs.result) { let ret = { result: [] };
ret.result.push({ for (const tx of txs.result) {
category: tx.category, ret.result.push({
amount: tx.amount, category: tx.category,
confirmations: tx.confirmations, amount: tx.amount,
address: tx.address, confirmations: tx.confirmations,
time: tx.time, 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;
} }
/** /**

View File

@ -11,6 +11,7 @@ User storage schema
* refresh_token_for_{userid} = {access_token} * refresh_token_for_{userid} = {access_token}
* importing_{txid} = 1 `atomic lock when processing topup tx` * importing_{txid} = 1 `atomic lock when processing topup tx`
* invoice_paying_for_{userid} = 1 `lock for when payinvoice is in progress` * 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` * preimage_for_{payment_hash_hex} = {preimage_hex} `ttl 1 month`