public async Task <string> ApproveContractAsRegulatorAsync(string ContractAddress) { //approve the contract (regulator do it) DappAccount account = RegulatorController._regulator; await DappAccountController.RefreshAccountData(account.publicKey); SmartContractService deployedContract = new SmartContractService(account, ContractAddress); Asset assetDetials = await deployedContract.getAssetDestails(); double DealPriceEth = assetDetials.Price; double taxToGet = DealPriceEth * 0.17; double beforeBalanceETH = await DappAccountController.get_ETH_Balance(account.publicKey, account.publicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(account.publicKey, account.publicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double feeETH; double feeILS; var isApproved = await deployedContract.approveAndExcecute(0.17); if (isApproved == true) { afterBalanceETH = await DappAccountController.get_ETH_Balance(account.publicKey, account.publicKey); feeETH = afterBalanceETH - beforeBalanceETH - taxToGet; feeILS = feeETH * exchangeRate; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot await UpdateContractToApprovedInDB(ContractAddress); await SwitchOwnership(ContractAddress); } else { throw new Exception("Out of money"); } RegulatorConfirmationRecipt recipt = new RegulatorConfirmationRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; recipt.feeILS = feeILS; var ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); return(ReciptJson); }
public async Task <string> CancelContractAsRegulator(string ContractAddress, string DenyNotes) { //cancel the contract and return the money to the buyer DappAccount account = RegulatorController._regulator; await DappAccountController.RefreshAccountData(account.publicKey); SmartContractService deployedContract = new SmartContractService(account, ContractAddress); double beforeBalanceETH = await DappAccountController.get_ETH_Balance(account.publicKey, account.publicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(account.publicKey, account.publicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double feeETH; double feeILS; var ReciptJson = ""; var isCanceled = await deployedContract.cancelDeal(); if (isCanceled == true) { afterBalanceETH = await DappAccountController.get_ETH_Balance(account.publicKey, account.publicKey); feeETH = beforeBalanceETH - afterBalanceETH; feeILS = feeETH * exchangeRate; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot RegulatorConfirmationRecipt recipt = new RegulatorConfirmationRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; recipt.feeILS = feeILS; ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); UpdateContractToDeniedAsRegulatorInDB(ContractAddress, DenyNotes); return(ReciptJson); } else { throw new Exception("No money the sign the transaction"); } }