diff --git a/dbWrapper/kyc.js b/dbWrapper/kyc.js index c29e371..0c8a292 100644 --- a/dbWrapper/kyc.js +++ b/dbWrapper/kyc.js @@ -23,10 +23,10 @@ const getPendingKycApprovals = async (filter, limit = 10) => { return pendingApprovals; }; -const setKycProcessed = async (id, txnId) => { +const setManyKycProcessed = async (ids, txnId) => { await mongoUtil.getDB() .collection(collections.KYC_APPROVALS) - .updateOne({ _id: id }, { + .update({ _id: { $in: ids } }, { $set: { status: 'processed', txhash: txnId, @@ -56,6 +56,6 @@ const setKycSuccess = async (txhash) => { module.exports = { addPendingKycApproval, getPendingKycApprovals, - setKycProcessed, + setManyKycProcessed, setKycSuccess, }; diff --git a/scripts/kyc.js b/scripts/kyc.js index 118bcbd..96e1432 100644 --- a/scripts/kyc.js +++ b/scripts/kyc.js @@ -2,7 +2,7 @@ const EthereumTx = require('ethereumjs-tx'); const { getPendingKycApprovals, - setKycProcessed, + setManyKycProcessed, setKycSuccess, } = require('../dbWrapper/kyc'); @@ -30,26 +30,33 @@ const { const keystore = require('../keystore/kyc-admin.json'); -const _getCallData = (entry) => { +const _getField = (entries, fieldName) => { + const fields = []; + entries.forEach((entry) => { + fields.push(entry[fieldName]); + }); + return fields; +}; + +const _getCallData = (entries) => { return getContracts() .daoIdentity - .updateKyc + .bulkUpdateKyc .request( - entry.address, - '', // empty doc hash - entry.id_expiration, + _getField(entries, 'address'), '', + _getField(entries, 'id_expiration'), ) .params[0] .data; }; -const _txnObject = (entry, kycAdmin, nonce) => { +const _txnObject = (entries, kycAdmin, nonce) => { return { from: kycAdmin, to: getContracts().daoIdentity.address, gas: 300000, gasPrice: 40 * (10 ** 9), - data: _getCallData(entry), + data: _getCallData(entries), nonce, }; }; @@ -71,14 +78,12 @@ const approveKyc = async (entry) => { const processPendingKycs = async () => { const pendingKycApprovals = await getPendingKycApprovals({ status: 'pending' }, 10); if (pendingKycApprovals.length <= 0) return; - for (const entry of pendingKycApprovals) { - try { - const txnId = await approveKyc(entry); - await setKycProcessed(entry._id, txnId); - await insertPendingTransactions([{ txhash: txnId }]); - } catch (e) { - console.log('[ERROR] ', e); - } + try { + const txnId = await approveKyc(pendingKycApprovals); + await setManyKycProcessed(_getField(pendingKycApprovals, '_id'), txnId); + await insertPendingTransactions([{ txhash: txnId }]); + } catch (e) { + console.log('[ERROR] ', e); } };