示例#1
0
 public static void Set(NFT e, string Uri, string FirstName, string LastName) // Template: NPCLevel1Set_cs.txt
 {
     if (e._state != NeoEntityModel.EntityState.NULL)
     {
         e._uri = Uri; e._firstName = FirstName; e._lastName = LastName;  e._state = NeoEntityModel.EntityState.SET;
     }
 }
示例#2
0
 // Factory methods // Template: NPCLevel1Part2_cs.txt
 private static NFT _Initialize(NFT e)
 {
     e._uri   = ""; e._firstName = ""; e._lastName = "";
     e._state = NeoEntityModel.EntityState.NULL;
     if (NeoTrace.RUNTIME)
     {
         LogExt("_Initialize(e).NFT", e);
     }
     return(e);
 }
示例#3
0
        public static NFT New()
        {
            NFT e = new NFT();

            _Initialize(e);
            if (NeoTrace.RUNTIME)
            {
                LogExt("New().NFT", e);
            }
            return(e);
        }
        public static NFT Tombstone()
        {
            NFT e = new NFT();

            e._uri   = ""; e._firstName = ""; e._lastName = "";
            e._state = NeoEntityModel.EntityState.TOMBSTONED;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Tombstone().NFT", e);
            }
            return(e);
        }
        public static NFT Missing()
        {
            NFT e = new NFT();

            e._uri   = ""; e._firstName = ""; e._lastName = "";
            e._state = NeoEntityModel.EntityState.MISSING;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Missing().NFT", e);
            }
            return(e);
        }
