public void ConvertLogic() { tokenContract = new SolidityContract(token.ToStructureName()); tokenContract.AddInheritance(ConverterConfig.OWNABLE_NAME); //constructor tokenContract.AddComponent(CreateConstructor()); //mint tokenContract.AddComponent(CreateMintFunction()); //transfer tokenContract.AddComponent(CreateTransferFunction()); dataModelConverter.AddDependency(ConverterConfig.OWNABLE_IMPORT); if (token.IsFungible) { tokenContract.AddInheritance(ConverterConfig.FUNGIBLE_TOKEN_NAME); dataModelConverter.AddDependency(ConverterConfig.FUNGIBLE_TOKEN_IMPORT); } else { tokenContract.AddInheritance(ConverterConfig.NON_FUNGIBLE_TOKEN_NAME); dataModelConverter.AddDependency(ConverterConfig.NON_FUNGIBLE_TOKEN_IMPORT); } foreach (var property in token.Properties) { tokenContract.AddComponent(dataModelConverter.ConvertProperty(property)); } }
public void TestContractWithFunction() { SolidityContract contract = new SolidityContract("foo"); contract.AddComponent(new SolidityFunction("bar", SolidityVisibility.Public)); var actual = contract.ToString(); var expected = "contract foo { \n" + "\tfunction bar() public {\n" + "\t}\n" + "\n }"; Assert.Equal(expected, actual); }
public ProcessConverter(Contract contract) { process = contract.Process; entities = (List <Entity>)contract.Entities; solidityContract = new SolidityContract("GeneratedContract"); AddDataModel(); // ERC721 HouseToken address, only for Mortgage usecase, remove otherwise solidityContract.AddComponent(new SolidityStatement("IERC721 houseTokenAddress = IERC721(address(0x93b6784CE509d1cEA255aE8269af4Ee258943Bd0))")); //Current state declaration solidityContract.AddComponent(new SolidityStatement("mapping (string => bool) public " + ACTIVE_STATES_NAME)); solidityContract.AddComponent(new SolidityStatement("mapping (string => address) public " + Helpers.ADDRESS_MAPPING_VAR_NAME)); //Method for retrieving current state var getStateFunction = new SolidityFunction(IS_STATE_ACTIVE_FUNCTION_NAME, SolidityVisibility.Public, "bool"); getStateFunction.AddToBody(new SolidityStatement("return " + ACTIVE_STATES_NAME + "[" + STATE_PARAMETER_NAME + "]")); getStateFunction.AddParameter(new SolidityParameter("string", STATE_PARAMETER_NAME)); solidityContract.AddComponent(getStateFunction); IterateProcess(); }
public void ConvertContract() { //Convert data model logic DataModelConverter.ConvertLogic(); //Add enum and struct definitions to the main contract mainSolidityContract.AddComponents(DataModelConverter.GetMainContractComponents()); mainSolidityContract.AddComponent(CreateAddressMapping()); //Convert all processes and add their logic to the main contract foreach (var processConverter in processConverters.Values) { processConverter.ConvertProcess(); mainSolidityContract.AddComponents(processConverter.GetGeneratedSolidityComponents()); } }
//TODO: Working, but not very nice solution. Might need update void AddDataModel() { foreach (var e in entities) { SolidityStruct s = new SolidityStruct(e); SolidityStatement statement = new SolidityStatement(); List <Property> newProperties = new List <Property>(); newProperties.Clear(); foreach (var p in e.Properties) { string type = Helpers.GetSolidityStringType(p); if (!p.IsCollection) { statement.Add(type + " " + Helpers.GetPropertyVariableName(p.Name)); } else if (p.IsCollection) { statement.Add("mapping (uint => " + type + ") " + Helpers.GetPropertyVariableName(p.Name)); Property property = new Property(); string name = Helpers.GetPropertyVariableName(p.Name) + "Length"; property.Type = PropertyType.Int; property.Name = name; statement.Add("uint " + name); newProperties.Add(property); } } foreach (var np in newProperties) { s.En.Properties.Add(np); } s.AddToBody(statement); solidityContract.AddComponent(s); dataModel.Add(s); } }