示例#1
0
        /// <summary>
        /// Handle decision from buyer to withdrawl value > max
        /// </summary>
        /// <param name="decision"></param>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static bool solveMaxFund(bool decision, string id, BigInteger value)
        {
            StorageMap maxfund = Storage.CurrentContext.CreateMap(id);
            //Check value
            BigInteger storedValue = maxfund.Get("value").AsBigInteger();

            if (value <= 0 || storedValue != value)
            {
                Error("No record found or value not matched");
                return(false);
            }
            byte[] buyer = maxfund.Get("from");
            //validate buyer
            if (!Runtime.CheckWitness(buyer))
            {
                Error("Authorization failed");
                return(false);
            }
            byte[] merchant = maxfund.Get("to");


            //Delete the case which has maxfund
            // and do transfer or reject it
            maxfund.Delete("value");
            maxfund.Delete("from");
            maxfund.Delete("to");
            DeleteMaxFund(id);
            if (decision) //grant the request
            {
                return(NEP.Transfer(buyer, merchant, value, (uint)ModuleCommission.getCommission("scheduleP")));
            }

            RejectMaxFund(id);
            return(false);
        }
        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));
        }
示例#3
0
 /***********************************************
  * Event event definition
  * ***************************************/
 /// <summary>
 /// This function is to directly transfer tokens from one user (from) to another user (to)
 /// if the calling is not from "from", throw error events "Authorization failed"
 /// success processing will create event "transferred"
 ///
 /// </summary>
 /// <param name="from"></param>  address of paying user, hash 160
 /// <param name="to"></param> address of benefit, hash 160, different from "to"
 /// <param name="amount"></param> number of tokens to be transferred, > 0 is required
 /// <returns></returns>
 private static bool InstantPay(byte[] from, byte[] to, BigInteger amount)
 {
     if (!Runtime.CheckWitness(from) || !Utils.ValidateNEOAddress(to))
     {
         Error("Authorization failed");
         return(false);
     }
     return(NEP.Transfer(from, to, amount, (uint)ModuleCommission.getCommission("directP")));
 }
示例#4
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);
        }
示例#5
0
        //PullPayment payment - except schedule
        /// <summary>
        /// To pull avaiable tokens from admin account to benefit account (to)
        /// -if the calling is not from "to", throw error events "Authorization failed"
        /// -if successfully process, there is a "update_holding" event to be created,
        /// if there is balance to be withdrawn, "transferred" event when be fired - otherwise, there will be error event
        /// </summary>
        /// <param name="to"></param> address of benefit, hash 160, different from "to"
        /// <param name="value"></param>  number of tokens to be handled, >0 is required
        /// <returns></returns>
        private static bool PullPayment(byte[] to, BigInteger value)
        {
            if (!Runtime.CheckWitness(to))
            {
                Error("Authorization failed");
                return(false);
            }
            UpdateHoldings(to, 0);
            bool success = NEP.Transfer(TOK.Owner, to, Storage.Get(Storage.CurrentContext, to + "_holding").AsBigInteger(), (uint)ModuleCommission.getCommission("singleP"));

            if (success)
            {
                Storage.Put(Storage.CurrentContext, to + "_holding", 0); //return value
                return(true);
            }
            return(false);
        }