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);
        }
        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);
        }
Exemple #3
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);
        }