Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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");
        }
Ejemplo n.º 3
0
        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");
        }