Ejemplo n.º 1
0
        /// <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(UserLedgerEntry e, NeoVersionedAppUser vau, byte[] domain, byte[] bindex)
        {
            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);

            // no readonly fields byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA));
            // no readonly fields if (NeoTrace.RUNTIME) TraceRuntime("Get(bkey).UserLedgerEntry.bsta", bsta.Length, bsta);
            // no readonly fields 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, bindex, _bSTA), e._state.AsBigInteger());

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bUserScriptHash), e._userScriptHash);             // Template: NPCLevel4APutElementExt2_cs.txt

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bPassphraseScriptHash), e._passphraseScriptHash); // Template: NPCLevel4APutElementExt2_cs.txt

            if (NeoTrace.RUNTIME)
            {
                LogExt("PutElement(vau,i).UserLedgerEntry", e);                   // Template: NPCLevel4BGetElement_cs.txt
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static UserLedgerEntry 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;

            UserLedgerEntry e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(skey).UserLedgerEntry.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = UserLedgerEntry.Missing();
            }
            else // not MISSING - bury it
            {
                e = UserLedgerEntry.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 + _sUserScriptHash, e._userScriptHash); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sPassphraseScriptHash, e._passphraseScriptHash); // Template: NPCLevel3CBury_cs.txt
            } // Template: NPCLevel3Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(skey).UserLedgerEntry", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
Ejemplo n.º 3
0
        public static bool Put(UserLedgerEntry 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);

            // no readonly fields byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA));
            // no readonly fields if (NeoTrace.RUNTIME) TraceRuntime("Put(bkey).bsta", bsta.Length, bsta);
            // no readonly fields 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());

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bUserScriptHash), e._userScriptHash);             // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bPassphraseScriptHash), e._passphraseScriptHash); // Template: NPCLevel2CPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(bkey).UserLedgerEntry", e);                   // Template: NPCLevel2DPut_cs.txt
            }
            return(true);
        }
Ejemplo n.º 4
0
 // Factory methods // Template: NPCLevel1Part2_cs.txt
 private static UserLedgerEntry _Initialize(UserLedgerEntry e)
 {
     e._userScriptHash = NeoEntityModel.NullByteArray; e._passphraseScriptHash = NeoEntityModel.NullByteArray;
     e._state          = NeoEntityModel.EntityState.NULL;
     if (NeoTrace.RUNTIME)
     {
         LogExt("_Initialize(e).UserLedgerEntry", e);
     }
     return(e);
 }
Ejemplo n.º 5
0
        public static UserLedgerEntry Null()
        {
            UserLedgerEntry e = new UserLedgerEntry();

            _Initialize(e);
            if (NeoTrace.RUNTIME)
            {
                LogExt("Null().UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 6
0
        public static UserLedgerEntry Tombstone()
        {
            UserLedgerEntry e = new UserLedgerEntry();

            e._userScriptHash = NeoEntityModel.NullByteArray; e._passphraseScriptHash = NeoEntityModel.NullByteArray;
            e._state          = NeoEntityModel.EntityState.TOMBSTONED;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Tombstone().UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 7
0
        public static UserLedgerEntry Missing()
        {
            UserLedgerEntry e = new UserLedgerEntry();

            e._userScriptHash = NeoEntityModel.NullByteArray; e._passphraseScriptHash = NeoEntityModel.NullByteArray;
            e._state          = NeoEntityModel.EntityState.MISSING;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Missing().UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 8
0
        public static UserLedgerEntry New(byte[] UserScriptHash, byte[] PassphraseScriptHash)
        {
            UserLedgerEntry e = new UserLedgerEntry();

            e._userScriptHash = UserScriptHash; e._passphraseScriptHash = PassphraseScriptHash;
            e._state          = NeoEntityModel.EntityState.INIT;
            if (NeoTrace.RUNTIME)
            {
                LogExt("New(.,.).UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 9
0
        /// <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>UserLedgerEntry</returns>
        public static UserLedgerEntry 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);

            UserLedgerEntry e;

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

                    byte[] PassphraseScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bPassphraseScriptHash)); // Template: NPCLevel4CGetElement_cs.txt

                    e._userScriptHash = UserScriptHash; e._passphraseScriptHash = PassphraseScriptHash;                                                                     // NPCLevel4DBuryElement_cs.txt
                    e._state          = sta;
                    e._state          = NeoEntityModel.EntityState.GETTED;                                                                                                  /* OVERRIDE */
                }
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).UserLedgerEntry.e", e);
            }
            return(e);
        }
Ejemplo n.º 10
0
        public static UserLedgerEntry 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;

            UserLedgerEntry e;

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

                byte[] UserScriptHash       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sUserScriptHash);       //NPCLevel2IGet_cs.txt
                byte[] PassphraseScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sPassphraseScriptHash); //NPCLevel2IGet_cs.txt
                if (NeoTrace.RUNTIME)
                {
                    TraceRuntime("Get(skey).e._userScriptHash, e._passphraseScriptHash", e._userScriptHash, e._passphraseScriptHash);                   // Template: NPCLevel2Part2_cs.txt
                }
                e._userScriptHash = UserScriptHash; e._passphraseScriptHash = PassphraseScriptHash;
                e._state          = sta;
                e._state          = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(skey).UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 11
