Пример #1
0
        private async Task <List <ContractOffer> > GetPendingContracts()
        { //get all the open contracts (pending) that waits for the regulaotr approval
            DappAccount account = RegulatorController._regulator;
            await DappAccountController.RefreshAccountData(account.publicKey);

            List <AssetInContract> deployedContractsFromDB = new List <AssetInContract>();

            deployedContractsFromDB = await _AssetInContractsContext.AssetsInContract.FromSqlRaw("select * from AssetsInContract where Status= 'Pending'").ToListAsync();

            List <ContractOffer> deployedContractsFromBlockchain = new List <ContractOffer>();

            foreach (AssetInContract assCon in deployedContractsFromDB)
            {
                ContractOffer offer           = new ContractOffer();
                string        contractAddress = assCon.ContractAddress;
                offer.ContractAddress = contractAddress;
                SmartContractService deployedContract = new SmartContractService(account, contractAddress);
                Asset assetInContract = await deployedContract.getAssetDestails(); //read from blockchain

                offer.AssetID        = assetInContract.AssetID;
                offer.Loaction       = assetInContract.Loaction;
                offer.Rooms          = assetInContract.Rooms;
                offer.AreaIn         = assetInContract.AreaIn;
                offer.ImageURL       = assetInContract.ImageURL;
                offer.PriceETH       = assetInContract.Price;
                offer.PriceILS       = offer.PriceETH * account.exchangeRateETH_ILS;
                offer.PriceILS       = Math.Truncate(offer.PriceILS * 1000) / 1000;
                offer.BuyerPublicKey = await deployedContract.getBuyerAddress();

                offer.SellerPublicKey = await deployedContract.getOldAssetOwner();

                offer.SellerSign = await deployedContract.getSellerSign();

                offer.BuyerSign = await deployedContract.getBuyerSign();

                offer.RegulatorSign = await deployedContract.getRegulatorSign();

                offer.Tax = await deployedContract.getTax();

                offer.BuyerID = await GetAddressID(offer.BuyerPublicKey);

                offer.OwnerID = await GetAddressID(offer.SellerPublicKey);

                offer.NewOwnerPublicKey = await deployedContract.getNewAssetOwner();

                offer.NewOwnerID = await GetAddressID(offer.NewOwnerPublicKey);

                offer.EtherscanURL = "https://ropsten.etherscan.io/address/" + assCon.ContractAddress;
                deployedContractsFromBlockchain.Add(offer);
            }
            return(deployedContractsFromBlockchain);
        }
Пример #2
0
        public async Task <IActionResult> ShowHomePage()
        {   //read all closed contracts and show it in page
            DappAccount            account = _regulator;
            List <AssetInContract> deployedContractsFromDB = new List <AssetInContract>();

            deployedContractsFromDB = await _AssetInContractsContext.AssetsInContract.FromSqlRaw("select * from AssetsInContract where Status= 'Approved' or (Status= 'Denied' and DeniedBy = 'Regulator') ").ToListAsync();

            List <ContractOffer> deployedContractsFromBlockchain = new List <ContractOffer>();

            foreach (AssetInContract assCon in deployedContractsFromDB)
            {
                ContractOffer offer           = new ContractOffer();
                string        contractAddress = assCon.ContractAddress;
                offer.ContractAddress = contractAddress;
                if (!assCon.Status.Equals("Denied"))  //For the non-destroyed contracts, "Denied" => Self Destruction
                {
                    SmartContractService deployedContract = new SmartContractService(account, contractAddress);
                    Asset assetInContract = await deployedContract.getAssetDestails(); //read from blockchain

                    offer.AssetID        = assetInContract.AssetID;
                    offer.Loaction       = assetInContract.Loaction;
                    offer.Rooms          = assetInContract.Rooms;
                    offer.AreaIn         = assetInContract.AreaIn;
                    offer.ImageURL       = assetInContract.ImageURL;
                    offer.PriceETH       = assetInContract.Price;
                    offer.PriceILS       = offer.PriceETH * account.exchangeRateETH_ILS;
                    offer.PriceILS       = Math.Truncate(offer.PriceILS * 1000) / 1000;
                    offer.BuyerPublicKey = await deployedContract.getBuyerAddress();

                    offer.SellerPublicKey = await deployedContract.getOldAssetOwner();

                    offer.SellerSign = await deployedContract.getSellerSign();

                    offer.BuyerSign = await deployedContract.getBuyerSign();

                    offer.RegulatorSign = await deployedContract.getRegulatorSign();

                    offer.Tax = await deployedContract.getTax();

                    offer.BuyerID = await GetAddressID(offer.BuyerPublicKey);

                    offer.OwnerID = await GetAddressID(offer.SellerPublicKey);

                    offer.NewOwnerPublicKey = await deployedContract.getNewAssetOwner();

                    offer.NewOwnerID = await GetAddressID(offer.NewOwnerPublicKey);
                }

                else
                {
                    offer.SellerPublicKey     = assCon.SellerPublicKey;
                    offer.BuyerPublicKey      = assCon.BuyerPublicKey;
                    offer.PriceETH            = assCon.DealPrice;
                    offer.PriceILS            = offer.PriceETH * account.exchangeRateETH_ILS;
                    offer.BuyerSign           = true;
                    offer.RegulatorSign       = false;
                    offer.IsDeniedByBuyer     = false;
                    offer.IsDeniedByRegulator = true;
                    offer.SellerSign          = true;
                    offer.DenyReason          = assCon.Reason;
                    offer.AssetID             = assCon.AssetID;
                    List <Asset> AssetsInDB = new List <Asset>();
                    AssetsInDB = await _AssetsContext.Assets.FromSqlRaw("select * from Assets where AssetID = {0}", offer.AssetID).ToListAsync();

                    offer.Loaction = AssetsInDB[0].Loaction;
                    offer.OwnerID  = await GetAddressID(offer.SellerPublicKey);

                    offer.BuyerID = await GetAddressID(offer.BuyerPublicKey);

                    offer.AreaIn     = AssetsInDB[0].AreaIn;
                    offer.Rooms      = AssetsInDB[0].Rooms;
                    offer.ImageURL   = AssetsInDB[0].ImageURL;
                    offer.DenyReason = assCon.Reason;
                }

                offer.EtherscanURL = "https://ropsten.etherscan.io/address/" + assCon.ContractAddress;
                deployedContractsFromBlockchain.Add(offer);
            }


            account.DeployedContractList = deployedContractsFromBlockchain;
            return(View("RegulatorMainPage", _regulator));
        }
