Beispiel #1
0
        public static UserPoint Bury(string key)
        {
            if (key.Length == 0)
            {
                return(Null());
            }

            Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext;
            string _skeyTag = key + _classKeyTag;

            UserPoint e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(skey).UserPoint.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserPoint.Missing();
            }
            else // not MISSING - bury it
            {
                e = UserPoint.Tombstone(); // but don't overwrite existing field values - just tombstone it
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sSTA, e._state.AsBigInteger());

                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sX, e._x); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sY, e._y); // Template: NPCLevel3CBury_cs.txt
            } // Template: NPCLevel3Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(skey).UserPoint", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
Beispiel #2
0
        /// <summary>
        /// Get an element of an array of entities from Storage based on a NeoStorageKey (NPC Level 4)
        /// </summary>
        /// <param name="vau">vau</param>
        /// <param name="index">index</param>
        /// <returns>UserPoint</returns>
        public static UserPoint GetElement(NeoVersionedAppUser vau, byte[] domain, byte[] bindex)
        {
            if (NeoVersionedAppUser.IsNull(vau))
            {
                return(Null());
            }

            Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext;
            NeoStorageKey nsk = NeoStorageKey.New(vau, domain, _bClassName);

            UserPoint e;

            //byte[] bkey;
            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Get(bkey).UserPoint.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserPoint.Missing();
            }
            else // not MISSING
            {
                int ista = (int)bsta.AsBigInteger();
                NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista;
                if (sta == NeoEntityModel.EntityState.TOMBSTONED)
                {
                    e = UserPoint.Tombstone();
                }
                else // not MISSING && not TOMBSTONED
                {
                    e = new UserPoint();
                    BigInteger X = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bX)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt

                    BigInteger Y = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bY)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt

                    e._x     = X; e._y = Y;                                                                                                              // NPCLevel4DBuryElement_cs.txt
                    e._state = sta;
                    e._state = NeoEntityModel.EntityState.GETTED;                                                                                        /* OVERRIDE */
                }
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).UserPoint.e", e);
            }
            return(e);
        }
Beispiel #3
0
        public static UserPoint Get(string key)
        {
            if (key.Length == 0)
            {
                return(Null());
            }

            Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext;
            string _skeyTag = key + _classKeyTag;

            UserPoint e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Get(skey).UserPoint.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserPoint.Missing();
            }
            else // not MISSING
            {
                int ista = (int)bsta.AsBigInteger();
                NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista;
                e = new UserPoint();

                BigInteger X = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sX).AsBigInteger(); //NPCLevel2IGet_cs.txt
                BigInteger Y = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sY).AsBigInteger(); //NPCLevel2IGet_cs.txt
                if (NeoTrace.RUNTIME)
                {
                    TraceRuntime("Get(skey).e._x, e._y", e._x, e._y);                   // Template: NPCLevel2Part2_cs.txt
                }
                e._x     = X; e._y = Y;
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(skey).UserPoint", e);
            }
            return(e);
        }
Beispiel #4
0
        public static UserPoint Get(byte[] key)
        {
            if (key.Length == 0)
            {
                return(Null());
            }

            Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext;
            byte[] _bkeyTag = Helper.Concat(key, _bclassKeyTag);

            UserPoint e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Get(bkey).bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserPoint.Missing();
            }
            else // not MISSING
            {
                int ista = (int)bsta.AsBigInteger();
                NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista;
                e = new UserPoint();

                BigInteger X = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bX)).AsBigInteger(); //NPCLevel2GGet_cs.txt
                BigInteger Y = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bY)).AsBigInteger(); //NPCLevel2GGet_cs.txt
                e._x     = X; e._y = Y;                                                                                                // Template: NPCLevel2HGet_cs.txt
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED;                                                                          /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).UserPoint", e);
            }
            return(e);
        }
Beispiel #5
0
        /// <summary>
        /// Bury an element of an array of entities in Storage based on a NeoStorageKey (NPC Level 4)
        /// </summary>
        /// <param name="vau">vau</param>
        /// <param name="index">index</param>
        /// <returns>UserPoint</returns>
        public static UserPoint BuryElement(NeoVersionedAppUser vau, byte[] domain, byte[] bindex)
        {
            if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY?
            {
                return(UserPoint.Null());
            }

            Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext;
            NeoStorageKey nsk = NeoStorageKey.New(vau, domain, _bClassName);

            //byte[] bkey;
            UserPoint e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(vau,index).UserPoint.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserPoint.Missing();
            }
            else // not MISSING - bury it
            {
                e = UserPoint.Tombstone(); // TODO - should Bury() preserve the exist field values or re-initialize them? Preserve is cheaper but not as private
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA), e._state.AsBigInteger());

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bX), e._x); // NPCLevel4EBuryElement_cs.txt

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bY), e._y); // NPCLevel4EBuryElement_cs.txt
            } // Template: NPCLevel4Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(vau,i).UserPoint", e);
            }
            return(e);
        }