0
        public static UserLedgerEntry 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);

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

                byte[] UserScriptHash       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bUserScriptHash));       //NPCLevel2GGet_cs.txt
                byte[] PassphraseScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bPassphraseScriptHash)); //NPCLevel2GGet_cs.txt
                e._userScriptHash = UserScriptHash; e._passphraseScriptHash = PassphraseScriptHash;                                                       // Template: NPCLevel2HGet_cs.txt
                e._state          = sta;
                e._state          = NeoEntityModel.EntityState.GETTED;                                                                                    /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 12
0
        public static bool Put(UserLedgerEntry e, string key)
        {
            if (key.Length == 0)
            {
                return(false);
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).UserLedgerEntry", 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);
            }

            // no readonly fields byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            // no readonly fields if (NeoTrace.RUNTIME) TraceRuntime("Put(skey).bsta", bsta.Length, bsta);
            // no readonly fields 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);
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sUserScriptHash, e._userScriptHash);             // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sPassphraseScriptHash, e._passphraseScriptHash); // Template: NPCLevel2EPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).UserLedgerEntry", e);                   // Template: NPCLevel2FGet_cs.txt
            }
            return(true);
        }
Ejemplo n.º 13
0
        /// <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>UserLedgerEntry</returns>
        public static UserLedgerEntry BuryElement(NeoVersionedAppUser vau, byte[] domain, byte[] bindex)
        {
            if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY?
            {
                return(UserLedgerEntry.Null());
            }

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

            //byte[] bkey;
            UserLedgerEntry e;

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

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bUserScriptHash), e._userScriptHash);             // NPCLevel4EBuryElement_cs.txt

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bPassphraseScriptHash), e._passphraseScriptHash); // NPCLevel4EBuryElement_cs.txt
            } // Template: NPCLevel4Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(vau,i).UserLedgerEntry", e);
            }
            return(e);
        }
Ejemplo n.º 14
0
 public static void Set(UserLedgerEntry e, byte[] UserScriptHash, byte[] PassphraseScriptHash) // Template: NPCLevel1Set_cs.txt
 {
     { e._userScriptHash = UserScriptHash; e._passphraseScriptHash = PassphraseScriptHash;  e._state = NeoEntityModel.EntityState.SET; }
 }
Ejemplo n.º 15
0
 public static byte[] GetPassphraseScriptHash(UserLedgerEntry e)
 {
     return(e._passphraseScriptHash);
 }
Ejemplo n.º 16
0
 public static void SetPassphraseScriptHash(UserLedgerEntry e, byte[] value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._passphraseScriptHash = value; e._state = NeoEntityModel.EntityState.SET;
 }
Ejemplo n.º 17
0
 public static byte[] GetUserScriptHash(UserLedgerEntry e)
 {
     return(e._userScriptHash);
 }
Ejemplo n.º 18
0
 public static void LogExt(string label, UserLedgerEntry e)
 {
     TraceRuntime(label, e._userScriptHash, e._passphraseScriptHash, e._state);
 }
Ejemplo n.º 19
0
 // EntityState wrapper methods
 public static bool IsNull(UserLedgerEntry e)
 {
     return(e._state == NeoEntityModel.EntityState.NULL);
 }
