public override IList <SolidityComponent> GetElementCode(List <ElementConverter> nextElements, IList <SequenceFlow> outgoingSeqFlows, IList <SolidityStruct> dataModel = null) { var logicFunction = new SolidityFunction(gateway.Id + "Logic", SolidityVisibility.Internal); var body = CreateParallelism(nextElements); if (gateway.Incoming.Count == 1) { logicFunction.AddToBody(body); return(new List <SolidityComponent> { logicFunction }); } else { var incomingFlowsVar = new SolidityStatement("int " + incVaribaleName + " = 0"); var ifElseBlock = new SolidityIfElse(); string ifElseCondition = incVaribaleName + "==" + gateway.Incoming.Count.ToString(); body.Add(incVaribaleName + " = 0"); ifElseBlock.AddConditionBlock(ifElseCondition, body); logicFunction.AddToBody(ifElseBlock); return(new List <SolidityComponent> { incomingFlowsVar, logicFunction }); } }
public override void ConvertElementLogic() { processReturnFunction = CreateProcessReturnFunction(); mainFunction = new SolidityFunction(GetElementCallName(), SolidityVisibility.Internal); mainFunction.AddParameters(processConverter.GetIdentifiersAsParameters()); var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity); var callSubprocessStatement = calledStartEventConverter.GetStatementForPrevious(callActivity); stateTracker = new SolidityStatement($"uint256 {ConversionTemplates.CallActivityCounter(GetElementCallName())}"); switch (callActivity.InstanceType) { case InstanceType.Single: //Call the subprocess. mainFunction.AddToBody(callSubprocessStatement); break; case InstanceType.Sequential: //Call the subprocess and create a counter. mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0")); mainFunction.AddToBody(callSubprocessStatement); break; case InstanceType.Parallel: //Call all of the subprocesses using an identifier, create a counter. mainFunction.AddToBody(new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} = 0")); var solidityForLoop = new SolidityFor(GetLoopVariable(), GetCountTarget(callActivity)); solidityForLoop.AddToBody(callSubprocessStatement); mainFunction.AddToBody(solidityForLoop); break; } }
SolidityFunction CreateElementMainFunction(ElementConverter nextElement, List <SolidityStruct> dataModel) { SolidityFunction function = new SolidityFunction(GetTaskName(), SolidityVisibility.Public); function.AddModifier("is" + GetTaskName() + "State"); if (userTask.Assignee != null && (userTask.Assignee.Address != null || userTask.Assignee.Name != null)) { function.AddModifier("is" + GetTaskName() + "Authorized"); } SolidityStatement statement = new SolidityStatement(ProcessConverter.ACTIVE_STATES_NAME + "[\"" + GetTaskName() + "\"] = false"); function.AddToBody(statement); if (userTask.Form.Fields != null) { foreach (var field in userTask.Form.Fields) { foreach (var s in dataModel) { Property p = s.En.Properties.FirstOrDefault(p => p.Id == field.PropertyExpression); if (p != null) { function.AddParameter(new SolidityParameter(Helpers.GetSolidityStringType(p), field.DisplayName)); function.AddToBody(new SolidityStatement(s.VariableName() + "." + Helpers.GetPropertyVariableName(p.Name) + " = " + field.DisplayName)); } } } } function.AddToBody(nextElement.GetStatementForPrevious(userTask)); return(function); }
public override SolidityStatement GetStatementForPrevious(ProcessElement previous) { SolidityStatement statement = new SolidityStatement(); statement.Add(GetFunctionCallStatement()); return(statement); }
SolidityStatement CreateParallelism(List <ElementConverter> nextElements) { var statement = new SolidityStatement(); nextElements.ForEach(e => { e.GetStatementForPrevious(gateway).GetStatements().ForEach(e => statement.Add(e)); }); return(statement); }
public void OneLineStatementTest() { var statement = new SolidityStatement(); statement.Add(line1); Assert.Equal(line1 + ";\n", statement.ToString()); }
public void NoSemicolonTest() { var statement = new SolidityStatement(); statement.Add(line1, false); Assert.Equal(line1 + "\n", statement.ToString()); }
SolidityModifier CreateAddressGuard() { //Initialize the modifier using the generated name SolidityModifier addressGuard = new SolidityModifier(ConversionTemplates.AddressGuardModifierName(GetElementCallName())); addressGuard.AddParameters(processConverter.GetIdentifiersAsParameters()); //Address is force assigned if (userTaskElement.Assignee.Address != null) { SolidityStatement requireStatement = new SolidityStatement($"require(msg.sender=={GetAssigneeAddress()})"); addressGuard.AddToBody(requireStatement); } //Address is not force assigned, it will be assigned to the first caller of the first task method containing this assignee else if (userTaskElement.Assignee.Name != null) { var addressPosition = $"{ConverterConfig.ADDRESS_MAPPING_VAR_NAME}[\"{userTaskElement.Assignee.Name}\"]"; var ifElseBlock = new SolidityIfElse(); //Assigns the address, if address has not been been yet assigned to the assignee ifElseBlock.AddConditionBlock($"{addressPosition} == address(0x0)", new SolidityStatement($"{addressPosition} = msg.sender")); //Checks whether the sender has the required address SolidityStatement requireStatement = new SolidityStatement($"require(msg.sender=={addressPosition})"); addressGuard.AddToBody(ifElseBlock); addressGuard.AddToBody(requireStatement); } return(addressGuard); }
public override SolidityStatement GetStatementForPrevious(ProcessElement previous) { var statement = new SolidityStatement(); statement.Add(GetChangeActiveStateStatement(true)); statement.Add(GetFunctionCallStatement()); return(statement); }
SolidityStatement CreateNextElementStatement() { var statement = new SolidityStatement(); statement.Add(GetChangeActiveStateStatement(false)); statement.Add(processConverter.GetStatementOfNextElement(callActivity)); return(statement); }
SolidityModifier CreateStateGuard() { SolidityModifier stateGuard = new SolidityModifier("is" + GetTaskName() + "State"); SolidityStatement requireStatement = new SolidityStatement( "require(" + ProcessConverter.IS_STATE_ACTIVE_FUNCTION_NAME + "(\"" + GetTaskName() + "\")==true)"); stateGuard.AddToBody(requireStatement); return(stateGuard); }
public SolidityStatement GetConstructorStatements() { var statement = new SolidityStatement(); foreach (var tokenConverter in tokenConverters) { statement.Add(tokenConverter.GetConstructorStatement()); } return(statement); }
public override SolidityStatement GetStatementForPrevious(ProcessElement previous) { var statement = new SolidityStatement(); if (counterVariablePresent) { statement.Add(new SolidityStatement($"{ConversionTemplates.MultiInstanceCounterVariable(GetElementCallName())} = 0")); } statement.Add(GetChangeActiveStateStatement(true)); return(statement); }
SolidityStatement CreateTouchFunctionLogic(TaskConverter attachedToConverter) { var touchLogic = new SolidityStatement(); //Disable the current state touchLogic.Add(attachedToConverter.GetChangeActiveStateStatement(false)); //place the call statement of the next element touchLogic.Add(processConverter.GetStatementOfNextElement(eventElement)); touchLogic.Add(new SolidityStatement("return false")); return(touchLogic); }
public void FromListTest() { List <string> list = new List <string>(); list.Add(line1); list.Add(line2); var statement = new SolidityStatement(list); Assert.Equal(line1 + ";\n" + line2 + ";\n", statement.ToString()); }
public void GetStatementsTest() { List <string> list = new List <string>(); list.Add(line1); list.Add(line2); var statement = new SolidityStatement(list); var actual = statement.GetStatements(); Assert.True(!list.Except(actual).Any() && list.Count == actual.Count); }
SolidityStatement CreateCallsToOutgoing() { var nextElementConverters = processConverter.GetTargetConvertersOfElement(gatewayElement).ToList(); var statement = new SolidityStatement(); nextElementConverters.ForEach(e => { e.GetStatementForPrevious(gatewayElement).GetStatements(). ForEach(f => statement.Add(f)); }); return(statement); }
public override SolidityStatement GetStatementForPrevious(ProcessElement previous) { var statement = new SolidityStatement(); statement.Add(GetChangeActiveStateStatement(true)); //Call the return function of the parent call element, if it exists if (processConverter.ParentProcessConverter != null) { var callActivityReturnName = ConversionTemplates.CallActivityReturnFunctionName(processConverter.GetParentCallActivityCallName()); statement.Add($"{callActivityReturnName}({processConverter.ParentProcessConverter.GetIdentifierNames()})"); } return(statement); }
public override SolidityStatement GetStatementForPrevious(ProcessElement previous) { SolidityStatement statement = new SolidityStatement(); if (gateway.Incoming.Count > 1) { var commonFlow = gateway.Incoming.Intersect(previous.Outgoing); statement.Add(incVaribaleName + " += 1"); } statement.Add(gateway.Id + "Logic" + "()"); return(statement); }
public override void ConvertElementLogic() { /* * if (IsAddressGuardRequired()) * addressGuard = CreateAddressGuard(); */ stateGuard = CreateStateGuard(); mainFunction = CreateElementMainFunction(); if (userTaskElement.InstanceType != InstanceType.Single) { multiInstanceCounter = CreateMultiInstanceCounterDefinition(); } }
public override IList <SolidityComponent> GetElementCode(List <ElementConverter> nextElements, IList <SequenceFlow> outgoingSeqFlows, IList <SolidityStruct> dataModel = null) { SolidityFunction function = new SolidityFunction(GetTaskName(), SolidityVisibility.Internal); function.AddModifier("is" + GetTaskName() + "State"); SolidityStatement disableFunctionStatement = new SolidityStatement(ProcessConverter.ACTIVE_STATES_NAME + "[\"" + GetTaskName() + "\"] = false"); function.AddToBody(disableFunctionStatement); function.AddToBody(new SolidityStatement(scriptTask.Script, false)); function.AddToBody(nextElements[0].GetStatementForPrevious(scriptTask)); return(new List <SolidityComponent> { CreateStateGuard(), function }); }
LiquidCollection GetDependencies() { LiquidCollection liquidCol = new LiquidCollection(); HashSet <string> dependencies = new HashSet <string>(); dependencies.UnionWith(DataModelConverter.GetDependencies()); foreach (var dependency in dependencies) { var statement = new SolidityStatement($"import {dependency}"); liquidCol.Add(statement.ToLiquidString(0)); } return(liquidCol); }
SolidityModifier CreateStateGuard() { SolidityModifier stateGuard = new SolidityModifier(ConversionTemplates.StateGuardModifierName(GetElementCallName())); stateGuard.AddParameters(processConverter.GetIdentifiersAsParameters()); var activeStateFunctionName = ConversionTemplates.ActiveStatesFunctionName(processConverter.Id); var callParameters = processConverter.GetIdentifierNames(); if (callParameters.Length > 0) { callParameters += ","; } callParameters += $"\"{GetElementCallName()}\""; SolidityStatement requireStatement = new SolidityStatement($"require({activeStateFunctionName}({callParameters}) == true)"); stateGuard.AddToBody(requireStatement); return(stateGuard); }
public SolidityStatement ConvertProperty(Property property) { SolidityStatement propertyStatement = new SolidityStatement(); string propertyType = Helpers.PropertyTypeToString(property, contractConverter); var propertyName = Helpers.ToLowerCamelCase(property.Name); if (property.PropertyType == PropertyType.Single || property.PropertyType == PropertyType.Collection) { propertyStatement.Add($"{propertyType} {propertyName}"); } else if (property.PropertyType == PropertyType.Dictionary) { var keyType = Helpers.PrimitivePropertyTypeToString(property.KeyDataType); propertyStatement.Add(ConversionTemplates.MappingTypeVariableDefinition(propertyName, keyType, propertyType)); //Also an an array to store the key values (used when iteration through the mapping is required) propertyStatement.Add($"{keyType}[] {ConversionTemplates.MappingKeysArrayName(propertyName)}"); } return(propertyStatement); //TODO: exception propertytype not defined }
SolidityModifier CreateAddressGuard() { SolidityModifier addressGuard = new SolidityModifier("is" + GetTaskName() + "Authorized"); if (userTask.Assignee.Address != null) { SolidityStatement requireStatement = new SolidityStatement("require(msg.sender==" + GetAssigneeAddress() + ")"); addressGuard.AddToBody(requireStatement); } else if (userTask.Assignee.Name != null) { var addressPosition = Helpers.ADDRESS_MAPPING_VAR_NAME + "[\"" + userTask.Assignee.Name + "\"]"; var ifElseBlock = new SolidityIfElse(); ifElseBlock.AddConditionBlock(addressPosition + " == address(0x0)", new SolidityStatement(addressPosition + " = msg.sender")); SolidityStatement requireStatement = new SolidityStatement("require(msg.sender==" + addressPosition + ")"); addressGuard.AddToBody(ifElseBlock); addressGuard.AddToBody(requireStatement); } return(addressGuard); }
SolidityFunction CreateProcessReturnFunction() { var function = new SolidityFunction(ConversionTemplates.CallActivityReturnFunctionName(GetElementCallName()), SolidityVisibility.Internal); function.AddParameters(processConverter.GetIdentifiersAsParameters()); var nextElementStatement = CreateNextElementStatement(); var incrementStatement = new SolidityStatement($"{ConversionTemplates.CallActivityCounter(GetElementCallName())}++"); var checkConditionBlock = new SolidityIfElse(); var calledStartEventConverter = processConverter.ContractConverter.GetStartEventConverter(callActivity); var callSubprocessStatement = calledStartEventConverter.GetStatementForPrevious(callActivity); checkConditionBlock.AddConditionBlock($"{ConversionTemplates.CallActivityCounter(GetElementCallName())} >= {GetCountTarget(callActivity)}", nextElementStatement); switch (callActivity.InstanceType) { case InstanceType.Single: function.AddToBody(nextElementStatement); break; case InstanceType.Sequential: //increment the counter, check if counter reached limit. //If counter reached limit, then call the next element. If not, call the subprocess again. function.AddToBody(incrementStatement); checkConditionBlock.AddConditionBlock("", callSubprocessStatement); function.AddToBody(checkConditionBlock); break; case InstanceType.Parallel: //increment the counter, check if counter reached limit. //If counter reached limit, then call the next element. If not, do nothing. function.AddToBody(incrementStatement); function.AddToBody(checkConditionBlock); break; } return(function); }
public override SolidityFunction CreateDecisionFunction() { FunctionName = Regex.Replace(Decision.Id, @" ", "").ToLowerCamelCase(); SolidityFunction function = new SolidityFunction(FunctionName, SolidityVisibility.Internal, $"{OutputStructName} memory", true); //Add declaration of helper varaibles function.AddToBody(new SolidityStatement($"{OutputStructName} memory output", true)); var emptyRule = false; //Add checks of conditions for matches and their bodies var rules = GetAllConditions(); foreach (var rule in rules.Select((value, i) => new { i, value })) { //Assign output if there is already the match string conditionBody = GetConditionBody(rule.i); //If the row is empty then do not put the logic into conditional statement if (string.IsNullOrEmpty(rule.value)) { var condition = new SolidityStatement(conditionBody, false); function.AddToBody(condition); emptyRule = true; break; } else { var condition = new SolidityIfElse(); condition.AddConditionBlock(rule.value, new SolidityStatement(conditionBody, false)); function.AddToBody(condition); } } //Add the rest of the function if (!emptyRule) { function.AddToBody(new SolidityStatement("revert('Undefined output')", true)); } return(function); }
public void EmptyStatementTest() { var statement = new SolidityStatement(); Assert.Equal("", statement.ToString()); }
public override void ConvertElementLogic() { mainFunction = CreateMainFunction(); incomingFlowsVariable = CreateIncomingFlowsVariable(); }
public void AddBoundaryEventCall(SolidityStatement eventCall) { boundaryEventCalls.Add(eventCall); //Update the logic ConvertElementLogic(); }