public async Task <string> ApproveContract(string ContractAddress, string PublicKey) { //approve the contract seny by the seller (send money and sign the contract) DappAccount account = DappAccountController.openWith[PublicKey.ToLower()]; SmartContractService deployedContract = new SmartContractService(account, ContractAddress); double beforeBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double afterBalanceILS; double feeETH; double feeILS; Asset dealAsset = await deployedContract.getAssetDestails(); double ethToPay = dealAsset.Price; bool isPaid = false; bool isSigned = false; isPaid = await deployedContract.sendEtherToContract(ethToPay); if (isPaid == true) { isSigned = await deployedContract.setBuyerSign(); } else { throw new Exception("Out of money"); } afterBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); afterBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); feeETH = beforeBalanceETH - (afterBalanceETH + ethToPay); feeILS = exchangeRate * feeETH; ConfirmationRecipt recipt = new ConfirmationRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot recipt.feeILS = feeILS; var ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); updateOfferToPending(ContractAddress); return(ReciptJson); }
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> DeployContract(ContractOffer offer) { //deploy (=create) the contract, save it in the blockahin and in the DB table - AssetInContracts double beforeBalanceETH = await DappAccountController.get_ETH_Balance(offer.SellerPublicKey, offer.SellerPublicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(offer.SellerPublicKey, offer.SellerPublicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double afterBalanceILS; double feeETH; double feeILS; try { InsertAssetInContractToDB(offer, "Busy"); var account = DappAccountController.openWith[offer.SellerPublicKey.ToLower()]; var ContractAddress = await SmartContractService.Deploy(account, offer); afterBalanceETH = await DappAccountController.get_ETH_Balance(offer.SellerPublicKey, offer.SellerPublicKey); afterBalanceILS = await DappAccountController.get_ILS_Balance(offer.SellerPublicKey, offer.SellerPublicKey); feeETH = beforeBalanceETH - afterBalanceETH; feeILS = beforeBalanceILS - afterBalanceILS; InsertAssetInContractToDB(offer, ContractAddress); RemoveBusyAssetInContractFromDB(offer); DeploymentRecipt recipt = new DeploymentRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot recipt.feeILS = feeILS; var ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); return(ReciptJson); } catch (Exception e) { RemoveBusyAssetInContractFromDB(offer); return("Error"); } }
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"); } }
public async Task <string> CancelDealAsBuyer(string ContractAddress, string Notes, string PublicKey) { //deny the contract /cancel the contract sent by seller DappAccount account = DappAccountController.openWith[PublicKey]; SmartContractService deployedContract = new SmartContractService(account, ContractAddress); double beforeBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double afterBalanceILS; double feeETH; double feeILS; bool isDenied = false; isDenied = await deployedContract.denyDeal(); if (isDenied == true) { afterBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); afterBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); feeETH = beforeBalanceETH - afterBalanceETH; feeILS = beforeBalanceILS - afterBalanceILS; ConfirmationRecipt recipt = new ConfirmationRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot recipt.feeILS = feeILS; var ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); updateOfferToDenied(ContractAddress, Notes); return(ReciptJson); } return("Fail"); }
public async Task <string> CancelDealAsSeller(string ContractAddress, string PublicKey) { //cancel the contract if the time is over (the buyer didn`t sign in time) DappAccount account = DappAccountController.openWith[PublicKey]; SmartContractService deployedContract = new SmartContractService(account, ContractAddress); double beforeBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); double beforeBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); double exchangeRate = DappAccountController.getExchangeRate_ETH_To_ILS(); double afterBalanceETH; double afterBalanceILS; double feeETH; double feeILS; bool isCanceled = false; isCanceled = await deployedContract.abort(); if (isCanceled == true) { afterBalanceETH = await DappAccountController.get_ETH_Balance(PublicKey, PublicKey); afterBalanceILS = await DappAccountController.get_ILS_Balance(PublicKey, PublicKey); feeETH = beforeBalanceETH - afterBalanceETH; feeILS = beforeBalanceILS - afterBalanceILS; ConfirmationRecipt recipt = new ConfirmationRecipt(); recipt.ContractAddress = ContractAddress; recipt.feeETH = feeETH; feeILS = Math.Truncate(feeILS * 100) / 100; //make the double number to be with 3 digits after dot recipt.feeILS = feeILS; var ReciptJson = Newtonsoft.Json.JsonConvert.SerializeObject(recipt); deleteCanceledOfferBySeller(ContractAddress); return(ReciptJson); } return("Fail"); }