示例#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(NPCContributor 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);

            //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, _bName), e._name);                             // Template: NPCLevel4APutElement_cs.txt

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bTitle), e._title);                           // Template: NPCLevel4APutElement_cs.txt

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bApproverScriptHash), e._approverScriptHash); // Template: NPCLevel4APutElement_cs.txt

            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bReqPublicKey), e._reqPublicKey);             // Template: NPCLevel4APutElement_cs.txt

            if (NeoTrace.RUNTIME)
            {
                LogExt("PutElement(vau,i).NPCContributor", e);                   // Template: NPCLevel4BGetElement_cs.txt
            }
            return(true);
        }
        public static NPCContributor GetContributor(NeoVersionedAppUser AppVAU, object[] args)
        {
            NPCContributor results = NPCContributor.Null();

            byte[] encodedContributorname = (byte[])args[0];
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("GetContributor.encodedContributorname", encodedContributorname);
            }

            NPCContributor uc = FindContributor(AppVAU, encodedContributorname);

            if (NeoTrace.INFO)
            {
                NPCContributor.LogExt("GetContributor.uc", uc);
            }

            results = uc;
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("GetContributor.results", results);
            }

            return(results);
        }
 // Factory methods // Template: NPCLevel1Part2_cs.txt
 private static NPCContributor _Initialize(NPCContributor e)
 {
     e._name  = ""; e._title = ""; e._approverScriptHash = NeoEntityModel.NullByteArray; e._reqPublicKey = NeoEntityModel.NullByteArray;
     e._state = NeoEntityModel.EntityState.NULL;
     if (NeoTrace.RUNTIME)
     {
         LogExt("_Initialize(e).NPCContributor", e);
     }
     return(e);
 }
        public static NPCContributor New()
        {
            NPCContributor e = new NPCContributor();

            _Initialize(e);
            if (NeoTrace.RUNTIME)
            {
                LogExt("New().NPCContributor", e);
            }
            return(e);
        }
        public static NPCContributor Missing()
        {
            NPCContributor e = new NPCContributor();

            e._name  = ""; e._title = ""; e._approverScriptHash = NeoEntityModel.NullByteArray; e._reqPublicKey = NeoEntityModel.NullByteArray;
            e._state = NeoEntityModel.EntityState.MISSING;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Missing().NPCContributor", e);
            }
            return(e);
        }
        public static NPCContributor New(string Name, string Title, byte[] ApproverScriptHash, byte[] ReqPublicKey)
        {
            NPCContributor e = new NPCContributor();

            e._name  = Name; e._title = Title; e._approverScriptHash = ApproverScriptHash; e._reqPublicKey = ReqPublicKey;
            e._state = NeoEntityModel.EntityState.INIT;
            if (NeoTrace.RUNTIME)
            {
                LogExt("New(.,.).NPCContributor", e);
            }
            return(e);
        }
示例#7
0
        public static NPCContributor Tombstone()
        {
            NPCContributor e = new NPCContributor();

            e._name  = ""; e._title = ""; e._approverScriptHash = NeoEntityModel.NullByteArray; e._reqPublicKey = NeoEntityModel.NullByteArray;
            e._state = NeoEntityModel.EntityState.TOMBSTONED;
            if (NeoTrace.RUNTIME)
            {
                LogExt("Tombstone().NPCContributor", e);
            }
            return(e);
        }