Ejemplo n.º 20
0
        public static object Main()
        {
            object result = false;

            NeoVersionedAppUser vau = NeoVersionedAppUser.New(_AppName, _AppVersionMajor, _AppVersionMinor, _AppVersionBuild, _OwnerAccountScriptHash);

            NeoCounter counter1 = NeoCounter.New(1234);

            NeoCounter.Put(counter1, "MyCounter1");
            NeoCounter.Log("counter1", counter1);
            counter1 = NeoCounter.Get("MyCounter1");
            NeoCounter.Log("counter1", counter1);

            NeoCounter counter2 = NeoCounter.New(5678);

            NeoCounter.PutElement(counter2, vau, DOMAIN_MYCOUNTER2, 0);
            NeoCounter.Log("counter2", counter2);
            counter2 = NeoCounter.GetElement(vau, DOMAIN_MYCOUNTER2, 0);
            NeoCounter.Log("counter2", counter2);

            BigInteger nextNumber3 = NeoCounter.TakeNextNumber(vau, NeoCounter.NeoCounters.PointCounter);

            NeoTrace.Trace("nextNumber3", nextNumber3);
            nextNumber3 = NeoCounter.TakeNextNumber(vau, NeoCounter.NeoCounters.PointCounter);
            NeoTrace.Trace("nextNumber3", nextNumber3);
            nextNumber3 = NeoCounter.TakeNextNumber(vau, NeoCounter.NeoCounters.PointCounter);
            NeoTrace.Trace("nextNumber3", nextNumber3);

            BigInteger nextNumber5 = NeoCounter.TakeNextNumber(vau, DOMAIN_MYCOUNTER5, NeoCounter.NeoCounters.RequisitionCounter);

            NeoTrace.Trace("nextNumber5", nextNumber5);
            nextNumber5 = NeoCounter.TakeNextNumber(vau, DOMAIN_MYCOUNTER5, NeoCounter.NeoCounters.RequisitionCounter);
            NeoTrace.Trace("nextNumber5", nextNumber5);
            nextNumber5 = NeoCounter.TakeNextNumber(vau, DOMAIN_MYCOUNTER5, NeoCounter.NeoCounters.RequisitionCounter);
            NeoTrace.Trace("nextNumber5", nextNumber5);

            int iteration = 0;

            while (true)
            {
                if (iteration >= 10)
                {
                    break;
                }
                NeoTrace.Trace("iteration", iteration);

                BigInteger nextIndex = NeoCounter.TakeNextNumber(vau, NeoCounter.NeoCounters.UserCounter);
                NeoTrace.Trace("nextIndex", nextIndex);

                UserLedgerEntry e = UserLedgerEntry.New(_User1AccountScriptHash, _User1PassphraseScriptHash);
                UserLedgerEntry.Log("e.put1", e);
                UserLedgerEntry.SetUserScriptHash(e, _User2AccountScriptHash);
                UserLedgerEntry.Log("e.put2", e);
                UserLedgerEntry.SetPassphraseScriptHash(e, _User2PassphraseScriptHash);
                UserLedgerEntry.Log("e.put3", e);

                UserLedgerEntry.PutElement(e, vau, DOMAIN_USERLEDGER, (int)nextIndex);
                iteration++;
            }

            iteration = 0;
            BigInteger nUsers = NeoCounter.GetNextNumber(vau, NeoCounter.NeoCounters.UserCounter);

            UserLedgerEntry[] users = new UserLedgerEntry[(int)nUsers];
            while (true)
            {
                if (iteration >= nUsers)
                {
                    break;
                }
                NeoTrace.Trace("iteration", iteration);

                UserLedgerEntry e = UserLedgerEntry.GetElement(vau, DOMAIN_USERLEDGER, iteration);
                UserLedgerEntry.Log("e.get", e);
                users[iteration] = e;
                UserLedgerEntry.Log("users[iteration]", users[iteration]);
                iteration++;
            }

            result = users;
            return(result);
        }
Ejemplo n.º 21
0
 // Deletable methods
 public static bool IsBuried(UserLedgerEntry e)
 {
     return(e._state == NeoEntityModel.EntityState.TOMBSTONED);
 }
Ejemplo n.º 22
0
 // Persistable methods
 public static bool IsMissing(UserLedgerEntry e)
 {
     return(e._state == NeoEntityModel.EntityState.MISSING);
 }