Esempio n. 1
0
        public async Task <ContractAddress> QueryReceipt(string certId, Guid orgId, string txId, int waitBeforeEachQuery = 1000)
        {
            TransactionReceipt            receipt  = default(TransactionReceipt);
            CertificationRegistryContract contract = new CertificationRegistryContract(_web3, EthConnectionData.mastercontractaddr);

            while (true)
            {
                receipt = await _web3.Eth.Transactions.GetTransactionReceipt
                          .SendRequestAsync(txId);

                var logs = receipt?.Logs;

                if (receipt != null)
                {
                    //todo ask henry chuong about orgId on blockchain
                    var certAddress = await contract.GetCertAddressByIdAsync(certId, orgId.ToString("N"));

                    return(new ContractAddress(certId, certAddress));
                }
                else
                {
                    await Task.Delay(waitBeforeEachQuery);
                }
            }
        }
        public async Task <TransactionResult> DeployContract(string accountAddress, string pw, string certId, string orgId, string hash)
        {
            /*
             * Clients retrieve the private key for an account (if stored on their keystore folder) using a password provided to decrypt the file.
             * This is done when unlocking an account, or just at the time of sending a transaction if using personal_sendTransaction with a password.
             */
            bool isUnlocked = await web3.Personal.UnlockAccount.SendRequestAsync(accountAddress, pw, 60);

            CertificationRegistryContract contract = new CertificationRegistryContract(web3, accountAddress, mastercontractaddr);

            var sha       = new SHA512Managed();
            var tempBytes = Encoding.UTF8.GetBytes(hash);
            var hashByte  = sha.ComputeHash(tempBytes);

            var txId = await contract.SetIndividualCertificate(hashByte, certId, orgId, 2_000_000_000);

            return(new TransactionResult(certId, txId));
        }
        public async Task <ContractAddress> QuerryReceipt(string certId, string orgId, string txId, int waitBeforeEachQuerry = 1000)
        {
            TransactionReceipt            receipt  = default(TransactionReceipt);
            CertificationRegistryContract contract = new CertificationRegistryContract(web3, mastercontractaddr);

            while (true)
            {
                receipt = await web3.Eth.Transactions.GetTransactionReceipt
                          .SendRequestAsync(txId);

                var logs = receipt?.Logs;

                if (receipt != null)
                {
                    var certAddress = await contract.GetCertAddressByIdAsync(certId, orgId);

                    return(new ContractAddress(certId, certAddress));
                }
                else
                {
                    await Task.Delay(waitBeforeEachQuerry);
                }
            }
        }