Esempio n. 1
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());
        }
Esempio n. 2
0
        public IEnumerable <ContractProjectGenerator> FromAbi(string contractName, string abiFilePath, string binFilePath, string baseNamespace, string outputFolder)
        {
            var abi = GeneratorConfigurationUtils.GetFileContent(outputFolder, abiFilePath);

            if (string.IsNullOrEmpty(abi))
            {
                throw new ArgumentException("Could not find abi file or abi content is empty");
            }

            if (string.IsNullOrEmpty(binFilePath))
            {
                binFilePath = abiFilePath.Replace(".abi", ".bin");
            }

            var byteCode = GeneratorConfigurationUtils.GetFileContent(outputFolder, binFilePath);

            if (string.IsNullOrEmpty(contractName))
            {
                contractName = Path.GetFileNameWithoutExtension(abiFilePath);
            }

            var generator = new ProjectGenerator
            {
                Namespace    = baseNamespace,
                OutputFolder = outputFolder,
                Contracts    = new List <ContractDefinition>
                {
                    new ContractDefinition(abi)
                    {
                        ContractName = contractName,
                        Bytecode     = byteCode
                    }
                }
            };

            return(generator.GetProjectGenerators());
        }
Esempio n. 3
0
        public IEnumerable <ContractProjectGenerator> FromTruffle(string directory, string outputFolder, string baseNamespace, CodeGenLanguage language)
        {
            FileAttributes attr = File.GetAttributes(directory);

            var directoryName     = attr.HasFlag(FileAttributes.Directory) ? directory : Path.GetDirectoryName(directory);
            var compiledContracts = Directory.GetFiles(directoryName, "*.json", SearchOption.AllDirectories);
            var contracts         = new List <ContractDefinition>(compiledContracts.Length);

            foreach (var file in compiledContracts)
            {
                var contract = JsonConvert.DeserializeObject <TruffleContract>(File.ReadAllText(file));
                contracts.Add(contract.GetContractConfiguration());
            }

            var generator = new ProjectGenerator
            {
                Language     = language,
                Contracts    = contracts,
                OutputFolder = outputFolder,
                Namespace    = baseNamespace
            };

            return(generator.GetProjectGenerators());
        }