public static BigInteger balanceOf(byte[] account)
        {
            BigInteger balance = (BigInteger)0;

            if (NeoTrace.VERBOSE)
            {
                NeoTrace.Trace("balanceOf():entered");
            }

            NPCNEP5LedgerEntry accountLedgerEntry = NPCNEP5LedgerEntry.Get(account);

            if (NeoTrace.VERBOSE)
            {
                NPCNEP5LedgerEntry.Log("balanceOf().ledgerEntry", accountLedgerEntry);
            }
            if (!NPCNEP5LedgerEntry.IsMissing(accountLedgerEntry))
            {
                if (NeoTrace.VERBOSE)
                {
                    NeoTrace.Trace("accountLedgerEntry is not Missing");
                }
                balance = NPCNEP5LedgerEntry.GetBalance(accountLedgerEntry);
            }

            return(balance);
        }
 // Factory methods // Template: NPCLevel1Part2_cs.txt
 private static NPCNEP5LedgerEntry _Initialize(NPCNEP5LedgerEntry e)
 {
     e._lastTxTimestamp = 0; e._debitCreditAmount = 0; e._balance = 0;
     e._state           = NeoEntityModel.EntityState.NULL;
     if (NeoTrace.RUNTIME)
     {
         LogExt("_Initialize(e).NPCNEP5LedgerEntry", e);
     }
     return(e);
 }
        public static NPCNEP5LedgerEntry New()
        {
            NPCNEP5LedgerEntry e = new NPCNEP5LedgerEntry();

            _Initialize(e);
            if (NeoTrace.RUNTIME)
            {
                LogExt("New().NPCNEP5LedgerEntry", e);
            }
            return(e);
        }
        public static NPCNEP5LedgerEntry UpdateLedger(NPCNEP5Base tokenBase, NPCNEP5FundingRound[] fundingRounds)
        {
            NPCNEP5LedgerEntry e = new NPCNEP5LedgerEntry();

            if (NeoTrace.RUNTIME)
            {
                LogExt("UpdateLedger().NPCNEP5LedgerEntry", e);
            }

            return(e);
        }
        public static NPCNEP5LedgerEntry New(BigInteger LastTxTimestamp, BigInteger DebitCreditAmount, BigInteger Balance)
        {
            NPCNEP5LedgerEntry e = new NPCNEP5LedgerEntry();

            e._lastTxTimestamp = LastTxTimestamp; e._debitCreditAmount = DebitCreditAmount; e._balance = Balance;
            e._state           = NeoEntityModel.EntityState.INIT;
            if (NeoTrace.RUNTIME)
            {
                LogExt("New(.,.).NPCNEP5LedgerEntry", e);
            }
            return(e);
        }
Esempio n. 6
0
        public static NPCNEP5LedgerEntry Missing()
        {
            NPCNEP5LedgerEntry e = new NPCNEP5LedgerEntry();

            e._lastTxTimestamp = 0; e._debitCreditAmount = 0; e._balance = 0;
            e._state           = NeoEntityModel.EntityState.MISSING;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Missing().NPCNEP5LedgerEntry", e);
            }
            return(e);
        }
Esempio n. 7
0
        public static NPCNEP5LedgerEntry 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;

            NPCNEP5LedgerEntry e;

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

                BigInteger LastTxTimestamp   = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sLastTxTimestamp).AsBigInteger();   //NPCLevel2IGet_cs.txt
                BigInteger DebitCreditAmount = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sDebitCreditAmount).AsBigInteger(); //NPCLevel2IGet_cs.txt
                BigInteger Balance           = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sBalance).AsBigInteger();           //NPCLevel2IGet_cs.txt
                if (NeoTrace.RUNTIME)
                {
                    TraceRuntime("Get(skey).e._lastTxTimestamp, e._debitCreditAmount, e._balance", e._lastTxTimestamp, e._debitCreditAmount, e._balance);                   // Template: NPCLevel2Part2_cs.txt
                }
                e._lastTxTimestamp = LastTxTimestamp; e._debitCreditAmount = DebitCreditAmount; e._balance = Balance;
                e._state           = sta;
                e._state           = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(skey).NPCNEP5LedgerEntry", e);
            }
            return(e);
        }
