From d9900cd4fddf5acf1df2b0bf0efc52dad87d0870 Mon Sep 17 00:00:00 2001 From: Denys Bitaccess Date: Tue, 30 Nov 2021 09:20:43 +0100 Subject: [PATCH] feat: configurable on-chain confirmations target confirmations target as a configurable variable instead of hardcoded const Signed-off-by: Denys Bitaccess --- class/User.js | 10 ++++++---- config.js | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/class/User.js b/class/User.js index a4f8e867..3eb888ee 100644 --- a/class/User.js +++ b/class/User.js @@ -325,18 +325,19 @@ export class User { } /** - * User's onchain txs that are >= 3 confs + * User's onchain txs that are >= configured target confirmations * Queries bitcoind RPC. * * @returns {Promise} */ async getTxs() { const addr = await this.getOrGenerateAddress(); + const targetConfirmations = config.bitcoin.confirmations; let txs = await this._listtransactions(); txs = txs.result; let result = []; for (let tx of txs) { - if (tx.confirmations >= 3 && tx.address === addr && tx.category === 'receive') { + if (tx.confirmations >= targetConfirmations && tx.address === addr && tx.category === 'receive') { tx.type = 'bitcoind_tx'; result.push(tx); } @@ -461,17 +462,18 @@ export class User { } /** - * Returning onchain txs for user's address that are less than 3 confs + * Returning onchain txs for user's address that are less than configured target confirmations * * @returns {Promise} */ async getPendingTxs() { const addr = await this.getOrGenerateAddress(); + const targetConfirmations = config.bitcoin.confirmations; let txs = await this._listtransactions(); txs = txs.result; let result = []; for (let tx of txs) { - if (tx.confirmations < 3 && tx.address === addr && tx.category === 'receive') { + if (tx.confirmations < targetConfirmations && tx.address === addr && tx.category === 'receive') { result.push(tx); } } diff --git a/config.js b/config.js index 840a265a..6f3d73c2 100644 --- a/config.js +++ b/config.js @@ -18,6 +18,9 @@ let config = { url: '1.1.1.1:10009', password: '', }, + bitcoin: { + confirmations: 3, + }, }; if (process.env.CONFIG) {