Example #1
0
        public static void log(string message, byte[] argument)
        {
#if SMART_CONTRACT_TEST
            Runtime.Notify(Helper.Concat(message.AsByteArray(), argument));
            Runtime.Notify(argument);
#endif
        }
        /*
         * 2 bytes data read for ushort
         */
        public static BigInteger GetBigInteger(byte[] data)
        {
            byte[] zero = new byte[] { 0x00 };
            byte[] temp = Helper.Concat(data, zero);

            BigInteger val = Helper.AsBigInteger(temp);

            return(val);
        }
        /*
         * Generic structure for array size. Each array structure begins with the leading size structure.
         * Size can be a octet, byte, uint or ulong, total size of this structure depends on the type of
         * the data, so size becomes 1, 3, 5, 9 byte(s) respectively.
         */

        public static VarSizeStr readVarSize(byte[] data, int idx)
        {
            byte[]     temp  = Helper.Range(data, idx, 1);
            byte[]     temp2 = new byte[] { 0x00 };
            byte[]     temp3 = Helper.Concat(temp, temp2);
            BigInteger temp4 = Helper.AsBigInteger(temp3);
            int        ind   = (int)temp4;

            byte[] val  = new byte[1];
            int    size = 0;

            if (ind == 0xfd)
            {
                // read next 2 bytes total 3 (ushort length string)
                size = 2;
                val  = new byte[3];
            }

            if (ind == 0xfe)
            {
                // read next 4 bytes total 5 (uint length string)
                size = 4;
                val  = new byte[5];
            }

            if (ind == 0xff)
            {
                // read next 8 bytes total 9 (ulong length string)
                size = 8;
                val  = new byte[9];
            }

            if (size > 0)
            {
                val = Helper.Range(data, idx + 1, size);

                val = Helper.Concat(val, temp2);
            }

            VarSizeStr res = new VarSizeStr();

            if (size == 0)
            {
                res.value = ind;
            }

            if (size > 0)
            {
                res.value = (int)Helper.AsBigInteger(val);
            }

            res.size = size + 1;

            return(res);
        }
Example #4
0
        public static void log(string condition, bool status)
        {
#if SMART_CONTRACT_TEST
            if (status)
            {
                Runtime.Notify(Helper.Concat(condition.AsByteArray(), "true".AsByteArray()));
            }
            else
            {
                Runtime.Notify(Helper.Concat(condition.AsByteArray(), "false".AsByteArray()));
            }
#endif
        }
Example #5
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);
        }
Example #6
0
 public static byte[] concat(byte[] first, byte[] second)
 {
     return(Helper.Concat(first, second));
 }