public PensionFundContract CheckContractCreationTransaction(String transactionHash) { var pensionFundContract = Data.GetPensionFundContract(transactionHash); if (pensionFundContract == null) { throw new ArgumentException("Invalid transaction hash."); } Transaction demoContractTransaction = EthereumManager.GetTransaction(transactionHash); if (demoContractTransaction == null) { if (pensionFundContract.CreationDate < DateTime.UtcNow.AddMinutes(PensionFundTransactionBusiness.BLOCKCHAIN_TRANSACTION_TOLERANCE)) { PoolInfo poolInfo = GetPoolInfo(); if (!poolInfo.Pending.Contains(pensionFundContract.TransactionHash)) { Logger.LogError(string.Format("Transaction for creation contract {0} is lost.", pensionFundContract.TransactionHash)); List <PensionFundReferenceContract> referenceDistribution = PensionFundReferenceContractBusiness.List(pensionFundContract.TransactionHash); if (!referenceDistribution.Any()) { throw new Exception("Reference contract cannot be found."); } PensionFund pensionFund = PensionFundBusiness.GetByTransaction(pensionFundContract.TransactionHash); if (pensionFund == null) { throw new Exception("Pension fund cannot be found."); } pensionFund.Option.Company.BonusDistribution = BonusDistributionBusiness.List(pensionFund.Option.Company.Address); if (!pensionFund.Option.Company.BonusDistribution.Any()) { throw new ArgumentException("Bonus distribution cannot be found."); } PensionFundReferenceContractBusiness.Delete(pensionFundContract.TransactionHash); Delete(pensionFundContract); pensionFundContract = Create(pensionFund.Option.Address, pensionFund.Option.Company.Address, pensionFund.Option.Company.Employee.Address, pensionFund.Option.Fee, pensionFund.Option.LatePenalty, pensionFund.Option.Company.MaxSalaryBonusRate, pensionFund.Option.Company.Employee.Contribution, pensionFund.Option.Company.BonusRate, pensionFund.Option.Company.Employee.Salary, referenceDistribution.ToDictionary(c => c.ReferenceContractAddress, c => c.Percentage), pensionFund.Option.Company.BonusDistribution.ToDictionary(c => c.Period, c => c.ReleasedBonus)); foreach (PensionFundReferenceContract reference in referenceDistribution) { PensionFundReferenceContractBusiness.Create(pensionFundContract.TransactionHash, reference.ReferenceContractAddress, reference.Percentage); } } } return(pensionFundContract); } else { pensionFundContract = UpdateAfterMined(pensionFundContract, demoContractTransaction); } return(pensionFundContract); }
private PensionFund GetFromDatabase(string pensionFundContractAddress) { PensionFund pensionFund = Data.GetByContract(pensionFundContractAddress); if (pensionFund == null || pensionFund.Option.Company == null || pensionFund.Option.Company.Employee == null) { throw new ArgumentException("Pension fund cannot be found."); } pensionFund.Option.PensionFundContract.PensionFundReferenceContract = PensionFundReferenceContractBusiness.List(pensionFund.Option.PensionFundContract.TransactionHash); if (!pensionFund.Option.PensionFundContract.PensionFundReferenceContract.Any()) { throw new ArgumentException("Reference contract cannot be found."); } pensionFund.Option.Company.BonusDistribution = BonusDistributionBusiness.List(pensionFund.Option.Company.Address); if (!pensionFund.Option.Company.BonusDistribution.Any()) { throw new ArgumentException("Bonus distribution cannot be found."); } return(pensionFund); }