/// <summary>
 /// Gets the application name as byte array.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>app</returns>
 public static byte[] GetAppNameAsByteArray(NeoStorageKey nsk)
 {
     return(nsk._app);
 }
        // EntityState wrapper methods

        /// <summary>
        /// Test whether the specified NeoStorageKey is Null.
        /// </summary>
        /// <param name="nsk">NSK</param>
        /// <returns>
        ///   <c>true</c> if the specified NSK is null; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNull(NeoStorageKey nsk)
        {
            return(nsk._state == NeoEntityModel.EntityState.NULL);
        }
 /// <summary>
 /// Gets the build number of an application
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>int</returns>
 public static int GetBuild(NeoStorageKey nsk)
 {
     return(nsk._build);
 }
 /// <summary>
 /// Sets the name of the application.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetAppName(NeoStorageKey nsk, byte[] value)
 {
     nsk._app = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Gets the major version number of an application.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>int</returns>
 public static int GetMajor(NeoStorageKey nsk)
 {
     return(nsk._major);
 }
        /// <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>Point</returns>
        public static Point GetElement(NeoVersionedAppUser vau, 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, "Point");

            Point p;

            byte[] bkey;
            /*STA*/
            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bSTA));
            NeoTrace.Trace("Get(kb).bs", bsta.Length, bsta);
            if (bsta.Length == 0)
            {
                p = Point.Missing();
            }
            else // not MISSING
            {
                /*EXT*/
                byte[] bext = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bEXT));
                int    ista = (int)bsta.AsBigInteger();
                NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista;
                if (sta == NeoEntityModel.EntityState.TOMBSTONED)
                {
                    p            = Point.Tombstone();
                    p._extension = bext; // TODO: does a Tomestone bury all of its extensions?
                }
                else // not MISSING && not TOMBSTONED
                {
                    p = new Point();
                    /*FIELD*/
                    BigInteger x = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bX)).AsBigInteger();
                    /*FIELD*/
                    BigInteger y = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bY)).AsBigInteger();
                    p._x         = x;
                    p._y         = y;
                    p._state     = sta;
                    p._state     = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
                    p._extension = bext;
                }
            }
            LogExt("Get(kb).p", p);
            return(p);
        }
 /// <summary>
 /// Sets the index of a NEO Storage Key
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetIndex(NeoStorageKey nsk, int value)
 {
     nsk._index = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Sets the name of the application.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetAppName(NeoStorageKey nsk, string value)
 {
     nsk._app = value.AsByteArray(); nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Gets the class name of a NEO Storage Key as byte array.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>className</returns>
 public static byte[] GetClassNameAsByteArray(NeoStorageKey nsk)
 {
     return(nsk._className);
 }
 /// <summary>
 /// Gets the class name of a NEO Storage Key as string.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>string</returns>
 public static string GetClassNameAsString(NeoStorageKey nsk)
 {
     return(nsk._className.AsString());
 }
 /// <summary>
 /// Sets the class name of a NEO Storage Key
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetClassName(NeoStorageKey nsk, byte[] value)
 {
     nsk._className = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Gets the userScriptHash of a NEO Storage Key.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>userScriptHash</returns>
 public static byte[] GetUserScriptHash(NeoStorageKey nsk)
 {
     return(nsk._userScriptHash);
 }
 //public static void SetRevision(NeoStorageKey nsk, int value) { nsk._revision = value; nsk._state = NeoEntityModel.EntityState.SET; }
 //public static int GetRevision(NeoStorageKey nsk) { return nsk._revision; }
 /// <summary>
 /// Sets the userScriptHash of a NEO Storage Key.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetUserScriptHash(NeoStorageKey nsk, byte[] value)
 {
     nsk._userScriptHash = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
        // Log/trace methods

        /// <summary>
        /// Logs the specified label.
        /// </summary>
        /// <param name="label">label</param>
        /// <param name="nsk">NSK</param>
        /// <returns>void</returns>
        public static void Log(string label, NeoStorageKey nsk)
        {
            NeoTrace.Trace(label, nsk._app, nsk._major, nsk._minor, nsk._build, /*nsk._revision,*/ nsk._className, nsk._index, nsk._fieldName, nsk._userScriptHash);
        }
 /// <summary>
 /// Gets the index of a NEO Storage Key
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>int</returns>
 public static int GetIndex(NeoStorageKey nsk)
 {
     return(nsk._index);
 }
 /// <summary>
 /// Logs the ext.
 /// </summary>
 /// <param name="label">label</param>
 /// <param name="nsk">NSK</param>
 /// <returns>void</returns>
 public static void LogExt(string label, NeoStorageKey nsk)
 {
     NeoTrace.Trace(label, nsk._app, nsk._major, nsk._minor, nsk._build, /*nsk._revision,*/ nsk._className, nsk._index, nsk._fieldName, nsk._userScriptHash, nsk._state); // long values, state, extension last
 }
 /// <summary>
 /// Sets the class field name of the NEO Storage Key.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetFieldName(NeoStorageKey nsk, string value)
 {
     nsk._fieldName = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Gets the application name as string.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>string</returns>
 public static string GetAppNameAsString(NeoStorageKey nsk)
 {
     return(nsk._app.AsString());
 }
 /// <summary>
 /// Gets the field name of the NEO Storage Key.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <returns>string</returns>
 public static string GetFieldName(NeoStorageKey nsk)
 {
     return(nsk._fieldName);
 }
 /// <summary>
 /// Sets the minor version number of an application
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetMinor(NeoStorageKey nsk, int value)
 {
     nsk._minor = value; nsk._state = NeoEntityModel.EntityState.SET;
 }
 /// <summary>
 /// Sets the specified NEO Storage Key field values.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="app">application</param>
 /// <param name="major">major</param>
 /// <param name="minor">minor</param>
 /// <param name="build">build</param>
 /// <param name="userScriptHash">userScriptHash</param>
 /// <param name="className">class name</param>
 /// <param name="index">index</param>
 /// <param name="fieldName">field name</param>
 /// <returns>void</returns>
 public static void Set(NeoStorageKey nsk, string app, int major, int minor, int build, /*int revision,*/ byte[] userScriptHash, string className, int index, string fieldName)
 {
     nsk._app            = app.AsByteArray(); nsk._major = major; nsk._minor = minor; nsk._build = build; /*nsk._revision = revision*/;
     nsk._userScriptHash = userScriptHash; nsk._className = className.AsByteArray(); nsk._index = index; nsk._fieldName = fieldName;
     nsk._state          = NeoEntityModel.EntityState.SET;
 }
        /// <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>Point</returns>
        public static Point BuryElement(NeoVersionedAppUser vau, int index)
        {
            if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY?
            {
                return(Point.Null());
            }

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

            byte[] bkey;
            Point  p;

            /*STA*/
            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bSTA));
            NeoTrace.Trace("Bury(vau,index).bs", bsta.Length, bsta);
            if (bsta.Length == 0)
            {
                p = Point.Missing();
            }
            else // not MISSING - bury it
            {
                p = Point.Tombstone(); // TODO - should Bury() preserve the exist field values or re-initialize them? Preserve is cheaper but not as private
                /*STA*/
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bSTA), p._state.AsBigInteger());
                /*EXT*/
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bEXT), p._extension);
                /*FIELD*/
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bX), p._x);
                /*FIELD*/
                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bY), p._y);
            }
            LogExt("Bury(vau,i).p", p);
            return(p);
        }
 /// <summary>
 /// Sets the build number of an application
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="value">value</param>
 /// <returns>void</returns>
 public static void SetBuild(NeoStorageKey nsk, int value)
 {
     nsk._build = value; nsk._state = NeoEntityModel.EntityState.SET;
 }