private static object ApplicationMethods(string operation, object[] args)
        {
            Called(operation);
            string prefix = operation.Substring(0, 3);

            if (prefix.Equals("PRO"))
            {
                return(PRO.ApplicationMethods(operation, args));
            }
            if (prefix.Equals("TOK"))
            {
                return(TOK.ApplicationMethods(operation, args));
            }
            if (prefix.Equals("UAV"))
            {
                return(UAV.ApplicationMethods(operation, args));
            }
            if (prefix.Equals("NEP"))
            {
                return(NEP.ApplicationMethods(operation, args));
            }
            if (prefix.Equals("COM"))
            {
                return(ModuleCommission.ApplicationMethods(operation, args));
            }
            return(ModuleMisc.ApplicationMethods(operation, args));
        }
Esempio n. 2
0
        /// <summary>
        /// Process monthly scheduled payment
        /// </summary>
        /// <param name="currentDateTime"></param>
        /// <param name="scheduleDateTime"></param>
        /// <returns></returns>
        private static uint[] ProcessMPayment(long currentDateTime, long scheduleDateTime)
        {
            uint[] paymentInfo = new uint[3];
            uint   count = 0; uint isWithraw = 0;
            uint   timeRelay = GetTimeRelay(3);

            while (scheduleDateTime <= currentDateTime)
            {
                count = count + 1;
                long afterSchedule = UAV.AddMonths(scheduleDateTime, 1); //get the next time of possible pays
                                                                         // |-------scheduleTime---------xrelay-------------afterSchedule-------|
                if (currentDateTime <= scheduleDateTime + timeRelay)
                {
                    isWithraw = 1;
                }
                scheduleDateTime = afterSchedule;
            }

            paymentInfo[2] = isWithraw;
            paymentInfo[1] = count;
            paymentInfo[0] = (uint)(scheduleDateTime - currentDateTime);

            return(paymentInfo);
        }
Esempio n. 3
0
        private static bool DoSchedulePayment(byte[] from, byte[] to, BigInteger value, byte[] txid, StorageMap agreement, bool isToHandleMaxFund)
        //long scheduleTime, BigInteger scheduleTypeFromStorage)
        {
            //Evaluate time
            long currentTime  = UAV.GetCurrentTime();
            uint scheduleType = (uint)agreement.Get("schedule").AsBigInteger();
            long scheduleTime = (long)agreement.Get("nextTime").AsBigInteger();


            if (currentTime < scheduleTime)
            {
                Error("Pull schedule payment: not in time yet");
                return(false);
            }
            uint[] paymentInfo = new uint[3];
            //get payment possibilities
            // 0 - nexTime
            // 1 - count
            // 2 - iswithdraw
            if (scheduleType < 3)
            {
                paymentInfo = ProcessDWPayment(scheduleType, currentTime, scheduleTime);
            }
            else
            {
                paymentInfo = ProcessMPayment(currentTime, scheduleTime);
            }

            //update
            uint duration = (uint)agreement.Get("duration").AsBigInteger();

            duration = duration - paymentInfo[1];

            if (duration < 0)
            {
                Error("Contract is no longer valid");
                DeleteAgreement(agreement, txid);
                return(false);
            }
            else if (duration == 0)
            {
                DeleteAgreement(agreement, txid);
            }
            else
            {
                agreement.Put("duration", duration);
                agreement.Put("nextTime", scheduleTime + paymentInfo[0]);
            }

            //---if over maxfund
            if (isToHandleMaxFund)
            {
                string     maxfundId  = Helper.Concat(txid, Helper.AsByteArray(duration)).AsString();
                StorageMap maxFundMap = Storage.CurrentContext.CreateMap(maxfundId);
                maxFundMap.Put("value", value);
                maxFundMap.Put("from", from);
                maxFundMap.Put("to", to);
                //Throw event
                MaxFund(maxfundId, value, from, to);
                return(false);
            }
            //-----End of handle max fund

            if (paymentInfo[2] == 1 && duration >= 0) //case of withdrwal
            {
                return(NEP.Transfer(from, to, value, (uint)ModuleCommission.getCommission("scheduleP")));
            }

            //if withdrawal
            Error("Pull scheduled payment: not duly");
            return(false);
        }