// Use case example: domain = user script hash, counter = NeoCounters.UserPointsCounter
        // TakeNextNumber semantics: return the current number and then advance the counter ...like at the grocery store
        public static BigInteger TakeNextNumber(NeoVersionedAppUser vau, byte[] domain, NeoCounters counter)
        {
            NeoCounter nc = NeoCounter.GetElement(vau, domain, (int)counter); // Get persisted counter value

            if (NeoTrace.INFO)
            {
                NeoCounter.LogExt("TakeNextNumber", nc);
            }

            if (NeoCounter.IsMissing(nc)) // Create persist the new counter entity
            {
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("TakeNextNumber.domain and counter is missing", nc);
                }
                nc = NeoCounter.New(); // Create a new counter entity
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("TakeNextNumber.putnew", nc);
                }
                NeoCounter.PutElement(nc, vau, domain, (int)counter); // Persist the new counter entity with a value of zero
            }

            if (NeoTrace.INFO)
            {
                NeoCounter.LogExt("TakeNextNumber.exists", nc);
            }
            BigInteger currentNextNumber = NeoCounter.GetCurrentNumber(nc);

            if (NeoTrace.INFO)
            {
                NeoTraceRuntime.TraceRuntime("currentNextNumber", currentNextNumber);
            }
            BigInteger newNextNumber = currentNextNumber + 1;

            if (NeoTrace.INFO)
            {
                NeoTraceRuntime.TraceRuntime("nextNumber", newNextNumber);
            }
            NeoCounter.SetCurrentNumber(nc, newNextNumber);
            if (NeoTrace.INFO)
            {
                NeoCounter.LogExt("TakeNextNumber.putincr", nc);
            }
            NeoCounter.PutElement(nc, vau, domain, (int)counter); // Persist the new counter

            return(currentNextNumber);
        }
        public static BigInteger TakeNextNumber(NeoVersionedAppUser vau, NeoCounters counter)
        {
            NeoCounter nc = NeoCounter.GetElement(vau, DOMAINAC, (int)counter); // Get persisted counter value

            if (NeoTrace.INFO)
            {
                NeoCounter.LogExt("TakeNextNumber", nc);
            }

            if (NeoCounter.IsMissing(nc))
            {
                nc = NeoCounter.New(); // Create a new counter value
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("TakeNextNumber.putnew", nc);
                }
                NeoCounter.PutElement(nc, vau, DOMAINAC, (int)counter); // Persist the new counter
            }
            else // Get and increment counter value by 1
            {
                BigInteger newNumber = NeoCounter.GetCurrentNumber(nc);
                if (NeoTrace.INFO)
                {
                    NeoTraceRuntime.TraceRuntime("newNumber", newNumber);
                }
                newNumber = newNumber + 1;
                if (NeoTrace.INFO)
                {
                    NeoTraceRuntime.TraceRuntime("newNumber", newNumber);
                }
                NeoCounter.SetCurrentNumber(nc, newNumber);
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("TakeNextNumber.putincr", nc);
                }
                NeoCounter.PutElement(nc, vau, DOMAINAC, (int)counter); // Persist the new counter
            }

            return(NeoCounter.GetCurrentNumber(nc));
        }
        // Use case example: domain = user script hash, counter = NeoCounters.UserPointsCounter
        public static BigInteger GiveBackLastNumber(NeoVersionedAppUser vau, byte[] domain, NeoCounters counter)
        {
            NeoCounter nc = NeoCounter.GetElement(vau, domain, (int)counter); // Get persisted counter value

            if (NeoTrace.INFO)
            {
                NeoCounter.LogExt("GiveBackLastNumber", nc);
            }

            if (NeoCounter.IsMissing(nc))
            {
                nc = NeoCounter.New(); // Create a new counter value
            }
            else // Get and decrement counter value by 1
            {
                BigInteger currentNumber = NeoCounter.GetCurrentNumber(nc);
                if (NeoTrace.INFO)
                {
                    NeoTraceRuntime.TraceRuntime("currentNumber", currentNumber);
                }
                currentNumber = currentNumber - 1;
                if (NeoTrace.INFO)
                {
                    NeoTraceRuntime.TraceRuntime("currentNumber", currentNumber);
                }
                NeoCounter.SetCurrentNumber(nc, currentNumber);
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("GiveBackLastNumber", nc);
                }
                NeoCounter.PutElement(nc, vau, domain, (int)counter); // Persist the incremented current value of the counter
                if (NeoTrace.INFO)
                {
                    NeoCounter.LogExt("GiveBackLastNumber", nc);
                }
            }

            return(NeoCounter.GetCurrentNumber(nc));
        }