Example #1
0
        public async Task <Attribute> GetAttributeAsync(string address)
        {
            AttributeService ethAttribute = new AttributeService(Web3, AccountService.PrivateKey, address);

            byte[] descriptionArr = await ethAttribute.DescriptionAsyncCall();

            string description = Encoding.UTF8.GetString(descriptionArr, 0, descriptionArr.Length);

            description = description.TrimEnd('\0');//remove null characters at the end of string

            //Populating attribute object with values from the smart contract
            Attribute attributeModel = new Attribute
            {
                Address     = address,
                Hash        = await ethAttribute.HashAsyncCall(),
                Location    = await ethAttribute.LocationAsyncCall(),
                Owner       = await ethAttribute.OwnerAsyncCall(),
                Description = description
            };

            //Fetch the content of the attribute
            attributeModel.Content = _contentService.GetContent(attributeModel.Location, attributeModel.Hash);

            //Fetching each certificate and adding them to the attribute
            Dictionary <string, Certificate> certificates = await GetCertificatesAsync(attributeModel);

            foreach (Certificate cert in certificates.Values)
            {
                //replace the OwningAttribute placeholder with a complete instance
                cert.OwningAttribute = attributeModel;
                attributeModel.AddCertificate(cert);
            }


            return(attributeModel);
        }