public BlockChainControllerTests() { IBlockChain blockChain = new BlockChain(); blockChain.Chain.First.Value.Data = "First Block Data"; Sut = new BlockChainController(blockChain); }
public async Task <IActionResult> PostDataInBlocks([FromBody] DataModel dataModel, [FromQuery] string uniqueKey) { GenericResponse <DataModel> response = new GenericResponse <DataModel>(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userModel = getPrivateKey(uniqueKey); if (userModel != null) { var account = new Account(userModel.PrimaryKey); var web3 = new Nethereum.Geth.Web3Geth(account, "https://ropsten.infura.io/v3/1e1358ffb3db40f69b7bdb6c51d016b6"); BlockChainController blockChainController = new BlockChainController(web3, account); try { var reciept = await blockChainController.SetContractData(dataModel, uniqueKey); if (reciept.Item1 != null) { response.HasError = false; response.Messege = "Sucessfull"; response.Result = dataModel; response.StatusCode = 200; } else { response.HasError = true; response.Messege = "unsucessfull"; response.Result = null; response.StatusCode = 400; } } catch (Exception e) { response.Messege = e.ToString(); } } else { response.HasError = true; response.Messege = "user does not exist"; response.Result = null; response.StatusCode = 400; } return(Ok(response)); }
public async Task <IActionResult> GetWalletTransaction(string uniqueKey) { GenericResponse <List <TransactionModel> > response = new GenericResponse <List <TransactionModel> >(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var credential = getPrivateKey(uniqueKey); if (credential != null) { var account = new Account(credential.PrimaryKey); var web3 = new Nethereum.Geth.Web3Geth(account, "https://ropsten.infura.io/v3/1e1358ffb3db40f69b7bdb6c51d016b6"); BlockChainController blockChainController = new BlockChainController(web3, account); try { var transactionList = await blockChainController.GetTransaction(account.Address); response.HasError = false; response.Messege = "successfull"; response.Result = transactionList; response.StatusCode = 200; } catch (Exception e) { response.HasError = true; response.Messege = e.ToString(); response.Result = null; response.StatusCode = 400; } } else { response.HasError = true; response.Messege = "User does not exist"; response.Result = null; response.StatusCode = 400; } return(Ok(response)); }
public bool LoginMenu() { var controller = new BlockChainController(); Console.Clear(); Console.Out.Flush(); while (true) { Console.WriteLine("================== BlockChain =================="); Console.WriteLine("------------------------- * -----------------------"); Console.WriteLine("1. Dang nhap \t \t 2. Dang ky"); Console.WriteLine("0. Quay lai"); Console.WriteLine("Vui long nhap lua chon cua ban: "); int choice = Int32.Parse(Console.ReadLine()); switch (choice) { case 1: if (!controller.DoLogin()) { return(false); } else { return(true); } case 2: // controller.DoRegister(); Console.WriteLine("Chuc nang dang phat trien!"); return(true); break; case 0: return(false); default: Console.WriteLine("Lua chon sai vui long chon lai!"); break; } } }
public void Menu() { while (true) { Console.Clear(); Console.Out.Flush(); IApplicationController controller = null; IMenu menu = null; Console.WriteLine("============= GIAO DICH ============="); Console.WriteLine("1. Ngan hang SHB"); Console.WriteLine("2. Block Chain"); Console.WriteLine("0. Thoat"); Console.WriteLine("Vui long nhap lua chon cua ban: "); var choice = Int32.Parse(Console.ReadLine()); switch (choice) { case 1: controller = new SHBController(); menu = new SHBMenu(); break; case 2: controller = new BlockChainController(); menu = new BlockChainMenu(); break; case 0: Environment.Exit(1); break; default: Console.WriteLine("Lua co sai vui long chon lai!"); break; } // check neu menu ko null thi chay tiep. ALT + ENTER may no tu sinh code chu e ko code :D menu?.Menu(controller); } }
public async Task <IActionResult> GetDataFromBlocks(string uniqueKey) { GenericResponse <List <DataModel> > response = new GenericResponse <List <DataModel> >(); var userModel = getPrivateKey(uniqueKey); if (userModel != null) { var account = new Account(userModel.PrimaryKey); var web3 = new Web3(account, "https://ropsten.infura.io/v3/1e1358ffb3db40f69b7bdb6c51d016b6"); BlockChainController blockChainController = new BlockChainController(web3, account); var listofData = await blockChainController.GetContractData(uniqueKey); if (listofData != null) { response.HasError = false; response.Messege = "Sucessfull"; response.Result = listofData; response.StatusCode = 200; } else { response.HasError = true; response.Messege = "UnSucessfull"; response.Result = null; response.StatusCode = 400; } } else { response.HasError = true; response.Messege = "user does not exist"; response.Result = null; response.StatusCode = 400; } return(Ok(response)); }
public async Task <IActionResult> CreateWallet(string uniqueKey) { GenericResponse <Account> response = new GenericResponse <Account>(); Credentials model = new Credentials(); BlockChainController chainController = new BlockChainController(); try { var account = await chainController .CreateWallet(uniqueKey); model.UniqueKey = CustomHashing.ComputeSha256Hash(uniqueKey); model.PrimaryKey = CustomEncryption.Encrypt(account.PrivateKey, uniqueKey); _context.Credentials.Add(model); await _context.SaveChangesAsync(); if (account != null) { response.HasError = false; response.Messege = "Sucessfull"; response.Result = account; response.StatusCode = 200; } } catch (Exception e) { response.HasError = true; response.Messege = "unsucessfull"; response.Result = null; response.StatusCode = 400; } return(Ok(response)); }