示例#8
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>NPCContributor</returns>
        public static NPCContributor 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);

            NPCContributor e;

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

                    string Title = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bTitle)).AsString();                // Template: NPCLevel4CGetElement_cs.txt

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

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

                    e._name  = Name; e._title = Title; e._approverScriptHash = ApproverScriptHash; e._reqPublicKey = ReqPublicKey;                                      // NPCLevel4DBuryElement_cs.txt
                    e._state = sta;
                    e._state = NeoEntityModel.EntityState.GETTED;                                                                                                       /* OVERRIDE */
                }
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).NPCContributor.e", e);
            }
            return(e);
        }
        private static NPCContributor FindContributor(NeoVersionedAppUser AppVAU, byte[] encodedContributorname)
        {
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("FindContributor.encodedContributorname", encodedContributorname);
            }

            NPCContributor result = NPCContributor.GetElement(AppVAU, DOMAINUCD, encodedContributorname);

            if (NeoTrace.ARGSRESULTS)
            {
                NPCContributor.LogExt("FindContributor.result", result);
            }

            return(result);
        }
        static readonly byte[] DOMAINUCD = "UCD".AsByteArray(); // User Credentials Directory (UCD)

        public static NPCContributor CreateContributor(NeoVersionedAppUser AppVAU, object[] args)
        {
            NPCContributor results = NPCContributor.Null();

            byte[] encodedContributorname = (byte[])args[0];
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("AddContributor.encodedContributorname", encodedContributorname);
            }
            byte[] encodedPassword = (byte[])args[1];
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("AddContributor.encodedPassword", encodedPassword);
            }

            NPCContributor uc = FindContributor(AppVAU, encodedContributorname);

            if (NPCContributor.IsMissing(uc)) // add the unique new user
            {
                if (NeoTrace.INFO)
                {
                    NPCContributor.LogExt("AddContributor.missing", uc);
                }
                uc = NPCContributor.New(encodedContributorname, encodedPassword);
                NPCContributor.PutElement(uc, AppVAU, DOMAINUCD, encodedContributorname);
                if (NeoTrace.INFO)
                {
                    NPCContributor.LogExt("AddContributor.added", uc);
                }
            }
            else
            {
                if (NeoTrace.INFO)
                {
                    NPCContributor.LogExt("AddContributor.exists", uc);
                }
            }

            results = uc;
            if (NeoTrace.ARGSRESULTS)
            {
                NeoTrace.Trace("AddContributor.results", results);
            }

            return(results);
        }
        public static NPCContributor 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;

            NPCContributor e;

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

                string Name  = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sName).AsString();                 //NPCLevel2IGet_cs.txt
                string Title = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sTitle).AsString();                //NPCLevel2IGet_cs.txt
                byte[] ApproverScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sApproverScriptHash); //NPCLevel2IGet_cs.txt
                byte[] ReqPublicKey       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sReqPublicKey);       //NPCLevel2IGet_cs.txt
                if (NeoTrace.RUNTIME)
                {
                    TraceRuntime("Get(skey).e._name, e._title, e._approverScriptHash, e._reqPublicKey", e._name, e._title, e._approverScriptHash, e._reqPublicKey);                   // Template: NPCLevel2Part2_cs.txt
                }
                e._name  = Name; e._title = Title; e._approverScriptHash = ApproverScriptHash; e._reqPublicKey = ReqPublicKey;
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(skey).NPCContributor", e);
            }
            return(e);
        }
        public static NPCContributor 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);

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

                string Name  = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bName)).AsString();                 //NPCLevel2GGet_cs.txt
                string Title = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bTitle)).AsString();                //NPCLevel2GGet_cs.txt
                byte[] ApproverScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bApproverScriptHash)); //NPCLevel2GGet_cs.txt
                byte[] ReqPublicKey       = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bReqPublicKey));       //NPCLevel2GGet_cs.txt
                e._name  = Name; e._title = Title; e._approverScriptHash = ApproverScriptHash; e._reqPublicKey = ReqPublicKey;                        // Template: NPCLevel2HGet_cs.txt
                e._state = sta;
                e._state = NeoEntityModel.EntityState.GETTED;                                                                                         /* OVERRIDE */
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Get(bkey).NPCContributor", e);
            }
            return(e);
        }
示例#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>NPCContributor</returns>
        public static NPCContributor BuryElement(NeoVersionedAppUser vau, byte[] domain, byte[] bindex)
        {
            if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY?
            {
                return(NPCContributor.Null());
            }

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

            //byte[] bkey;
            NPCContributor e;

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

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

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

                Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bReqPublicKey), e._reqPublicKey);             // NPCLevel4EBuryElement_cs.txt
            } // Template: NPCLevel4Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(vau,i).NPCContributor", e);
            }
            return(e);
        }
        public static bool Put(NPCContributor 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, _bName), e._name);                             // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bTitle), e._title);                           // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bApproverScriptHash), e._approverScriptHash); // Template: NPCLevel2CPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bReqPublicKey), e._reqPublicKey);             // Template: NPCLevel2CPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(bkey).NPCContributor", e);                   // Template: NPCLevel2DPut_cs.txt
            }
            return(true);
        }
        public static bool Put(NPCContributor e, string key)
        {
            if (key.Length == 0)
            {
                return(false);
            }
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NPCContributor", 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 + _sName, e._name);                             // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sTitle, e._title);                           // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sApproverScriptHash, e._approverScriptHash); // Template: NPCLevel2EPut_cs.txt
            Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sReqPublicKey, e._reqPublicKey);             // Template: NPCLevel2EPut_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Put(skey).NPCContributor", e);                   // Template: NPCLevel2FGet_cs.txt
            }
            return(true);
        }
