public static NeoCounter 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; NeoCounter e; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA); if (NeoTrace.RUNTIME) { TraceRuntime("Bury(skey).NeoCounter.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING - bury it { e = NeoCounter.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 + _sCurrentNumber, e._currentNumber); // Template: NPCLevel3CBury_cs.txt } // Template: NPCLevel3Part2_cs.txt if (NeoTrace.RUNTIME) { LogExt("Bury(skey).NeoCounter", e); } return(e); // return Entity e to signal if key is Missing or bad key }
/// <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>NeoCounter</returns> public static NeoCounter BuryElement(NeoVersionedAppUser vau, string domain, string sindex) { if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY? { return(NeoCounter.Null()); } Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext; NeoStorageKey nsk = NeoStorageKey.New(vau, domain, "NeoCounter"); byte[] bkey; NeoCounter e; /*STA*/ byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, sindex, _bSTA)); NeoTrace.Trace("Bury(vau,index).NeoCounter.bsta", bsta.Length, bsta); if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING - bury it { e = NeoCounter.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, bkey = NeoStorageKey.StorageKey(nsk, sindex, _bSTA), e._state.AsBigInteger()); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, sindex, _bCurrentNumber), e._currentNumber); // NPCLevel4EBuryElement_cs.txt } // Template: NPCLevel4Part2_cs.txt LogExt("Bury(vau,i).NeoCounter", e); return(e); }
public static NeoCounter 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); NeoCounter e; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA)); NeoTrace.Trace("Get(bkey).bsta", bsta.Length, bsta); if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING { byte[] bext = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bEXT)); int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; e = new NeoCounter(); BigInteger CurrentNumber = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bCurrentNumber)).AsBigInteger(); //NPCLevel2GGet_cs.txt e._currentNumber = CurrentNumber; // Template: NPCLevel2HGet_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } LogExt("Get(bkey).NeoCounter", e); return(e); }
public static NeoCounter 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; NeoCounter e; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA); NeoTrace.Trace("Get(skey).NeoCounter.bsta", bsta.Length, bsta); if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING { byte[] bext = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sEXT); int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; e = new NeoCounter(); BigInteger CurrentNumber = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sCurrentNumber).AsBigInteger(); //NPCLevel2IGet_cs.txt NeoTrace.Trace("Get(skey).e._currentNumber", e._currentNumber); // Template: NPCLevel2Part2_cs.txt e._currentNumber = CurrentNumber; e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } LogExt("Get(skey).NeoCounter", e); return(e); }
public static NeoCounter 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); NeoCounter e; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA)); NeoTrace.Trace("Bury(bkey).bsta", bsta.Length, bsta); if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING - bury it { e = NeoCounter.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, _bCurrentNumber), e._currentNumber); // Template: NPCLevel3ABury_cs.txt } // Template: NPCLevel3BBury_cs.txt LogExt("Bury(bkey).NeoCounter", e); return(e); // return Entity e to signal if key is Missing or bad key }
/// <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>NeoCounter</returns> public static NeoCounter 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); NeoCounter e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).NeoCounter.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = NeoCounter.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new NeoCounter(); BigInteger CurrentNumber = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bCurrentNumber)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt e._currentNumber = CurrentNumber; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).NeoCounter.e", e); } return(e); }