Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbWrapper/kyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -56,6 +56,6 @@ const setKycSuccess = async (txhash) => {
module.exports = {
addPendingKycApproval,
getPendingKycApprovals,
setKycProcessed,
setManyKycProcessed,
setKycSuccess,
};
37 changes: 21 additions & 16 deletions scripts/kyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const EthereumTx = require('ethereumjs-tx');

const {
getPendingKycApprovals,
setKycProcessed,
setManyKycProcessed,
setKycSuccess,
} = require('../dbWrapper/kyc');

Expand Down Expand Up @@ -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,
};
};
Expand All @@ -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);
}
};

Expand Down