示例#16
0
        public static NPCContributor 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);

            NPCContributor e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, Helper.Concat(_bkeyTag, _bSTA));
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(bkey).bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = NPCContributor.Missing();
            }
            else // not MISSING - bury it
            {
                e = NPCContributor.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, _bName), e._name); // Template: NPCLevel3ABury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bTitle), e._title); // Template: NPCLevel3ABury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bApproverScriptHash), e._approverScriptHash); // Template: NPCLevel3ABury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, Helper.Concat(_bkeyTag, _bReqPublicKey), e._reqPublicKey); // Template: NPCLevel3ABury_cs.txt
            } // Template: NPCLevel3BBury_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(bkey).NPCContributor", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
示例#17
0
        public static NPCContributor 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;

            NPCContributor e;

            byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, _skeyTag + _sSTA);
            if (NeoTrace.RUNTIME)
            {
                TraceRuntime("Bury(skey).NPCContributor.bsta", bsta.Length, bsta);
            }
            if (bsta.Length == 0)
            {
                e = NPCContributor.Missing();
            }
            else // not MISSING - bury it
            {
                e = NPCContributor.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 + _sName, e._name); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sTitle, e._title); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sApproverScriptHash, e._approverScriptHash); // Template: NPCLevel3CBury_cs.txt
                //Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, _skeyTag + _sReqPublicKey, e._reqPublicKey); // Template: NPCLevel3CBury_cs.txt
            } // Template: NPCLevel3Part2_cs.txt
            if (NeoTrace.RUNTIME)
            {
                LogExt("Bury(skey).NPCContributor", e);
            }
            return(e); // return Entity e to signal if key is Missing or bad key
        }
示例#18
0
 // Deletable methods
 public static bool IsBuried(NPCContributor e)
 {
     return(e._state == NeoEntityModel.EntityState.TOMBSTONED);
 }
 public static void SetTitle(NPCContributor e, string value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._title = value; e._state = NeoEntityModel.EntityState.SET;
 }
 // Persistable methods
 public static bool IsMissing(NPCContributor e)
 {
     return(e._state == NeoEntityModel.EntityState.MISSING);
 }
