public async Task <IHttpActionResult> DeploySampleContract(int userId) { bool isContractAlreadyExist = _contractRepository.GetAll().ToList() .Where(item => item.Name == CONTRACT_NAME).FirstOrDefault() != null ? true : false; if (!isContractAlreadyExist) { var user = _userRepository.GetByID(userId); if (user != null) { var userAccount = _userAccountRepository.GetAll().ToList().Where(item => item.UserId == user.Id).FirstOrDefault(); var node = _nodeRepository.GetByID(user.NodeId); if (node != null && userAccount != null) { var accessKey = _accessKeyRepository.GetAll().ToList().Where(item => item.NodeId == node.Id).FirstOrDefault(); if (accessKey != null) { var managedAccount = new ManagedAccount(userAccount.Address, userAccount.PrivateKey); var web3Managed = new Web3(managedAccount, accessKey.UrlKey); var service = await HelloService.DeployContractAndGetServiceAsync(web3Managed, new HelloDeployment()); var message = await service.GetMessageQueryAsync(new GetMessageFunction()); _contractRepository.Save(new DLL.DataModels.Contract() { Name = CONTRACT_NAME, Address = service.ContractHandler.ContractAddress, NodeId = node.Id, UserId = user.Id, UserAccountId = userAccount.Id }); return(Ok(message)); } } } } return(Ok("Contract Already Exist")); }
public async Task <IHttpActionResult> CreateUserAccount(int userId, string password) { var user = _userKeyRepository.GetByID(userId); if (user != null) { var node = _nodeRepository.GetByID(user.NodeId); if (node != null) { var accessKey = _accessKeyRepository.GetAll().ToList().Where(item => item.NodeId == node.Id).FirstOrDefault(); if (accessKey != null) { var ecKey = Nethereum.Signer.EthECKey.GenerateKey(); var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex(); var web3 = new Web3Quorum(accessKey.UrlKey); var publicKey = await web3.Personal.NewAccount.SendRequestAsync(privateKey); var userAccount = new UserAccount() { Name = user.Name, Password = privateKey, PublicKey = publicKey, Address = publicKey, UserId = user.Id, PrivateKey = privateKey }; _userAccountKeyRepository.Save(userAccount); } } } //node. //var web3 = new Web3Quorum("https://admintest.blockchain.azure.com:3200/o8rC9YIzD9rZ23lBwwhzqt5M"); //var personalAccountDetails = await web3.Personal.NewAccount.SendRequestAsync(password); return(Ok(200)); }