private async void btnConfirm_ClickedAsync(object sender, EventArgs eventArgs) { var name = inputName.Text; var department = inputDepartment.Text ?? string.Empty; var telephone = inputTelephone.Text ?? string.Empty; var email = inputEmail.Text ?? string.Empty; var passphrase = inputPassPhrase.Text; Console.WriteLine($"Name: {name}, Department: {department}, Telephone: {telephone}, Email: {email}, Passphrase: {passphrase}"); if (name.IsNullOrEmpty() || passphrase.IsNullOrEmpty()) { Console.WriteLine($"Invalid input. Aborting."); return; } var web3 = new Web3(Settings.Current.ServerIpAddress); string wallet; try { // creating the new account wallet = await web3.Personal.NewAccount.SendRequestAsync(passphrase); Console.WriteLine($"The new wallet has the address {wallet}."); } catch (Exception e) { Console.WriteLine($"An unexpected error occured when creating a new account."); Console.WriteLine(e); return; } var coffeeEconomyService = new CoffeeEconomyService(new ManagedAccount(wallet, passphrase), web3, Settings.Current.ContractAddress); try { // create customer for wallet var transactionId = await coffeeEconomyService.AddCustomerAsync(wallet, name, department, telephone, email); Console.WriteLine($"Created customer with transactionId {transactionId}."); } catch (Exception e) { Console.WriteLine($"An unexpected error occured when creating the customer."); Console.WriteLine(e); return; // also if we have an error, this cannot be valid or useful, so we abort } Settings.Current.PublicWalletAddress = wallet; Settings.Current.Passphrase = passphrase; Console.WriteLine($"Successfully set credentials and returning to dashboard."); await Navigation.PopAllPopupAsync(); }
private async void btnConfirm_ClickedAsync(object sender, EventArgs eventArgs) { var wallet = inputWalletAddress.Text; var passphrase = inputPassPhrase.Text; Console.WriteLine($"Wallet: {wallet}, Passphrase: {passphrase}"); if (wallet.IsNullOrEmpty() || !wallet.IsValidEthereumAddress() || passphrase.IsNullOrEmpty()) { Console.WriteLine($"Invalid input. Aborting."); return; } var web3 = new Web3(Settings.Current.ServerIpAddress); var coffeeEconomyService = new CoffeeEconomyService(new ManagedAccount(wallet, passphrase), web3, Settings.Current.ContractAddress); try { // check if wallet is a customer //if (!(await coffeeEconomyService.IsCustomerAsync(wallet))) //{ // System.Console.WriteLine($"Given wallet ({wallet}) is no customer."); // return; // it is no registered customer on our coffee chain //} // check credentials via web3 if (!(await web3.Personal.UnlockAccount.SendRequestAsync(wallet, passphrase, 0))) { Console.WriteLine($"Unlocking account with given credentials failed."); return; // these credentials seem invalid } } catch (Exception e) { Console.WriteLine($"An unexpected error occured."); Console.WriteLine(e); return; // also if we have an error, this cannot be valid or useful, so we abort } Settings.Current.PublicWalletAddress = wallet; Settings.Current.Passphrase = passphrase; Console.WriteLine($"Successfully set credentials and returning to dashboard."); await Navigation.PopAllPopupAsync(); }
static async Task Main(string[] args) { Console.WriteLine("Welcome to the CoffeeChain Wallet Application."); Console.WriteLine("=============================================="); Console.WriteLine("Bootstrapping Nethereum..."); //var password = Console.ReadLine(); var password = PassPhrase; var account = Account.LoadFromKeyStore(KeyFile, password); var web3 = new Nethereum.Web3.Web3(account, "http://192.168.1.166:30304"); var coffeeEconomyService = new CoffeeEconomyService(account, web3, ContractAddress); var console = new ConsoleService(web3, coffeeEconomyService); await console.Handle(); }
public ConsoleService(Web3 web3, CoffeeEconomyService coffeeEconomyService) { _web3 = web3; _coffeeEconomyService = coffeeEconomyService; }