Beispiel #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);
        }
        public virtual async Task Setup()
        {
            //create some dummy attributes
            Attribute firstname = new Attribute()
            {
                Location    = "1",
                Hash        = "1",
                Content     = new StringContent("Olivier"),
                Description = "firstname"
            };

            Certificate firstnameCert = new Certificate()
            {
                Hash            = "hash",
                Location        = "location",
                OwningAttribute = firstname,
                Content         = new StringContent("content"),
                Owner           = "0x123456778"
            };

            firstname.AddCertificate(firstnameCert);

            Attribute lastname = new Attribute()
            {
                Location    = "2",
                Hash        = "2",
                Content     = new StringContent("Brochu Dufour"),
                Description = "lastname"
            };

            Certificate lastnameCert = new Certificate()
            {
                Hash            = "hash2",
                Location        = "location2",
                OwningAttribute = lastname,
                Content         = new StringContent("content"),
                Owner           = "0x123456778"
            };

            lastname.AddCertificate(lastnameCert);

            Attribute age = new Attribute()
            {
                Location    = "3",
                Hash        = "3",
                Content     = new IntContent(24),
                Description = "age"
            };

            t = new ID();
            t.AddAttribute(firstname);
            t.AddAttribute(lastname);
            t.AddAttribute(age);

            IFile file = await FileSystem.Current.LocalStorage.CreateFileAsync("mydata.db", CreationCollisionOption.ReplaceExisting);

            var path = file.Path;

            Mapper  = new IDMapper(path, new AttributeMapper(path, new ExternalElementMapper <Certificate>(path)));
            Mapper2 = new IDMapper(path, new AttributeMapper(path, new ExternalElementMapper <Certificate>(path)));
        }