public async Task <bool> CertifyCandidateUser(CandidateMicroCredentialCourse candidateMicroCredentialCourse) { var candidate = _unitOfWork.CandidateRepository.GetById(candidateMicroCredentialCourse.CandidateId); var microCredential = _unitOfWork.MicroCredentialRepository.GetById(candidateMicroCredentialCourse.MicroCredentialId); var moocProvider = _unitOfWork.MoocProviderRepository.GetAll().FirstOrDefault(m => m.MoocProviderId == microCredential.MoocProviderId); if (moocProvider == null) { throw new Exception($"MoocProvider Cannot be null, for MicroCredentialId = {microCredential.MoocProviderId}"); } var stratisBlockDataToSign = _moocMicroCredentialProvider.GetUserDataToCertify(candidate.EmailAddress, moocProvider.EmailAddress, microCredential); var signature = _moocMicroCredentialProvider.CreateSignature(stratisBlockDataToSign); //_moocMicroCredentialProvider.StratisMineBlockThenReturnResponse(stratisBlockDataSigned); //var signBlockRequest = new SignBlockRequest { externalAddress = ConfigurationManager.AppSettings["ExternalAddress"], message = signature /*stratisBlockDataToSign*/, walletName = ConfigurationManager.AppSettings["StratisWalletName"], password = ConfigurationManager.AppSettings["StratisWalletAccountPassword"] }; //var signature = _moocMicroCredentialProvider.StratisApiFullfilRequestComponent.SignBlockData(signBlockRequest).Result; var transactionDataRequest = new TransactionBuildData { accountName = "account 0", allowUnconfirmed = true, shuffleOutputs = true, changeAddress = ConfigurationManager.AppSettings["StratisWalletAddress"], feeType = "medium", walletName = ConfigurationManager.AppSettings["StratisWalletName"], password = ConfigurationManager.AppSettings["StratisWalletAccountPassword"], recipients = new Recipient[] { new Recipient { amount = microCredential.CertificateFee.ToString(), destinationAddress = ConfigurationManager.AppSettings["ExternalAddress"] } } }; var trasaction = await _moocMicroCredentialProvider.StratisApiFullfilRequestComponent.BuildTransaction(transactionDataRequest); var transactionResult = await _moocMicroCredentialProvider.StratisApiFullfilRequestComponent.SendTransaction(trasaction.hex); var candidateCourseCredential = _unitOfWork.CandidateMicroCredentialCourseRepository.GetAll().Where(c => c.MicroCredentialId == candidateMicroCredentialCourse.MicroCredentialId && c.CandidateId == candidateMicroCredentialCourse.CandidateId).FirstOrDefault(); //Save to Hash to DB: if (candidateCourseCredential != null) { candidateCourseCredential.HasPassed = true; candidateCourseCredential.HashOfMine = signature; candidateCourseCredential.transactionHex = trasaction.hex; candidateCourseCredential.transactionId = trasaction.transactionId; candidateCourseCredential.MicroCredentialBadgeId = candidateMicroCredentialCourse.MicroCredentialBadgeId; _unitOfWork.CandidateMicroCredentialCourseRepository.Update(candidateCourseCredential); _unitOfWork.SaveChanges(); return(true); } return(false); }
public async Task <TransactionBuildResponse> BuildTransaction(TransactionBuildData txData) { HttpResponseMessage result = await GetSetHttpClient.PostAsJsonAsync <TransactionBuildData>(ConfigurationManager.AppSettings["BuildTransactionUrl"], txData); return(JsonConvert.DeserializeObject <TransactionBuildResponse>(result.Content.ReadAsStringAsync().Result)); }