/// <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 specified NEO Storage Key field values.
 /// </summary>
 /// <param name="nsk">NSK</param>
 /// <param name="vau">vau</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, NeoVersionedAppUser vau, byte[] userScriptHash, string className, int index, string fieldName)
 {
     nsk._major          = NeoVersionedAppUser.GetMajor(vau); nsk._minor = NeoVersionedAppUser.GetMinor(vau); nsk._build = NeoVersionedAppUser.GetBuild(vau); /*nsk._revision = NeoVersionedAppUser.GetRevision(vau);*/
     nsk._userScriptHash = NeoVersionedAppUser.GetUserScriptHash(vau);
     nsk._className      = className.AsByteArray(); nsk._index = index; nsk._fieldName = fieldName;
     nsk._state          = NeoEntityModel.EntityState.SET;
 }
Пример #3
0
        /// <summary>
        /// Create a new entity representing a Null entity
        /// </summary>
        /// <returns>NeoVersionedAppUser</returns>
        public static NeoVersionedAppUser Null()
        {
            NeoVersionedAppUser vau = new NeoVersionedAppUser();

            _Initialize(vau);
            LogExt("Null().vau", vau);
            return(vau);
        }
Пример #4
0
 /// <summary>
 /// Initializes the specified vau.
 /// </summary>
 /// <param name="vau">vau</param>
 /// <returns>NeoVersionedAppUser</returns>
 private static NeoVersionedAppUser _Initialize(NeoVersionedAppUser vau)
 {
     vau._app   = NeoEntityModel.NullByteArray;
     vau._major = 0;
     vau._minor = 0;
     vau._build = 0;
     //vau._revision = 0;
     vau._state = NeoEntityModel.EntityState.NULL;
     LogExt("_Initialize(vau).vau", vau);
     return(vau);
 }
