Skip to content

Commit

Permalink
last update remove extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
kKahina committed Mar 28, 2024
1 parent d09b77e commit 02db13f
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 142 deletions.
4 changes: 2 additions & 2 deletions src/boilerplate/common/commitment-storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export async function getNullifiedCommitments() {
}

/**
* Retourne la somme des valeurs de tous les engagements nullifiés.
* @returns {Promise<number>} La somme des valeurs de tous les engagements nullifiés.
* Retourne la somme des valeurs de tous les engagements non nullifiés.
* @returns {Promise<number>} La somme des valeurs de tous les engagements non nullifiés.
*/
export async function getBalance() {
const connection = await mongo.connection(MONGO_URL);
Expand Down
39 changes: 0 additions & 39 deletions src/boilerplate/common/web3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,5 @@ export default {
};


/*import Web3 from 'web3';
import config from 'config';
import logger from './logger.mjs';
export default {
connection() {
if (!this.web3) this.connect();
return this.web3;
},
connect() {
if (this.web3) return this.web3.currentProvider;
logger.http('Blockchain Connecting ...');
const provider = new Web3.providers.WebsocketProvider(
config.web3.url,
null,
config.web3.options,
);
provider.on('error', console.error);
provider.on('connect', () => logger.http('Blockchain Connected ...'));
provider.on('end', console.error);

this.web3 = new Web3(provider);
return provider;
},
* @return {Boolean} - Resolves to true or false
isConnected() {
if (this.web3) {
return this.web3.eth.net.isListening();
}
return false;
},
};*/

Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,7 @@ export function buildPrivateStateNode(nodeType: string, fields: any = {}): any {
throw new TypeError(nodeType);
}
}
export function buildPublicStateNode(nodeType: string, fields: any = {}): any {
switch (nodeType) {
case 'SendTransaction': {
const {

accessedOnly,
} = fields;
return {
nodeType,
accessedOnly,
};
}
// Ajoutez d'autres cas selon les besoins pour d'autres types de nœuds
default:
throw new TypeError(nodeType);
}
}