Esempio n. 8
0
        public static NPCNEP5LedgerEntry 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);

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

                BigInteger LastTxTimestamp   = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bLastTxTimestamp)).AsBigInteger();   //NPCLevel2GGet_cs.txt
                BigInteger DebitCreditAmount = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bDebitCreditAmount)).AsBigInteger(); //NPCLevel2GGet_cs.txt
                BigInteger Balance           = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bBalance)).AsBigInteger();           //NPCLevel2GGet_cs.txt
                e._lastTxTimestamp = LastTxTimestamp; e._debitCreditAmount = DebitCreditAmount; e._balance = Balance;                                                  // Template: NPCLevel2HGet_cs.txt
                e._state           = sta;
                e._state           = NeoEntityModel.EntityState.GETTED;                                                                                                /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).NPCNEP5LedgerEntry", e);
            }
            return(e);
        }
Esempio n. 9
0
        public static bool Put(NPCNEP5LedgerEntry 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);

            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, _bLastTxTimestamp), e._lastTxTimestamp);     // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bDebitCreditAmount), e._debitCreditAmount); // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bBalance), e._balance);                     // Template: NPCLevel2CPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(bkey).NPCNEP5LedgerEntry", e);                   // Template: NPCLevel2DPut_cs.txt
            }
            return(true);
        }
        public static bool deploy(NPCNEP5Base tokenbase)
        {
            bool result = false;

            if (NeoTrace.VERBOSE)
            {
                NeoTrace.Trace("deploy():entered");
            }

            NPCEnvironment env = NPCEnvironment.New();

            NPCEnvironment.Initialize(env);

            NPCNEP5LedgerEntry ownerLedgerEntry = NPCNEP5LedgerEntry.Get(OwnerAccountScriptHash);

            if (NeoTrace.VERBOSE)
            {
                NPCNEP5LedgerEntry.Log("deploy().ownerLedgerEntry", ownerLedgerEntry);
            }
            if (NPCNEP5LedgerEntry.IsMissing(ownerLedgerEntry))
            {
                if (NeoTrace.VERBOSE)
                {
                    NeoTrace.Trace("ownerLedgerEntry is Missing");
                }
                NPCNEP5LedgerEntry.Set(ownerLedgerEntry,
                                       NPCEnvironment.GetBlockTimestamp(env), 0, NPCNEP5Base.GetTotalSupply(tokenbase));
                NPCNEP5LedgerEntry.Put(ownerLedgerEntry, OwnerAccountScriptHash);
                if (NeoTrace.VERBOSE)
                {
                    NPCNEP5LedgerEntry.Log("deploy().ownerLedgerEntry", ownerLedgerEntry);
                }
                result = true;
            }

            return(result);
        }
Esempio n. 11
0
        public static bool Put(NPCNEP5LedgerEntry e, string key)
        {
            if (key.Length == 0)
            {
                return(false);
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NPCNEP5LedgerEntry", 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);
            }

            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 + _sLastTxTimestamp, e._lastTxTimestamp);     // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sDebitCreditAmount, e._debitCreditAmount); // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sBalance, e._balance);                     // Template: NPCLevel2EPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NPCNEP5LedgerEntry", e);                   // Template: NPCLevel2FGet_cs.txt
            }
            return(true);
        }
 // EntityState wrapper methods
 public static bool IsNull(NPCNEP5LedgerEntry e)
 {
     return(e._state == NeoEntityModel.EntityState.NULL);
 }
 public static void Set(NPCNEP5LedgerEntry e, BigInteger LastTxTimestamp, BigInteger DebitCreditAmount, BigInteger Balance) // Template: NPCLevel1Set_cs.txt
 {
     e._lastTxTimestamp = LastTxTimestamp; e._debitCreditAmount = DebitCreditAmount; e._balance = Balance;  e._state = NeoEntityModel.EntityState.SET;
 }
