private static async Task CheckAndRegisterContractFile(IRepository <ContractFile> repository, IBlobContractFileRepository blobContractFileRepository, IReferenceBlobContractFileRepository referenceBlobContractFileRepository, string ownerAddress, IFormFile file) { var fileInfo = new DirectoryInfo(file.FileName); var fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length); var contractFile = (await repository.Find(c => c.OwnerAddress == ownerAddress && c.Name == fileName)).FirstOrDefault() ?? new ContractFile() { Name = fileName, OwnerAddress = ownerAddress, }; if (fileInfo.Extension.ToLower() == ".json") { if (contractFile.IncludesJson) { throw new IOException($"{fileInfo.Name} already exists"); } contractFile.IncludesJson = true; var blobContractFile = await blobContractFileRepository.GetBlobContractFile(ownerAddress, fileName, true, false, false); var targetContractCode = blobContractFile.Abi; var referenceContracts = (await referenceBlobContractFileRepository.GetReferenceContractFiles()).OrderBy(f => f.Name).Reverse(); foreach (var r in referenceContracts) { var f = r.Name; var contractComparer = new ContractComparer(r.Abi.ToString(), targetContractCode.ToString()); if (contractComparer.IsInterfaceImplemented()) { var contractType = f.Split('|')[0]; var version = f.Split('|')[1]; contractFile.ApiType = contractType; contractFile.ApiVersion = version; } } } if (fileInfo.Extension.ToLower() == ".sol") { if (contractFile.IncludesSol) { throw new IOException($"{fileInfo.Name} already exists"); } contractFile.IncludesSol = true; } if (contractFile.Id == 0) { await repository.AddNew(contractFile); } else { await repository.Update(contractFile); } }
public static async Task <IActionResult> CalculateContractFee( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "contractfiles/reference/{contractType}")] HttpRequest req, string contractType, ILogger log, [Inject(typeof(IReferenceBlobContractFileRepository))] IReferenceBlobContractFileRepository referenceBlobContractFileRepository) { var referenceContractFiles = await referenceBlobContractFileRepository.GetReferenceContractFiles(); BlobContractFile blobContractFile = referenceContractFiles.Where(r => r.ContractType == contractType).OrderBy(f => f.Name).Reverse().First(); return(new OkObjectResult(blobContractFile)); }