Skip to content

Commit

Permalink
Merge pull request #812 from EYBlockchain/liju.jose/refactor-wallet-c…
Browse files Browse the repository at this point in the history
…ircuitsFiles

refactor aws circuits path in config
  • Loading branch information
Westlad authored Jul 29, 2022
2 parents d0e3533 + 83652aa commit af121cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 65 deletions.
58 changes: 15 additions & 43 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ function configureAWSBucket() {
return `${bucket}-${mode}`;
}

function parseCircuitFilesPath() {
let circuits = ['deposit', 'withdraw', 'single_transfer', 'double_transfer'];
if (process.env.USE_STUBS === 'true') circuits = circuits.map(circuit => `${circuit}_stub`);
const parsedPath = {};
for (const circuit of circuits) {
parsedPath[circuit] = {
abi: `circuits/${circuit}/artifacts/${circuit}-abi.json`,
program: `circuits/${circuit}/artifacts/${circuit}-program`,
pk: `circuits/${circuit}/keypair/${circuit}_pk.key`,
};
}
return parsedPath;
}

/* eslint-disable no-extend-native */
BigInt.prototype.toJSON = function () {
return `${this.toString()} BigInt`;
Expand Down Expand Up @@ -440,51 +454,9 @@ module.exports = {

KEYS_COLLECTION: 'keys',
DEFAULT_ACCOUNT_NUM: 10,
circuitsAWSFiles: {
deposit_stub: {
abi: 'circuits/deposit_stub/artifacts/deposit_stub-abi.json',
program: 'circuits/deposit_stub/artifacts/deposit_stub-program',
pk: 'circuits/deposit_stub/keypair/deposit_stub_pk.key',
},
withdraw_stub: {
abi: 'circuits/withdraw_stub/artifacts/withdraw_stub-abi.json',
program: 'circuits/withdraw_stub/artifacts/withdraw_stub-program',
pk: 'circuits/withdraw_stub/keypair/withdraw_stub_pk.key',
},
single_transfer_stub: {
abi: 'circuits/single_transfer_stub/artifacts/single_transfer_stub-abi.json',
program: 'circuits/single_transfer_stub/artifacts/single_transfer_stub-program',
pk: 'circuits/single_transfer_stub/keypair/single_transfer_stub_pk.key',
},
double_transfer_stub: {
abi: 'circuits/double_transfer_stub/artifacts/double_transfer_stub-abi.json',
program: 'circuits/double_transfer_stub/artifacts/double_transfer_stub-program',
pk: 'circuits/double_transfer_stub/keypair/double_transfer_stub_pk.key',
},
deposit: {
abi: 'circuits/deposit/artifacts/deposit-abi.json',
program: 'circuits/deposit/artifacts/deposit-program',
pk: 'circuits/deposit/keypair/deposit_pk.key',
},
withdraw: {
abi: 'circuits/withdraw/artifacts/withdraw-abi.json',
program: 'circuits/withdraw/artifacts/withdraw-program',
pk: 'circuits/withdraw/keypair/withdraw_pk.key',
},
single_transfer: {
abi: 'circuits/single_transfer/artifacts/single_transfer-abi.json',
program: 'circuits/single_transfer/artifacts/single_transfer-program',
pk: 'circuits/single_transfer/keypair/single_transfer_pk.key',
},
double_transfer: {
abi: 'circuits/double_transfer/artifacts/double_transfer-abi.json',
program: 'circuits/double_transfer/artifacts/double_transfer-program',
pk: 'circuits/double_transfer/keypair/double_transfer_pk.key',
},
},

AWS: {
s3Bucket: configureAWSBucket(),
circuitFiles: parseCircuitFilesPath(),
},

utilApiServerUrl: process.env.LOCAL_UTIL_API_URL,
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/nightfall-browser/services/fetch-circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ async function fetchAWSfiles(Bucket, Key) {

export default async function fetchCircuit(
circuit,
{ utilApiServerUrl, isLocalRun, circuitsAWSFiles, AWS: { s3Bucket } },
{ utilApiServerUrl, isLocalRun, AWS: { s3Bucket, circuitFiles } },
) {
let { abi, program, pk } = circuitsAWSFiles[circuit]; // keys path in bucket
let { abi, program, pk } = circuitFiles[circuit]; // keys path in bucket
abi = JSON.parse(new TextDecoder().decode(await fetchAWSfiles(s3Bucket, abi)));
program = await fetchAWSfiles(s3Bucket, program);
if (isLocalRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const tokensList = {
name: 'Ether - ERC20 Mock',
symbol: 'ETH',
decimals: 9,
address: '0x9b7bD670D87C3Dd5C808ba627c75ba7E88aD066f',
address: '0x4f3c4F8D4575Cf73c2FAf9F36cc505e19E65B9C0',
logoURI: 'https://wallet-asset.matic.network/img/tokens/eth.svg',
tags: ['pos', 'erc20', 'swapable', 'metaTx'],
id: 'ethereum',
Expand Down
30 changes: 11 additions & 19 deletions wallet/src/web-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,22 @@ import fetchCircuit from 'comlink-loader?singleton!@Nightfall/services/fetch-cir
import { checkIndexDBForCircuit, storeCircuit } from '@Nightfall/services/database';

const {
circuitsAWSFiles,
USE_STUBS,
utilApiServerUrl,
isLocalRun,
AWS: { s3Bucket },
AWS: { s3Bucket, circuitFiles },
} = global.config;

export default async function fetchCircuitFileAndStoreInIndexedDB() {
for (const circuit in circuitsAWSFiles) {
if (
(!USE_STUBS && circuit.slice(-4) !== 'stub') ||
(USE_STUBS && circuit.slice(-4) === 'stub')
) {
if (!(await checkIndexDBForCircuit(circuit))) {
const { abi, program, pk } = await fetchCircuit(circuit, {
utilApiServerUrl,
isLocalRun,
circuitsAWSFiles,
AWS: { s3Bucket },
});
await storeCircuit(`${circuit}-abi`, abi);
await storeCircuit(`${circuit}-program`, program);
await storeCircuit(`${circuit}-pk`, pk);
}
for (const circuit in circuitFiles) {
if (!(await checkIndexDBForCircuit(circuit))) {
const { abi, program, pk } = await fetchCircuit(circuit, {
utilApiServerUrl,
isLocalRun,
AWS: { s3Bucket, circuitFiles },
});
await storeCircuit(`${circuit}-abi`, abi);
await storeCircuit(`${circuit}-program`, program);
await storeCircuit(`${circuit}-pk`, pk);
}
}
}

0 comments on commit af121cb

Please sign in to comment.