export function generateLogicAppForMicroservice()

in src/Generators/CodeGenerator/CodeGenerator.ts [23:85]


export function generateLogicAppForMicroservice(
  abi: string,
  contractAddress: string,
  subscriptionId: string,
  location: string,
  solFilePath: string,
) {
  const { variables, functionsDefinitions } = parseSolidityContract(solFilePath);

  const logicApp = getLogicAppTemplate();
  const definition = getDefinitionTemplate();
  const switchBlock = getSwitchTemplate();

  for (const item of [...variables, ...functionsDefinitions]) {
    const actions: { [key: string]: any } = {};
    const action = getActionLogicAppTemplate();
    const bodyParameters: { [key: string]: any } = {};

    if (item.type === 'FunctionDefinition') {
      for (const parameter of item.parameters) {
        bodyParameters[parameter.name] = `@triggerBody()?['${propertyInputParameters}']?['${parameter.name}']`;
      }

      action.inputs.path = `/contract/functions/@{encodeURIComponent(encodeURIComponent('${item.name}'))}/execute`;
    } else {
      action.inputs.path = `/contract/functions/@{encodeURIComponent(encodeURIComponent('${item.name}'))}/query`;
    }

    action.inputs.body = bodyParameters;
    action.inputs.queries.abi = abi;
    action.inputs.queries.contractAddress = contractAddress;
    action.inputs.host.connection.name = `@parameters('$connections')['${propertyBlockchainethereum}']['connectionId']`;

    const actionResponse = getActionResponseTemplate();
    actionResponse.inputs.body = `@body('${item.name}')`;
    actionResponse.runAfter[item.name!] = [ 'Succeeded' ];

    actions[item.name!] = action;
    actions[`${item.name}Response`] = actionResponse;

    const caseBlock = getCaseTemplate();
    caseBlock.case = item.name!;
    caseBlock.actions = actions;

    switchBlock.Switch.cases[`Case_${item.name}`] = caseBlock;
  }

  switchBlock.Switch.expression = `@triggerBody()?['${propertyFunctionName}']`;

  definition.actions = switchBlock;
  definition.triggers.manual.inputs.schema.properties[propertyInputParameters] = { type: 'object' };
  definition.triggers.manual.inputs.schema.properties[propertyFunctionName] = { type: 'string' };

  logicApp.definition = definition;

  logicApp.parameters.$connections.value[propertyBlockchainethereum] = getConnectionValueTemplate();
  logicApp.parameters.$connections.value[propertyBlockchainethereum].connectionId
    = `/subscriptions/${subscriptionId}/resourceGroups/`;
  logicApp.parameters.$connections.value[propertyBlockchainethereum].id
    = `/subscriptions/${subscriptionId}/providers/Microsoft.Web/locations/${location}/managedApis/blockchainethereum`;

  return logicApp;
}