/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class BoilerplateGenerator {
`\nimport fs from 'fs';
\n`,
`\nimport { getContractInstance, getContractAddress, registerKey } from './common/contract.mjs';`,
`\nimport { storeCommitment, getCurrentWholeCommitment, getCommitmentsById, getAllCommitments, getInputCommitments, joinCommitments, markNullified,getnullifierMembershipWitness,getupdatedNullifierPaths,temporaryUpdateNullifier,updateNullifierTree,} from './common/commitment-storage.mjs';`,
`\nimport { storeCommitment, getCurrentWholeCommitment, getCommitmentsById, getAllCommitments, getInputCommitments, joinCommitments, markNullified,getnullifierMembershipWitness,getupdatedNullifierPaths,temporaryUpdateNullifier,updateNullifierTree} from './common/commitment-storage.mjs';`,
`\nimport { generateProof } from './common/zokrates.mjs';`,
`\nimport { getMembershipWitness, getRoot } from './common/timber.mjs';`,
`\nimport Web3 from './common/web3.mjs';`,
Expand Down
39 changes: 4 additions & 35 deletions src/codeGenerators/orchestration/files/toOrchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { collectImportFiles, localFile } from '../../common.js'
import OrchestrationBP from '../../../boilerplate/orchestration/javascript/raw/boilerplate-generator.js';
import codeGenerator from '../nodejs/toOrchestration.js';
import logger from '../../../utils/logger.js';
import { StateVariableIndicator, FunctionDefinitionIndicator } from '../../../traverse/Indicator.js';



/**
Expand Down Expand Up @@ -147,31 +147,6 @@ const prepareIntegrationApiServices = (node: any) => {
let structparams;
const paramName = fn.parameters.parameters.map((obj: any) => obj.name);


const parameters = fn.parameters.parameters;
const modifiedStateVariables = fn.parameters.modifiedStateVariables;

// Check if the function interacts with secret or public data
let interactsWithSecret = false;
let interactsWithPublic = false;

parameters.forEach(param => {
if (param.isSecret) {
interactsWithSecret = true;
} else {
interactsWithPublic = true;
}
});

modifiedStateVariables.forEach(stateVar => {
if (stateVar.isSecret) {
interactsWithSecret = true;
} else {
interactsWithPublic = true;
}
});


fn.parameters.parameters.forEach(p => {
if (p.typeName.isStruct) {
structparams = `{ ${p.typeName.properties.map(prop => `${prop.name}: req.body.${p.name}.${prop.name}`)}}`;
Expand All @@ -191,7 +166,7 @@ const prepareIntegrationApiServices = (node: any) => {
// Adding Return parameters
let returnParams: string[] = [];

console.log(`${fn.name} interacts with secret data`);

let returnParamsName = fn.returnParameters.parameters.filter((paramnode: any) => (paramnode.isSecret || paramnode.typeName.name === 'bool')).map(paramnode => (paramnode.name)) || []; // Adapt
if(returnParamsName.length > 0){
returnParamsName.forEach(param => {
Expand All @@ -203,14 +178,8 @@ const prepareIntegrationApiServices = (node: any) => {
returnParams.push('bool');
});
}
// Handle functions that interact with public data
console.log(`${fn.name} interacts with public data`);
fnboilerplate = fnboilerplate.replace(/const { tx , encEvent, _RESPONSE_} = await FUNCTION_NAME\(FUNCTION_SIG\);/, 'const { tx } = await FUNCTION_NAME(FUNCTION_SIG);');
fnboilerplate = fnboilerplate.replace(/res.send\({tx, encEvent, _RESPONSE_}\);/, 'res.send({tx});');

//let returnParamsName = fn.returnParameters.parameters.filter((paramnode) => paramnode.isSecret).map((paramnode) => paramnode.name) || [];

// to close if (fn.isSecret)


// replace the signature with test inputs
fnboilerplate = fnboilerplate.replace(/const FUNCTION_SIG/g, fnParam);
fnboilerplate = fnboilerplate.replace(/,const/g, `const`);
Expand Down
48 changes: 1 addition & 47 deletions src/transformers/visitors/toOrchestrationVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,53 +319,7 @@ const visitor = {
);
}
}
} /*else if (!scope.modifiesSecretState()) {
const contractName = `${parent.name}Shield`;
const fnName = path.getUniqueFunctionName();
node.fileName = fnName;
// After getting an appropriate Name , we build the node
const newNode = buildNode('File', {
fileName: fnName, // the name of this function
fileExtension: '.mjs',
nodes: [
buildNode('Imports'),
buildNode('FunctionDefinition', { name: node.name, contractName }),
],
});
node._newASTPointer = newNode.nodes[1]; // eslint-disable-line prefer-destructuring
parent._newASTPointer.push(newNode);
for (const file of parent._newASTPointer) {
if (file.nodes?.[0].nodeType === 'IntegrationTestBoilerplate') {
file.nodes[0].functions.push(
buildNode('IntegrationTestFunction', {
name: fnName,
parameters: [],
}),
);
}
if (file.nodes?.[0].nodeType === 'IntegrationApiServicesBoilerplate') {
file.nodes[0].functions.push(
buildNode('IntegrationApiServiceFunction', {
name: fnName,
parameters: [],
returnParameters:[],
}),
);
}
if (file.nodes?.[0].nodeType === 'IntegrationApiRoutesBoilerplate') {
file.nodes[0].functions.push(
buildNode('IntegrationApiRoutesFunction', {
name: fnName,
parameters: [],
}),
);
}
} }*/

}
else {
state.skipSubNodes = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/traverse/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class Binding {
export class VariableBinding extends Binding {
isSecret: boolean;
stateVariable: boolean;
isPublic: boolean;


isModified: boolean;
modificationCount: number = 0;
Expand Down

0 comments on commit 02db13f

Please sign in to comment.