public GeneratorConfiguration FromConfigFile(string destinationProjectFolder, string assemblyName)
        {
            var configFilePath = GeneratorConfigurationUtils.DeriveConfigFilePath(destinationProjectFolder);

            if (!File.Exists(configFilePath))
            {
                return(null);
            }

            var configuration = GeneratorConfiguration.FromJson(configFilePath);

            if (configuration == null)
            {
                return(null);
            }

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);

            foreach (var abiConfiguration in configuration.ABIConfigurations)
            {
                abiConfiguration.ResolveEmptyValuesWithDefaults(defaultNamespace, destinationProjectFolder);
            }

            return(configuration);
        }
Пример #2
0
        public IEnumerable <ContractProjectGenerator> FromAbiFilesInProject(string projectFileName, string assemblyName, CodeGenLanguage language)
        {
            var projectFolder = Path.GetDirectoryName(projectFileName);
            var abiFiles      = Directory.GetFiles(projectFolder, "*.abi", SearchOption.AllDirectories);
            var contracts     = new List <ContractDefinition>(abiFiles.Length);

            foreach (var file in abiFiles)
            {
                var contractName = Path.GetFileNameWithoutExtension(file);
                var binFileName  = Path.Combine(Path.GetDirectoryName(file), contractName + ".bin");
                var byteCode     = File.Exists(binFileName) ? File.ReadAllText(binFileName) : string.Empty;

                contracts.Add(new ContractDefinition(File.ReadAllText(file))
                {
                    ContractName = contractName,
                    Bytecode     = byteCode
                });
            }

            var generator = new ProjectGenerator
            {
                Language     = language,
                Contracts    = contracts,
                OutputFolder = projectFolder,
                Namespace    = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName)
            };

            return(generator.GetProjectGenerators());
        }
Пример #3
0
        public IEnumerable <ContractProjectGenerator> FromConfigFile(string destinationProjectFolder, string assemblyName)
        {
            var configFilePath = GeneratorConfigurationUtils.DeriveConfigFilePath(destinationProjectFolder);

            if (!File.Exists(configFilePath))
            {
                return(null);
            }

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);
            var configuration    = ABICollectionConfiguration.FromJson(configFilePath);

            return(configuration.GetContractProjectGenerators(defaultNamespace, destinationProjectFolder));
        }
        private static ABIConfiguration CreateAbiConfiguration(string abiFile, string projectFolder, string projectName, string assemblyName, CodeGenLanguage language)
        {
            var contractName = Path.GetFileNameWithoutExtension(abiFile);

            var binFileName = Path.Combine(Path.GetDirectoryName(abiFile), contractName + ".bin");
            var byteCode    = File.Exists(binFileName) ? File.ReadAllText(binFileName) : string.Empty;

            var abiConfig = new ABIConfiguration
            {
                CodeGenLanguage = language,
                ABI             = File.ReadAllText(abiFile),
                ByteCode        = byteCode,
                ContractName    = contractName
            };

            var defaultNamespace = GeneratorConfigurationUtils.CreateNamespaceFromAssemblyName(assemblyName);

            abiConfig.ResolveEmptyValuesWithDefaults(defaultNamespace, projectFolder);
            return(abiConfig);
        }