Beispiel #1
0
        public Withdrawal ReadWithdrawal(string contractAddress)
        {
            string     cacheKey         = string.Format("Withdrawal{0}", contractAddress);
            Withdrawal cachedWithdrawal = MemoryCache.Get <Withdrawal>(cacheKey);

            if (cachedWithdrawal != null)
            {
                return(cachedWithdrawal);
            }

            PensionFund            pensionFund   = PensionFundBusiness.GetByContract(contractAddress);
            SmartContract          smartContract = SmartContractBusiness.GetDefaultDemonstrationPensionFund();
            PensionFundTransaction transaction   = Data.List(pensionFund.Option.PensionFundContract.TransactionHash).Where(c => c.FunctionType == FunctionType.CompleteWithdrawal).SingleOrDefault();

            if (transaction == null)
            {
                return(null);
            }

            WithdrawalInfo withdrawalInfo = EthereumManager.ReadWithdrawalFromDefaultPensionFund(contractAddress);

            PensionFundTransaction[] pendingCreate   = string.IsNullOrEmpty(transaction.TransactionHash) ? new PensionFundTransaction[] { transaction } : new PensionFundTransaction[0];
            PensionFundTransaction[] pendingComplete = pendingCreate.Length == 0 && !transaction.BlockNumber.HasValue ? new PensionFundTransaction[] { transaction } : new PensionFundTransaction[0];
            BaseEventInfo[]          withdrawEvent   = withdrawalInfo != null ? new BaseEventInfo[] { withdrawalInfo } : new BaseEventInfo[0];

            HandleTransactions(smartContract, pensionFund, new PensionFundTransaction[] { }, pendingCreate, pendingComplete, withdrawEvent);

            Withdrawal withdrawal = null;

            if (withdrawalInfo != null)
            {
                withdrawal = new Withdrawal()
                {
                    TransactionHash       = transaction.TransactionHash,
                    CreatedDate           = transaction.CreationDate,
                    Responsable           = transaction.WalletAddress,
                    BlockNumber           = withdrawalInfo.BlockNumber,
                    Period                = withdrawalInfo.Period,
                    EmployeeAbsoluteBonus = withdrawalInfo.EmployeeAbsoluteBonus,
                    EmployeeBonus         = withdrawalInfo.EmployeeBonus,
                    EmployeeSzaboCashback = withdrawalInfo.EmployeeSzaboCashback,
                    EmployeeTokenCashback = withdrawalInfo.EmployeeTokenCashback,
                    EmployerSzaboCashback = withdrawalInfo.EmployerSzaboCashback,
                    EmployerTokenCashback = withdrawalInfo.EmployerTokenCashback,
                    ReferenceDate         = pensionFund.Option.PensionFundContract.CreationDate.AddMonths(withdrawalInfo.Period).Date
                };
                MemoryCache.Set <Withdrawal>(cacheKey, withdrawal);
            }
            else
            {
                withdrawal = new Withdrawal()
                {
                    TransactionHash = transaction.TransactionHash,
                    CreatedDate     = transaction.CreationDate,
                    Responsable     = transaction.WalletAddress
                };
            }
            return(withdrawal);
        }
Beispiel #2
0
        public Withdrawal GetWithdrawalInfo(string pensionFundContractAddress)
        {
            PensionFund    pensionFund    = GetByContract(pensionFundContractAddress);
            SmartContract  smartContract  = SmartContractBusiness.GetDefaultDemonstrationPensionFund();
            WithdrawalInfo withdrawalInfo = EthereumManager.GetWithdrawalInfo(pensionFund.Option.Company.Employee.Address, pensionFundContractAddress, smartContract.ABI);

            return(new Withdrawal()
            {
                EmployeeAbsoluteBonus = withdrawalInfo.EmployeeAbsoluteBonus,
                EmployeeBonus = withdrawalInfo.EmployeeBonus,
                EmployeeSzaboCashback = withdrawalInfo.EmployeeSzaboCashback,
                EmployeeTokenCashback = withdrawalInfo.EmployeeTokenCashback,
                EmployerSzaboCashback = withdrawalInfo.EmployerSzaboCashback,
                EmployerTokenCashback = withdrawalInfo.EmployerTokenCashback
            });
        }