Example #1
0
        private async Task <IEnumerable <BlobContractFile> > GetReferenceContractFilesFromStore()
        {
            var result     = new List <BlobContractFile>();
            var blobClient = _storageAccount.CreateCloudBlobClient();
            var container  = blobClient.GetContainerReference("contracts");
            var directory  = container.GetDirectoryReference("reference");
            BlobContinuationToken token = null;

            do
            {
                var blobList = await directory.ListBlobsSegmentedAsync(token);

                foreach (CloudBlob referenceFile in blobList.Results)
                {
                    var fileInfo = new DirectoryInfo(referenceFile.Name.Split('/')[1]);
                    if (fileInfo.Extension == ".json")
                    {
                        var fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length);

                        if (!fileName.Contains("|"))
                        {
                            fileName = $"{fileName}|Default";
                        }

                        var referenceContract         = BlobHelper.ReadJsonFromStream(await referenceFile.OpenReadAsync());
                        var referenceContractAbi      = referenceContract["abi"];
                        var referenceContractBytecode = referenceContract["bytecode"].ToString();
                        var r = new BlobContractFile
                        {
                            Name         = fileName,
                            ContractType = fileName.Split('|')[0],
                            Abi          = referenceContractAbi,
                            Bytecode     = referenceContractBytecode,
                        };

                        var jsonblob = directory.GetBlockBlobReference($"{fileName}.json");
                        if (await jsonblob.ExistsAsync())
                        {
                            var content = BlobHelper.ReadStringFromStream(await jsonblob.OpenReadAsync());
                            r.SourceCode = content;
                        }

                        result.Add(r);
                    }
                }
                token = blobList.ContinuationToken;
            }while (token != null);
            return(result);
        }
        public async Task <BlobContractFile> GetBlobContractFile(string owner, string fileName, bool includeAbi, bool includeBytecode, bool includeSourceCode)
        {
            var directory = _blobContainer.GetDirectoryReference(owner);

            var result = new BlobContractFile()
            {
                Name = fileName
            };

            if (includeAbi)
            {
                var blob = directory.GetBlockBlobReference($"{fileName}.json");
                if (await blob.ExistsAsync())
                {
                    var content = BlobHelper.ReadJsonFromStream(await blob.OpenReadAsync());
                    result.Abi = content["abi"];
                }
            }

            if (includeBytecode)
            {
                var blob = directory.GetBlockBlobReference($"{fileName}.json");
                if (await blob.ExistsAsync())
                {
                    var content = BlobHelper.ReadJsonFromStream(await blob.OpenReadAsync());
                    result.Bytecode = content["bytecode"].ToString();
                }
            }

            if (includeSourceCode)
            {
                var blob = directory.GetBlockBlobReference($"{fileName}.sol");
                if (await blob.ExistsAsync())
                {
                    var content = BlobHelper.ReadStringFromStream(await blob.OpenReadAsync());
                    result.SourceCode = content;
                }
            }

            return(result);
        }