Пример #3
0
        public async Task <IActionResult> ContractsStatusPage(string PublicKey) //now
        {                                                                       //load the page of the open/closed contracts, we read all the related open contracts and sort them
            await DappAccountController.RefreshAccountData(PublicKey);

            DappAccount            account = DappAccountController.openWith[PublicKey.ToLower()];
            List <AssetInContract> deployedContractsFromDB = new List <AssetInContract>();

            deployedContractsFromDB = await _AssetInContractsContext.AssetsInContract.FromSqlRaw("select * from AssetsInContract where ( SellerPublicKey = {0} or BuyerPublicKey = {0} )", account.publicKey).ToListAsync();

            List <ContractOffer> deployedContractsFromBlockchain = new List <ContractOffer>();

            foreach (AssetInContract assCon in deployedContractsFromDB)
            {
                ContractOffer offer           = new ContractOffer();
                string        contractAddress = assCon.ContractAddress;
                offer.ContractAddress = contractAddress;
                if (!assCon.Status.Equals("Denied"))  //For the non-destroyed contracts, "Denied" => Self Destruction
                {
                    SmartContractService deployedContract = new SmartContractService(account, contractAddress);
                    Asset assetInContract = await deployedContract.getAssetDestails(); //read from blockchain

                    offer.AssetID        = assetInContract.AssetID;
                    offer.Loaction       = assetInContract.Loaction;
                    offer.Rooms          = assetInContract.Rooms;
                    offer.AreaIn         = assetInContract.AreaIn;
                    offer.ImageURL       = assetInContract.ImageURL;
                    offer.PriceETH       = assetInContract.Price;
                    offer.PriceILS       = offer.PriceETH * account.exchangeRateETH_ILS;
                    offer.PriceILS       = Math.Truncate(offer.PriceILS * 1000) / 1000;
                    offer.BuyerPublicKey = await deployedContract.getBuyerAddress();

                    offer.SellerPublicKey = await deployedContract.getOldAssetOwner();

                    offer.SellerSign = await deployedContract.getSellerSign();

                    offer.BuyerSign = await deployedContract.getBuyerSign();

                    offer.RegulatorSign = await deployedContract.getRegulatorSign();

                    offer.Tax = await deployedContract.getTax();

                    offer.BuyerID = await GetAddressID(offer.BuyerPublicKey);

                    offer.OwnerID = await GetAddressID(offer.SellerPublicKey);

                    if (assCon.Status.Equals("Approved"))
                    {
                        offer.NewOwnerPublicKey = await deployedContract.getNewAssetOwner();

                        offer.NewOwnerID = await GetAddressID(offer.NewOwnerPublicKey);
                    }

                    if (assCon.Status.Equals("Ongoing"))
                    {
                        ulong time = await deployedContract.getTimeLeftInSeconds();

                        int timeLeft = (int)time;
                        if (timeLeft > 21)
                        {
                            timeLeft = timeLeft - 20;
                        }
                        offer.TimeToBeOpen = timeLeft;
                    }
                }

                else
                {
                    offer.SellerPublicKey = assCon.SellerPublicKey;
                    offer.BuyerPublicKey  = assCon.BuyerPublicKey;
                    offer.PriceETH        = assCon.DealPrice;
                    offer.PriceILS        = offer.PriceETH * account.exchangeRateETH_ILS;
                    if (assCon.DeniedBy.Equals("Buyer"))
                    {
                        offer.BuyerSign           = false;
                        offer.RegulatorSign       = false;
                        offer.IsDeniedByBuyer     = true;
                        offer.IsDeniedByRegulator = false;
                    }

                    else if (assCon.DeniedBy.Equals("Regulator"))
                    {
                        offer.BuyerSign           = true;
                        offer.RegulatorSign       = false;
                        offer.IsDeniedByBuyer     = false;
                        offer.IsDeniedByRegulator = true;
                    }

                    offer.SellerSign = true;
                    offer.DenyReason = assCon.Reason;
                    offer.AssetID    = assCon.AssetID;
                    List <Asset> AssetsInDB = new List <Asset>();
                    AssetsInDB = await _AssetsContext.Assets.FromSqlRaw("select * from Assets where AssetID = {0}", offer.AssetID).ToListAsync();

                    offer.Loaction = AssetsInDB[0].Loaction;
                    offer.OwnerID  = await GetAddressID(offer.SellerPublicKey);

                    offer.BuyerID = await GetAddressID(offer.BuyerPublicKey);

                    offer.AreaIn     = AssetsInDB[0].AreaIn;
                    offer.Rooms      = AssetsInDB[0].Rooms;
                    offer.ImageURL   = AssetsInDB[0].ImageURL;
                    offer.DenyReason = assCon.Reason;
                }

                offer.EtherscanURL = "https://ropsten.etherscan.io/address/" + assCon.ContractAddress;
                deployedContractsFromBlockchain.Add(offer);
            }


            account.DeployedContractList = deployedContractsFromBlockchain;
            return(View(account));
        }