Esempio n. 14
0
 // Persistable methods
 public static bool IsMissing(NPCNEP5LedgerEntry e)
 {
     return(e._state == NeoEntityModel.EntityState.MISSING);
 }
 public static void LogExt(string label, NPCNEP5LedgerEntry e)
 {
     TraceRuntime(label, e._lastTxTimestamp, e._debitCreditAmount, e._balance, e._state);
 }
 public static BigInteger GetLastTxTimestamp(NPCNEP5LedgerEntry e)
 {
     return(e._lastTxTimestamp);
 }
        // Accessors

        public static void SetLastTxTimestamp(NPCNEP5LedgerEntry e, BigInteger value) // Template: NPCLevel1SetXGetX_cs.txt
        {
            e._lastTxTimestamp = value; e._state = NeoEntityModel.EntityState.SET;
        }
 public static void SetDebitCreditAmount(NPCNEP5LedgerEntry e, BigInteger value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._debitCreditAmount = value; e._state = NeoEntityModel.EntityState.SET;
 }
 public static BigInteger GetDebitCreditAmount(NPCNEP5LedgerEntry e)
 {
     return(e._debitCreditAmount);
 }
 public static void SetBalance(NPCNEP5LedgerEntry e, BigInteger value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._balance = value; e._state = NeoEntityModel.EntityState.SET;
 }
 public static BigInteger GetBalance(NPCNEP5LedgerEntry e)
 {
     return(e._balance);
 }
        public static bool transfer(byte[] from, byte[] to, BigInteger amount)
        {
            bool result = false;

            if (NeoTrace.VERBOSE)
            {
                NeoTrace.Trace("transfer():entered", from, to, amount);
            }

            // https://github.com/neo-project/examples-csharp/blob/master/ICO_Template/ICO_Template.cs#L146

            if (amount > 0)
            {
                if (NeoTrace.VERBOSE)
                {
                    NeoTrace.Trace("transfer():amount > 0");
                }
                //if (Neo.SmartContract.Framework.Services.Neo.Runtime.CheckWitness(from))
                {
                    if (from == to)
                    {
                        if (NeoTrace.VERBOSE)
                        {
                            NeoTrace.Trace("transfer():from == to");
                        }
                        result = true;
                    }
                    else
                    {
                        if (NeoTrace.VERBOSE)
                        {
                            NeoTrace.Trace("transfer():from != to");
                        }
                        NPCNEP5LedgerEntry fromLedgerEntry = NPCNEP5LedgerEntry.Get(from);
                        if (NeoTrace.VERBOSE)
                        {
                            NPCNEP5LedgerEntry.Log("transfer().fromLedgerEntry", fromLedgerEntry);
                        }
                        BigInteger fromBalance = NPCNEP5LedgerEntry.GetBalance(fromLedgerEntry);
                        if (fromBalance >= amount)
                        {
                            if (NeoTrace.VERBOSE)
                            {
                                NeoTrace.Trace("transfer():fromBalance >= amount");
                            }
                            //NPCEnvironment env = NPCEnvironment.New();
                            //NPCEnvironment.Initialize(env);
                            //BigInteger timestamp = NPCEnvironment.GetBlockTimestamp(env);

                            //uint h = Blockchain.GetHeight();
                            //Header header = Blockchain.GetHeader(h);
                            //BigInteger timestamp = header.Timestamp;
                            //Block block = Blockchain.GetBlock(h); // NEO Debugger: not implemented
                            //BigInteger timestamp = block.Timestamp;

                            BigInteger timestamp = 0;

                            NPCNEP5LedgerEntry.Set(fromLedgerEntry, timestamp, 0 - amount, fromBalance - amount);
                            NPCNEP5LedgerEntry.Put(fromLedgerEntry, from);
                            if (NeoTrace.VERBOSE)
                            {
                                NPCNEP5LedgerEntry.Log("transfer().fromLedgerEntry", fromLedgerEntry);
                            }

                            NPCNEP5LedgerEntry toLedgerEntry = NPCNEP5LedgerEntry.Get(to);
                            if (NeoTrace.VERBOSE)
                            {
                                NPCNEP5LedgerEntry.Log("transfer().toLedgerEntry", toLedgerEntry);
                            }
                            BigInteger toBalance = NPCNEP5LedgerEntry.GetBalance(toLedgerEntry);

                            NPCNEP5LedgerEntry.Set(toLedgerEntry, timestamp, 0 + amount, toBalance + amount);
                            NPCNEP5LedgerEntry.Put(toLedgerEntry, to);
                            if (NeoTrace.VERBOSE)
                            {
                                NPCNEP5LedgerEntry.Log("transfer().toLedgerEntry", toLedgerEntry);
                            }

                            Transfer(from, to, amount);
                            result = true;
                        }
                    }
                }
            }

            return(result);
        }