/// <summary> /// @dev responsible for setting up connection to the following /// @var rhodeITDB the RhodesIT Platforms Database /// @var rhodesDataBase represents Rhodes Universities DB /// @var web3 responsible for establishing a connection between RChain (Private Blockchain) and the Mobile App /// @var SmartContractFunctions responsible for allowing access to all smart contract functions /// </summary> public void SetupAsync() { BaseContract = new RhodeITDeployment(); rhodesDataBase = new RhodesDataBase(); Account = new ManagedAccount(Variables.adminAddress, Variables.Passwordd); web3 = new Web3Quorum(Variables.RPCAddressNodeGenesis); web3.TransactionManager.DefaultGas = new System.Numerics.BigInteger(8000000); web3.TransactionManager.DefaultGasPrice = new System.Numerics.BigInteger(20000000000); SmartContractFunctions = new RhodeITService(); }
public void Purchase_Ride_Credits() { RhodeITService rhodeITServices = new RhodeITService(); RhodeITDB db = new RhodeITDB(); IUserDialogs dialog = UserDialogs.Instance; dialog.ShowLoading("Purchasing Ride Credits..."); try { bool result = int.TryParse(amount.Text, out int rideCredit); if (!result) { throw new InvalidNumberException("Invalid"); } try { if (rideCredit <= 0) { throw new InvalidNumberException(""); } else { Details = db.GetUserDetails(); rhodeITServices.UpdateCreditRequestAsync(Details.Ethereum_Address, rideCredit).ConfigureAwait(false); Details.RideCredits += rideCredit; RhodesDataBase.ChargeUserRideCreditBalanceToAccount(Details).ConfigureAwait(false); db.UpdateLoginDetails(Details); dialog.HideLoading(); dialog.Alert(string.Format("Succesfully recharged ride credits with {0}", rideCredit), "Success", "OK"); } } catch (Exception e) { dialog.HideLoading(); PopupLayout.Dismiss(); Console.WriteLine("Error whilst purcasing credits: " + e.Message); dialog.Alert("Something went wrong whilst purchasing credit", "Insufficient Funds", "OK"); } } catch (InvalidNumberException e) { dialog.HideLoading(); PopupLayout.Dismiss(); Console.WriteLine("Error whilst purcasing credits: " + e.Message); dialog.Alert("Please ensure you entered a valid number e.g. 12", "Invalid Number", "OK"); } }