示例#6
0
        public static NFT New(string Uri, string FirstName, string LastName)
        {
            NFT e = new NFT();

            e._uri   = Uri; e._firstName = FirstName; e._lastName = LastName;
            e._state = NeoEntityModel.EntityState.INIT;
            if (NeoTrace.RUNTIME)
            {
                LogExt("New(.,.).NFT", e);
            }
            return(e);
        }
        public static bool Put(NFT e, string key)
        {
            if (key.Length == 0)
            {
                return(false);
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NFT", e);
            }

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

            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Put(skey)._skeyTag", _skeyTag);
            }

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Put(skey).bsta", bsta.Length, bsta);
            }
            bool isMissing = false; if (bsta.Length == 0)

            {
                isMissing = true;
            }

            e._state = NeoEntityModel.EntityState.PUTTED;
            BigInteger bis = e._state.AsBigInteger();

            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Put(skey).bis", bis);
            }
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sSTA, bis);
            if (isMissing)
            {
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sUri, e._uri);         // Template: NPCLevel2EPut_cs.txt
            }
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sFirstName, e._firstName); // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sLastName, e._lastName);   // Template: NPCLevel2EPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NFT", e);                   // Template: NPCLevel2FGet_cs.txt
            }
            return(true);
        }
        /// <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>NFT</returns>
        public static NFT GetElement(NeoVersionedAppUser vau, byte[] domain, int index)
        {
            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);

            NFT e;

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

                    string FirstName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bFirstName)).AsString(); // Template: NPCLevel4CGetElement_cs.txt

                    string LastName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bLastName)).AsString();   // Template: NPCLevel4CGetElement_cs.txt

                    e._uri   = Uri; e._firstName = FirstName; e._lastName = LastName;                                                                           // NPCLevel4DBuryElement_cs.txt
                    e._state = sta;
                    e._state = NeoEntityModel.EntityState.GETTED;                                                                                               /* OVERRIDE */
                }
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).NFT.e", e);
            }
            return(e);
        }
        public static NFT 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;

            NFT e;

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

                string Uri       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sUri).AsString();       //NPCLevel2IGet_cs.txt
                string FirstName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sFirstName).AsString(); //NPCLevel2IGet_cs.txt
                string LastName  = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sLastName).AsString();  //NPCLevel2IGet_cs.txt
                if (NeoTrace.RUNTIME)
                {
                    TraceRuntime("Get(skey).e._uri, e._firstName, e._lastName", e._uri, e._firstName, e._lastName);                   // Template: NPCLevel2Part2_cs.txt
                }
                e._uri   = Uri; e._firstName = FirstName; e._lastName = LastName;
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(skey).NFT", e);
            }
            return(e);
        }
        public static NFT 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);

            NFT 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 = NFT.Missing();
            }
            else // not MISSING
            {
                int ista = (int)bsta.AsBigInteger();
                NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista;
                e = new NFT();

                string Uri       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bUri)).AsString();       //NPCLevel2GGet_cs.txt
                string FirstName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bFirstName)).AsString(); //NPCLevel2GGet_cs.txt
                string LastName  = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bLastName)).AsString();  //NPCLevel2GGet_cs.txt
                e._uri   = Uri; e._firstName = FirstName; e._lastName = LastName;                                                              // Template: NPCLevel2HGet_cs.txt
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED;                                                                                  /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).NFT", e);
            }
            return(e);
        }
        /// <summary>
        /// Collectible methods (NPC Level 4)
        /// </summary>
        /// <param name="e">e</param>
        /// <param name="vau">vau</param>
        /// <param name="index">index</param>
        /// <returns>bool</returns>
        public static bool PutElement(NFT e, NeoVersionedAppUser vau, byte[] domain, int index)
        {
            if (NeoVersionedAppUser.IsNull(vau))
            {
                return(false);
            }

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

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Get(bkey).NFT.bsta", bsta.Length, bsta);
            }
            bool isMissing = false; if (bsta.Length == 0)

            {
                isMissing = true;
            }

            //byte[] bkey;
            e._state = NeoEntityModel.EntityState.PUTTED;
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA), e._state.AsBigInteger());

            if (isMissing)
            {
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bUri), e._uri);         // Template: NPCLevel4APutElementExt0_cs.txt
            }
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bFirstName), e._firstName); // Template: NPCLevel4APutElementExt0_cs.txt

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bLastName), e._lastName);   // Template: NPCLevel4APutElementExt0_cs.txt

            if (NeoTrace.RUNTIME)
            {
                LogExt("PutElement(vau,i).NFT", e);                   // Template: NPCLevel4BGetElement_cs.txt
            }
            return(true);
        }
        /// <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>NFT</returns>
        public static NFT BuryElement(NeoVersionedAppUser vau, byte[] domain, int index)
        {
            if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY?
            {
                return(NFT.Null());
            }

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

            //byte[] bkey;
            NFT e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(vau,index).NFT.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = NFT.Missing();
            }
            else // not MISSING - bury it
            {
                e = NFT.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, index, _bSTA), e._state.AsBigInteger());

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bUri), e._uri);             // NPCLevel4EBuryElement_cs.txt

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bFirstName), e._firstName); // NPCLevel4EBuryElement_cs.txt

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bLastName), e._lastName);   // NPCLevel4EBuryElement_cs.txt
            } // Template: NPCLevel4Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(vau,i).NFT", e);
            }
            return(e);
        }
        public static NFT 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;

            NFT e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(skey).NFT.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = NFT.Missing();
            }
            else // not MISSING - bury it
            {
                e = NFT.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 + _sUri, e._uri); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sFirstName, e._firstName); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sLastName, e._lastName); // Template: NPCLevel3CBury_cs.txt
            } // Template: NPCLevel3Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(skey).NFT", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
        public static bool Put(NFT e, byte[] key)
        {
            if (key.Length == 0)
            {
                return(false);
            }

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

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Put(bkey).bsta", bsta.Length, bsta);
            }
            bool isMissing = false; if (bsta.Length == 0)

            {
                isMissing = true;
            }

            e._state = NeoEntityModel.EntityState.PUTTED;
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bSTA), e._state.AsBigInteger());

            if (isMissing)
            {
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bUri), e._uri);         // Template: NPCLevel2CPut_cs.txt
            }
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bFirstName), e._firstName); // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bLastName), e._lastName);   // Template: NPCLevel2CPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(bkey).NFT", e);                   // Template: NPCLevel2DPut_cs.txt
            }
            return(true);
        }
        public static NFT Bury(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);

            NFT e;

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

                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bUri), e._uri); // Template: NPCLevel3ABury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bFirstName), e._firstName); // Template: NPCLevel3ABury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bLastName), e._lastName); // Template: NPCLevel3ABury_cs.txt
            } // Template: NPCLevel3BBury_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(bkey).NFT", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
示例#16
0
 public static void LogExt(string label, NFT e)
 {
     TraceRuntime(label, e._uri, e._firstName, e._lastName, e._state);
 }
 // Persistable methods
 public static bool IsMissing(NFT e)
 {
     return(e._state == NeoEntityModel.EntityState.MISSING);
 }
 // Deletable methods
 public static bool IsBuried(NFT e)
 {
     return(e._state == NeoEntityModel.EntityState.TOMBSTONED);
 }
示例#19
0
 public static string GetLastName(NFT e)
 {
     return(e._lastName);
 }
示例#20
0
 public static void SetLastName(NFT e, string value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._lastName = value; e._state = NeoEntityModel.EntityState.SET;
 }
示例#21
0
 public static string GetFirstName(NFT e)
 {
     return(e._firstName);
 }
示例#22
0
        // Accessors

        // readonly public static void SetUri(NFT e, string value) // Template: NPCLevel1SetXGetX_cs.txt
        // readonly                        { e._uri = value; e._state = NeoEntityModel.EntityState.SET; }
        public static string GetUri(NFT e)
        {
            return(e._uri);
        }
示例#23
0
 // EntityState wrapper methods
 public static bool IsNull(NFT e)
 {
     return(e._state == NeoEntityModel.EntityState.NULL);
 }