Пример #5
0
        /// <summary>
        /// News the specified application.
        /// </summary>
        /// <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>
        /// <returns>NeoVersionedAppUser</returns>
        public static NeoVersionedAppUser New(string app, int major, int minor, int build, /*int revision,*/ byte[] userScriptHash)
        {
            NeoVersionedAppUser vau = new NeoVersionedAppUser();

            vau._app   = app.AsByteArray();
            vau._major = major;
            vau._minor = minor;
            vau._build = build;
            //vau._revision = revision;
            vau._userScriptHash = userScriptHash;
            vau._state          = NeoEntityModel.EntityState.INIT;
            LogExt("New(sa,m,m,b,u).vau", vau);
            return(vau);
        }
        /// <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>
        /// News the specified vau.
        /// </summary>
        /// <param name="vau">vau</param>
        /// <param name="className">class name</param>
        /// <returns>NeoStorageKey</returns>
        public static NeoStorageKey New(NeoVersionedAppUser vau, string className)
        {
            if (NeoVersionedAppUser.IsNull(vau))
            {
                return(NeoStorageKey.Null());
            }

            NeoStorageKey nsk = new NeoStorageKey();

            nsk._app   = NeoVersionedAppUser.GetAppNameAsByteArray(vau);
            nsk._major = NeoVersionedAppUser.GetMajor(vau);
            nsk._minor = NeoVersionedAppUser.GetMinor(vau);
            nsk._build = NeoVersionedAppUser.GetBuild(vau);
            //nsk._revision = NeoVersionedAppUser.GetRevision(vau);
            nsk._userScriptHash = NeoVersionedAppUser.GetUserScriptHash(vau);
            nsk._className      = className.AsByteArray();
            nsk._index          = 0;
            nsk._fieldName      = "";
            nsk._state          = NeoEntityModel.EntityState.INIT;
            LogExt("New(vau,sc).nsk", nsk);
            return(nsk);
        }
        /// <summary>
        /// Collectible methods (NPC Level 4)
        /// </summary>
        /// <param name="p">p</param>
        /// <param name="vau">vau</param>
        /// <param name="index">index</param>
        /// <returns>bool</returns>
        public static bool PutElement(Point p, NeoVersionedAppUser vau, 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, "Point");

            byte[] bkey;
            p._state = NeoEntityModel.EntityState.PUTTED;
            /*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("PutElement(vau,i).p", p);
            return(true);
        }
Пример #9
0
 public static void SetMinor(NeoVersionedAppUser vau, int value)
 {
     vau._minor = value; vau._state = NeoEntityModel.EntityState.SET;
 }
Пример #10
0
 public static string GetAppNameAsString(NeoVersionedAppUser vau)
 {
     return(vau._app.AsString());
 }
Пример #11
0
 public static void SetAppName(NeoVersionedAppUser vau, string value)
 {
     vau._app = value.AsByteArray(); vau._state = NeoEntityModel.EntityState.SET;
 }
Пример #12
0
 public static byte[] GetAppNameAsByteArray(NeoVersionedAppUser vau)
 {
     return(vau._app);
 }
Пример #13
0
 public static byte[] GetUserScriptHash(NeoVersionedAppUser vau)
 {
     return(vau._userScriptHash);
 }
Пример #14
0
 public static int GetBuild(NeoVersionedAppUser vau)
 {
     return(vau._build);
 }
Пример #15
0
        // EntityState wrapper methods

        /// <summary>
        /// Test whether the specified NeoVersionedAppUser is Null.
        /// </summary>
        /// <param name="vau">vau</param>
        /// <returns>
        ///   <c>true</c> if the specified vau is null; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNull(NeoVersionedAppUser vau)
        {
            return(vau._state == NeoEntityModel.EntityState.NULL);
        }
Пример #16
0
 public static int GetMinor(NeoVersionedAppUser vau)
 {
     return(vau._minor);
 }
Пример #17
0
 public static void SetBuild(NeoVersionedAppUser vau, int value)
 {
     vau._build = value; vau._state = NeoEntityModel.EntityState.SET;
 }
Пример #18
0
 // Log/trace methods
 /// <summary>
 /// Logs the specified label.
 /// </summary>
 /// <param name="label">label</param>
 /// <param name="vau">vau</param>
 /// <returns>void</returns>
 public static void Log(string label, NeoVersionedAppUser vau)
 {
     NeoTrace.Trace(label, vau._app, vau._major, vau._minor, vau._build, /*vau._revision,*/ vau._userScriptHash);
 }
Пример #19
0
 //public static void SetRevision(NeoVersionedAppUser vau, int value) { vau._revision = value; vau._state = NeoEntityModel.EntityState.SET; }
 //public static int GetRevision(NeoVersionedAppUser vau) { return vau._revision; }
 public static void SetUserScriptHash(NeoVersionedAppUser vau, byte[] value)
 {
     vau._userScriptHash = value; vau._state = NeoEntityModel.EntityState.SET;
 }
Пример #20
0
 /// <summary>
 /// Logs the ext.
 /// </summary>
 /// <param name="label">label</param>
 /// <param name="vau">vau</param>
 /// <returns>void</returns>
 public static void LogExt(string label, NeoVersionedAppUser vau)
 {
     NeoTrace.Trace(label, vau._app, vau._major, vau._minor, vau._build, /*vau._revision,*/ vau._userScriptHash, vau._state); // long values, state, extension last
 }
Пример #21
0
 public static void Set(NeoVersionedAppUser vau, string app, int major, int minor, int build, /*int revision,*/ byte[] userScriptHash)
 {
     vau._app            = app.AsByteArray(); vau._major = major; vau._minor = minor; vau._build = build; /*vau._revision = revision;*/
     vau._userScriptHash = userScriptHash; vau._state = NeoEntityModel.EntityState.SET;
 }
Пример #22
0
 public static void SetAppName(NeoVersionedAppUser vau, byte[] value)
 {
     vau._app = value; vau._state = NeoEntityModel.EntityState.SET;
 }