/// <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> /// 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); }
/// <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); }