示例#21
0
        public static object ProcessOperation(NeoVersionedAppUser AppVAU, NPCNEP5Base tokenBase, string operation, object[] args)
        {
            object result = false;

            if (NeoTrace.VERBOSE)
            {
                NeoTrace.Trace("operation", operation);
            }

            if (operation == "deploy")
            {
                result = deploy(tokenBase);
            }
            else if (operation == "ping")
            {
                result = ping();
            }

            else if (operation == "name")
            {
                result = name(tokenBase);
            }
            else if (operation == "symbol")
            {
                result = symbol(tokenBase);
            }
            else if (operation == "decimals")
            {
                result = decimals(tokenBase);
            }
            else if (operation == "totalSupply")
            {
                result = totalSupply(tokenBase);
            }
            else if (operation == "balanceOf")
            {
                byte[] account = (byte[])args[0];
                if (NeoTrace.TESTING && account[0] == 0x0) // DEBUGGING
                {
                    account = OwnerAccountScriptHash;
                    if (NeoTrace.VERBOSE)
                    {
                        NeoTrace.Trace("DEBUGGING:from", account);
                    }
                }
                result = balanceOf(account);
            }
            else if (operation == "transfer")
            {
                if (args.Length == 3)
                {
                    // https://github.com/neo-project/examples-csharp/blob/master/ICO_Template/ICO_Template.cs#L59
                    byte[]     from   = (byte[])args[0];
                    byte[]     to     = (byte[])args[1];
                    BigInteger amount = (BigInteger)args[2];
                    if (NeoTrace.TESTING && from[0] == 0x0) // DEBUGGING
                    {
                        from = OwnerAccountScriptHash;
                        if (NeoTrace.VERBOSE)
                        {
                            NeoTrace.Trace("DEBUGGING:from", from);
                        }
                    }
                    result = transfer(from, to, amount);
                }
            }
            else if (operation == "allowance")
            {
                byte[] from = (byte[])args[0];
                byte[] to   = (byte[])args[1];
                if (NeoTrace.TESTING && from[0] == 0x0) // DEBUGGING
                {
                    from = OwnerAccountScriptHash;
                    if (NeoTrace.VERBOSE)
                    {
                        NeoTrace.Trace("DEBUGGING:from", from);
                    }
                }
                result = allowance(from, to); // optional
            }
            else if (operation == "transferFrom")
            {
                byte[]     originator = OwnerAccountScriptHash;
                byte[]     from       = (byte[])args[0];
                byte[]     to         = (byte[])args[1];
                BigInteger amount     = (BigInteger)args[2];
                if (NeoTrace.TESTING && originator[0] == 0x0) // DEBUGGING
                {
                    originator = OwnerAccountScriptHash;
                    if (NeoTrace.VERBOSE)
                    {
                        NeoTrace.Trace("DEBUGGING:originator", originator);
                    }
                }
                result = transferFrom(originator, from, to, amount); // optional
            }
            else if (operation == "approve")
            {
                byte[]     originator = OwnerAccountScriptHash;
                byte[]     to         = (byte[])args[0];
                BigInteger amount     = (BigInteger)args[1];
                if (NeoTrace.TESTING && originator[0] == 0x0) // DEBUGGING
                {
                    originator = OwnerAccountScriptHash;
                    if (NeoTrace.VERBOSE)
                    {
                        NeoTrace.Trace("DEBUGGING:originator", originator);
                    }
                }
                result = approve(originator, to, amount); // optional
            }
            else if (operation == "createUser")
            {
                result = UserCredentials.CreateUser(AppVAU, args);
            }
            else if (operation == "getUser")
            {
                result = UserCredentials.GetUser(AppVAU, args);
            }
            //else if (operation == "getUsers")
            //{
            //    result = UserCredentials.GetUsers(AppVAU, args);
            //}
            else if (operation == "CreateContributor")
            {
                result = NPCContributor.CreateContributor(AppVAU, args);
            }
            else if (operation == "getContributor")
            {
                result = NPCContributor.GetContributor(AppVAU, args);
            }
            //else if (operation == "getContributors")
            //{
            //    result = NPCContributor.GetContributors(AppVAU, args);
            //}
            else if (operation == "createRequisition")
            {
                result = NPCNEP5Requisition.CreateRequisition(AppVAU, args);
            }
            else if (operation == "submitRequisition")
            {
                result = NPCNEP5Requisition.SubmitRequisition(AppVAU, args);
            }
            else if (operation == "getContributorRequisitions")
            {
                result = NPCNEP5Requisition.GetContributorRequisitions(AppVAU, args);
            }
            else if (operation == "updateRequisition")
            {
                result = NPCNEP5Requisition.UpdateRequisition(AppVAU, args);
            }
            else if (operation == "payRequisition")
            {
                result = NPCNEP5Requisition.PayRequisition(AppVAU, args);
            }
            else
            {
                if (NeoTrace.INFO)
                {
                    NeoTrace.Trace("Unknown operation", operation);
                }
                string message = "unknown operation '" + operation + "'";
                if (NeoTrace.ERROR)
                {
                    NeoTrace.Trace("**ERROR** operation", message);
                }
                result = false;
            }

            if (NeoTrace.VERBOSE)
            {
                NeoTrace.Trace("result", result);
            }

            return(result);
        }
 public static string GetTitle(NPCContributor e)
 {
     return(e._title);
 }
 public static string GetName(NPCContributor e)
 {
     return(e._name);
 }
 public static void Set(NPCContributor e, string Name, string Title, byte[] ApproverScriptHash, byte[] ReqPublicKey) // Template: NPCLevel1Set_cs.txt
 {
     e._name = Name; e._title = Title; e._approverScriptHash = ApproverScriptHash; e._reqPublicKey = ReqPublicKey;  e._state = NeoEntityModel.EntityState.SET;
 }
 public static byte[] GetReqPublicKey(NPCContributor e)
 {
     return(e._reqPublicKey);
 }
 public static void SetReqPublicKey(NPCContributor e, byte[] value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._reqPublicKey = value; e._state = NeoEntityModel.EntityState.SET;
 }
 // EntityState wrapper methods
 public static bool IsNull(NPCContributor e)
 {
     return(e._state == NeoEntityModel.EntityState.NULL);
 }
 public static void SetApproverScriptHash(NPCContributor e, byte[] value) // Template: NPCLevel1SetXGetX_cs.txt
 {
     e._approverScriptHash = value; e._state = NeoEntityModel.EntityState.SET;
 }
 public static byte[] GetApproverScriptHash(NPCContributor e)
 {
     return(e._approverScriptHash);
 }
 public static void LogExt(string label, NPCContributor e)
 {
     TraceRuntime(label, e._name, e._title, e._approverScriptHash, e._reqPublicKey, e._state);
 }