Exemple #1
0
        public async Task <ID> DeployAsync(ID id)
        {
            FactoryService factory = new FactoryService(Web3, AccountService.PrivateKey, _factoryAddress);

            //Use the provided Factory address to create an ID + IDController
            Event         idCreationEvent   = factory.GetEventReturnIDController();
            HexBigInteger filterAddressFrom =
                await idCreationEvent.CreateFilterAsync(AccountService.GetAccountAddress());

            await factory.CreateIDAsync();

            List <EventLog <ReturnIDControllerEventDTO> > log =
                await idCreationEvent.GetFilterChanges <ReturnIDControllerEventDTO>(filterAddressFrom);

            string controllerAddress       = log[0].Event._controllerAddress;
            IDControllerService idcService =
                new IDControllerService(Web3, AccountService.PrivateKey, controllerAddress);

            id.ControllerAddress = controllerAddress;
            id.Address           = await idcService.GetIDAsyncCall();

            id.Owner = await idcService.OwnerAsyncCall();


            //Add each attribute from the ID model to the ID smart contract
            foreach (string key in id.Attributes.Keys)
            {
                Attribute attribute = id.GetAttribute(key);
                await AddAttributeAsync(id, attribute);
            }
            return(id);
        }
Exemple #2
0
        //This function will only be used to create the initial ID object on login
        public async Task <ID> GetIDAsync(string address, string[] accessibleAttributes = null)
        {
            IDService idService  = new IDService(Web3, AccountService.PrivateKey, address);
            string    idcAddress = await idService.OwnerAsyncCall();

            IDControllerService idcService = new IDControllerService(Web3, AccountService.PrivateKey, idcAddress);

            ID newID = new ID
            {
                ControllerAddress = idcAddress,
                Address           = address,
                Owner             = await idcService.OwnerAsyncCall()
            };
            //Get attributes from the smart contract and add them to the ID object
            Dictionary <string, Attribute> attributes;

            if (accessibleAttributes != null)
            {
                attributes = await GetAttributesAsync(newID, accessibleAttributes);
            }
            else
            {
                attributes = await GetAttributesAsync(newID);
            }

            newID.Attributes = attributes;

            return(newID);
        }
Exemple #3
0
        private async Task <Attribute> GetAttributeByKey(IDControllerService idcService, byte[] attributeKey)
        {
            string ethAttributeAddress = await idcService.GetAttributeAsyncCall(attributeKey);

            //Get the attribute and add it to the dict
            Attribute attribute = await _attributeFacade.GetAttributeAsync(ethAttributeAddress);

            return(attribute);
        }
Exemple #4
0
        public async Task <Attribute> AddAttributeAsync(ID id, Attribute attribute)
        {
            IDControllerService idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);

            //If the attribute to be added is not yet deployed, deploy it
            if (attribute.Address == null)
            {
                attribute = await _attributeFacade.DeployAsync(attribute, id.Address);
            }


            await idcService.AddAttributeAsync(attribute.Address);

            return(attribute);
        }
        protected async Task DeployIDControllerAsync()
        {
            string transactionHash = await IDControllerService.DeployContractAsync(
                Web3, AddressFrom, ID.GetAddress(), new HexBigInteger(3905820));

            TransactionReceipt receipt = await
                                         Web3.Eth.Transactions.GetTransactionReceipt.
                                         SendRequestAsync(transactionHash);

            IDController = new IDControllerService(Web3, receipt.ContractAddress);

            //Change the owner of the ID to make the ID controller the owner
            transactionHash = await ID.ChangeOwnerAsync(AddressFrom, IDController.GetAddress(), new HexBigInteger(3905820));

            Assert.NotNull(transactionHash);
        }
Exemple #6
0
        public async Task <Dictionary <string, Attribute> > GetAttributesAsync(ID id)
        {
            IDControllerService            idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);
            Dictionary <string, Attribute> dict       = new Dictionary <string, Attribute>();

            BigInteger attributes = await idcService.AttributeCountAsyncCall();

            for (BigInteger i = 0; i < attributes; i++)
            {
                //Get all attribute keys and addresses for the ID
                byte[] attributeKey = await idcService.GetAttributeKeyAsyncCall(i);

                //Get the attribute and add it to the dict
                Attribute newAttribute = await GetAttributeByKey(idcService, attributeKey);

                dict.Add(newAttribute.Description, newAttribute);
            }

            return(dict);
        }
Exemple #7
0
        public async Task <Dictionary <string, Attribute> > GetAttributesAsync(ID id, string[] accessibleAttributes)
        {
            IDControllerService            idcService = new IDControllerService(Web3, AccountService.PrivateKey, id.ControllerAddress);
            Dictionary <string, Attribute> dict       = new Dictionary <string, Attribute>();

            BigInteger attributes = await idcService.AttributeCountAsyncCall();

            for (BigInteger i = 0; i < attributes; i++)
            {
                //Get all attribute keys and addresses for the ID
                byte[] attributeKey = await idcService.GetAttributeKeyAsyncCall(i);

                string keyStr = Encoding.UTF8.GetString(attributeKey, 0, attributeKey.Length);
                keyStr = keyStr.TrimEnd('\0');//remove null characters at the end of string
                if (accessibleAttributes.Contains(keyStr))
                {
                    //Get the attribute and add it to the dict
                    Attribute newAttribute = await GetAttributeByKey(idcService, attributeKey);

                    dict.Add(newAttribute.Description, newAttribute);
                }
            }
            return(dict);
        }