public static NPCNEP5Requisition[] GetContributorRequisitions(NeoVersionedAppUser AppVAU, object[] args) { NPCNEP5Requisition[] results = { NPCNEP5Requisition.Null() }; byte[] encodedRequisitionName = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("GetRequisition.encodedRequisitionName", encodedRequisitionName); } NPCNEP5Requisition uc = FindRequisition(AppVAU, encodedRequisitionName); if (NeoTrace.INFO) { NPCNEP5Requisition.LogExt("GetRequisition.uc", uc); } results[0] = uc; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("GetRequisition.results", results); } return(results); }
// Use case example: domain = user script hash, counter = NeoCounters.UserPointsCounter public static BigInteger TakeNextNumber(NeoVersionedAppUser vau, byte[] domain, NeoCounters counter) { NeoCounter nc = NeoCounter.GetElement(vau, domain, (int)counter); // Get persisted counter value NeoCounter.LogExt("TakeNextNumber", nc); if (NeoCounter.IsMissing(nc)) { nc = NeoCounter.New(); // Create a new counter value } else // Get and increment counter value by 1 { BigInteger newNumber = NeoCounter.GetCurrentNumber(nc); NeoTrace.Trace("newNumber", newNumber); newNumber = newNumber + 1; NeoTrace.Trace("newNumber", newNumber); NeoCounter.SetCurrentNumber(nc, newNumber); NeoCounter.LogExt("TakeNextNumber", nc); } NeoCounter.PutElement(nc, vau, DOMAINAC, (int)counter); // Persist the incremented current value of the counter NeoCounter.LogExt("TakeNextNumber", nc); return(NeoCounter.GetCurrentNumber(nc)); }
/// <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>NeoCounter</returns> public static NeoCounter BuryElement(NeoVersionedAppUser vau, byte[] domain, int index) { if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY? { return(NeoCounter.Null()); } Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext; NeoStorageKey nsk = NeoStorageKey.New(vau, domain, _bClassName); //byte[] bkey; NeoCounter e; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Bury(vau,index).NeoCounter.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = NeoCounter.Missing(); } else // not MISSING - bury it { e = NeoCounter.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, index, _bSTA), e._state.AsBigInteger()); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bCurrentNumber), e._currentNumber); // NPCLevel4EBuryElement_cs.txt } // Template: NPCLevel4Part2_cs.txt if (NeoTrace.RUNTIME) { LogExt("Bury(vau,i).NeoCounter", e); } return(e); }
/// <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>UserCredentials</returns> public static UserCredentials BuryElement(NeoVersionedAppUser vau, string domain, byte[] bindex) { if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY? { return(UserCredentials.Null()); } Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext; NeoStorageKey nsk = NeoStorageKey.New(vau, domain, "UserCredentials"); byte[] bkey; UserCredentials e; /*STA*/ byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, bindex, _bSTA)); NeoTrace.Trace("Bury(vau,index).UserCredentials.bsta", bsta.Length, bsta); if (bsta.Length == 0) { e = UserCredentials.Missing(); } else // not MISSING - bury it { e = UserCredentials.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, bkey = NeoStorageKey.StorageKey(nsk, bindex, _bSTA), e._state.AsBigInteger()); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, bindex, _bEncodedUsername), e._encodedUsername); // NPCLevel4EBuryElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, bindex, _bEncodedPassword), e._encodedPassword); // NPCLevel4EBuryElement_cs.txt } // Template: NPCLevel4Part2_cs.txt LogExt("Bury(vau,i).UserCredentials", e); return(e); }
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); }
/// <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(NPCNEP5Requisition 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, _bFromScriptHash), e._fromScriptHash); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bToScriptHash), e._toScriptHash); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bEncryptedBlobURI), e._encryptedBlobURI); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bWorkflowState), e._workflowState); // Template: NPCLevel4APutElement_cs.txt if (NeoTrace.RUNTIME) { LogExt("PutElement(vau,i).NPCNEP5Requisition", e); // Template: NPCLevel4BGetElement_cs.txt } return(true); }
private static object[] UserGetSingle(NeoVersionedAppUser AppVAU, object[] args) { object[] results = { -1 }; byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("UserGetSingle.encodedUsername", encodedUsername); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (NeoTrace.INFO) { UserCredentials.LogExt("UserGetSingle.uc", uc); } results = new object[] { uc }; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("UserGetSingle.results", results); } return(results); }
public static UserCredentials GetUser(NeoVersionedAppUser AppVAU, object[] args) { UserCredentials results = UserCredentials.Null(); byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("GetUser.encodedUsername", encodedUsername); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (NeoTrace.INFO) { UserCredentials.LogExt("GetUser.uc", uc); } results = uc; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("GetUser.results", results); } return(results); }
public static object Main(string operation, params object[] args) { object result = false; NeoVersionedAppUser AppVAU = NeoVersionedAppUser.New("NPC.mwherman2000.NeoExpenses1.Contract", 1, 1, 1, "7074acf3f06dd3f456e11053ebf61c5b04b07ebc".AsByteArray()); // DEBUG ONLY if (NeoTrace.TESTING) { NeoVersionedAppUser.LogExt("AppVAU", AppVAU); } NPCNEP5Base tokenBase = NPCNEP5Base.New("My Meetup Token", "MMT", 8, 1000000); if (NeoTrace.VERBOSE) { NPCNEP5Base.Log("tokenBase", tokenBase); } result = ProcessOperation(AppVAU, tokenBase, operation, args); if (NeoTrace.VERBOSE) { NeoTrace.Trace("result", result); } return(result); }
/// <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(MeetupAttendee e, NeoVersionedAppUser vau, byte[] domain, int index) { 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, index, _bSTA), e._state.AsBigInteger()); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeName), e._attendeeName); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeID), e._attendeeID); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeUrl), e._attendeeUrl); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeePhotoUrl), e._attendeePhotoUrl); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bMeetingID), e._meetingID); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bMeetingUrl), e._meetingUrl); // Template: NPCLevel4APutElement_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttended), e._attended); // Template: NPCLevel4APutElement_cs.txt if (NeoTrace.RUNTIME) { LogExt("PutElement(vau,i).MeetupAttendee", e); // Template: NPCLevel4BGetElement_cs.txt } return(true); }
/// <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(Point 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).Point.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, _bX), e._x); // Template: NPCLevel4APutElementExt2_cs.txt Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bY), e._y); // Template: NPCLevel4APutElementExt2_cs.txt if (NeoTrace.RUNTIME) { LogExt("PutElement(vau,i).Point", e); // Template: NPCLevel4BGetElement_cs.txt } return(true); }
/// <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); }
/// <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>Point</returns> public static Point BuryElement(NeoVersionedAppUser vau, int index) { if (NeoVersionedAppUser.IsNull(vau)) // TODO - create NeoEntityModel.EntityState.BADKEY? { return(Point.Null()); } Neo.SmartContract.Framework.Services.Neo.StorageContext ctx = Neo.SmartContract.Framework.Services.Neo.Storage.CurrentContext; NeoStorageKey nsk = NeoStorageKey.New(vau, "Point"); byte[] bkey; Point p; /*STA*/ byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bSTA)); NeoTrace.Trace("Bury(vau,index).bs", bsta.Length, bsta); if (bsta.Length == 0) { p = Point.Missing(); } else // not MISSING - bury it { p = Point.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, bkey = NeoStorageKey.StorageKey(nsk, index, _bSTA), p._state.AsBigInteger()); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bX), p._x); Neo.SmartContract.Framework.Services.Neo.Storage.Put(ctx, bkey = NeoStorageKey.StorageKey(nsk, index, _bY), p._y); } LogExt("Bury(vau,i).p", p); return(p); }
/// <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>MeetupAttendee</returns> public static MeetupAttendee GetElement(NeoVersionedAppUser vau, byte[] domain, int index) { 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); MeetupAttendee e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).MeetupAttendee.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = MeetupAttendee.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = MeetupAttendee.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new MeetupAttendee(); string AttendeeName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeName)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string AttendeeID = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeID)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string AttendeeUrl = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeeUrl)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string AttendeePhotoUrl = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttendeePhotoUrl)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string MeetingID = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bMeetingID)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string MeetingUrl = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bMeetingUrl)).AsString(); // Template: NPCLevel4CGetElement_cs.txt BigInteger Attended = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bAttended)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt e._attendeeName = AttendeeName; e._attendeeID = AttendeeID; e._attendeeUrl = AttendeeUrl; e._attendeePhotoUrl = AttendeePhotoUrl; e._meetingID = MeetingID; e._meetingUrl = MeetingUrl; e._attended = Attended; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).MeetupAttendee.e", e); } return(e); }
private static object[] PointGetAll(NeoVersionedAppUser AppVAU, object[] args) { object[] results = { -1 }; byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("PointGetAll.encodedUsername", encodedUsername); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (UserCredentials.IsMissing(uc)) { if (NeoTrace.INFO) { UserCredentials.LogExt("PointGetAll.user missing", uc); } } else { if (NeoTrace.INFO) { UserCredentials.LogExt("PointGetAll.user exists", uc); } BigInteger nPoints = NeoCounter.GetCurrentNextNumber(AppVAU, encodedUsername, NeoCounters.UserPointsCounter); if (NeoTrace.INFO) { NeoTrace.Trace("PointGetAll.nPoints", nPoints); } UserPoint[] points = new UserPoint[(int)nPoints]; for (int index = 0; index < nPoints; index++) { if (NeoTrace.INFO) { NeoTrace.Trace("PointGetAll.index", index); } UserPoint up = UserPoint.GetElement(AppVAU, encodedUsername, (int)index); if (NeoTrace.INFO) { UserPoint.LogExt("PointGetAll.up", up); } points[index] = up; } results = points; } if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("PointGetAll.results", results); } return(results); }
/// <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>NPCNEP5Requisition</returns> public static NPCNEP5Requisition 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); NPCNEP5Requisition e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).NPCNEP5Requisition.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = NPCNEP5Requisition.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = NPCNEP5Requisition.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new NPCNEP5Requisition(); byte[] FromScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bFromScriptHash)); // Template: NPCLevel4CGetElement_cs.txt byte[] ToScriptHash = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bToScriptHash)); // Template: NPCLevel4CGetElement_cs.txt string EncryptedBlobURI = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bEncryptedBlobURI)).AsString(); // Template: NPCLevel4CGetElement_cs.txt Int32 WorkflowState = (Int32)Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bWorkflowState)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt e._fromScriptHash = FromScriptHash; e._toScriptHash = ToScriptHash; e._encryptedBlobURI = EncryptedBlobURI; e._workflowState = WorkflowState; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).NPCNEP5Requisition.e", e); } return(e); }
/// <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); }
public static BigInteger GetNextNumber(NeoVersionedAppUser vau, byte[] domain, NeoCounters counter) { BigInteger result = -1; NeoCounter nc = NeoCounter.GetElement(vau, domain, (int)counter); // Get persisted counter value if (!NeoCounter.IsMissing(nc)) { result = NeoCounter.GetCurrentNumber(nc); } return(result); // Return the current value for this counter }
/// <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>NFT</returns> public static NFT GetElement(NeoVersionedAppUser vau, byte[] domain, int index) { 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); NFT e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).NFT.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = NFT.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = NFT.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new NFT(); string Uri = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bUri)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string FirstName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bFirstName)).AsString(); // Template: NPCLevel4CGetElement_cs.txt string LastName = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bLastName)).AsString(); // Template: NPCLevel4CGetElement_cs.txt e._uri = Uri; e._firstName = FirstName; e._lastName = LastName; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).NFT.e", e); } return(e); }
/// <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); }
/// <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>Point</returns> public static Point 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); Point e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).Point.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = Point.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = Point.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new Point(); BigInteger X = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bX)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt BigInteger Y = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, bindex, _bY)).AsBigInteger(); // Template: NPCLevel4CGetElement_cs.txt e._x = X; e._y = Y; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).Point.e", e); } return(e); }
// 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.VERBOSE) { NeoCounter.LogExt("TakeNextNumber", nc); } if (NeoCounter.IsMissing(nc)) // Create persist the new counter entity { if (NeoTrace.VERBOSE) { NeoCounter.LogExt("TakeNextNumber.domain and counter is missing", nc); } nc = NeoCounter.New(); // Create a new counter entity if (NeoTrace.VERBOSE) { NeoCounter.LogExt("TakeNextNumber.putnew", nc); } NeoCounter.PutElement(nc, vau, domain, (int)counter); // Persist the new counter entity with a value of zero } if (NeoTrace.VERBOSE) { NeoCounter.LogExt("TakeNextNumber.exists", nc); } BigInteger currentNextNumber = NeoCounter.GetCurrentNumber(nc); if (NeoTrace.VERBOSE) { NeoTraceRuntime.TraceRuntime("currentNextNumber", currentNextNumber); } BigInteger newNextNumber = currentNextNumber + 1; if (NeoTrace.VERBOSE) { NeoTraceRuntime.TraceRuntime("nextNumber", newNextNumber); } NeoCounter.SetCurrentNumber(nc, newNextNumber); if (NeoTrace.VERBOSE) { NeoCounter.LogExt("TakeNextNumber.putincr", nc); } NeoCounter.PutElement(nc, vau, domain, (int)counter); // Persist the new counter return(currentNextNumber); }
/// <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>UserCredentials</returns> public static UserCredentials GetElement(NeoVersionedAppUser vau, byte[] domain, int index) { 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); UserCredentials e; //byte[] bkey; byte[] bsta = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bSTA)); if (NeoTrace.RUNTIME) { TraceRuntime("Get(bkey).UserCredentials.bsta", bsta.Length, bsta); } if (bsta.Length == 0) { e = UserCredentials.Missing(); } else // not MISSING { int ista = (int)bsta.AsBigInteger(); NeoEntityModel.EntityState sta = (NeoEntityModel.EntityState)ista; if (sta == NeoEntityModel.EntityState.TOMBSTONED) { e = UserCredentials.Tombstone(); } else // not MISSING && not TOMBSTONED { e = new UserCredentials(); byte[] EncodedUsername = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bEncodedUsername)); // Template: NPCLevel4CGetElement_cs.txt byte[] EncodedPassword = Neo.SmartContract.Framework.Services.Neo.Storage.Get(ctx, NeoStorageKey.StorageKey(nsk, index, _bEncodedPassword)); // Template: NPCLevel4CGetElement_cs.txt e._encodedUsername = EncodedUsername; e._encodedPassword = EncodedPassword; // NPCLevel4DBuryElement_cs.txt e._state = sta; e._state = NeoEntityModel.EntityState.GETTED; /* OVERRIDE */ } } if (NeoTrace.RUNTIME) { LogExt("Get(bkey).UserCredentials.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); }
private static NPCNEP5Requisition FindRequisition(NeoVersionedAppUser AppVAU, byte[] encodedRequisitionName) { if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("FindRequisition.encodedRequisitionName", encodedRequisitionName); } NPCNEP5Requisition result = NPCNEP5Requisition.GetElement(AppVAU, DOMAINNEP5REQ, encodedRequisitionName); if (NeoTrace.ARGSRESULTS) { NPCNEP5Requisition.LogExt("FindRequisition.result", result); } return(result); }
private static UserCredentials FindUser(NeoVersionedAppUser AppVAU, byte[] encodedUsername) { if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("FindUser.encodedUsername", encodedUsername); } UserCredentials result = UserCredentials.GetElement(AppVAU, DOMAINUCD, encodedUsername); if (NeoTrace.ARGSRESULTS) { UserCredentials.LogExt("FindUser.result", result); } return(result); }
public static NPCNEP5Requisition SubmitRequisition(NeoVersionedAppUser AppVAU, object[] args) { NPCNEP5Requisition results = NPCNEP5Requisition.Null(); byte[] encodedRequisitionName = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddRequisition.encodedRequisitionName", encodedRequisitionName); } byte[] encodedPassword = (byte[])args[1]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddRequisition.encodedPassword", encodedPassword); } NPCNEP5Requisition uc = FindRequisition(AppVAU, encodedRequisitionName); if (NPCNEP5Requisition.IsMissing(uc)) // add the unique new user { if (NeoTrace.INFO) { NPCNEP5Requisition.LogExt("AddRequisition.missing", uc); } uc = NPCNEP5Requisition.New(encodedRequisitionName, encodedPassword); NPCNEP5Requisition.PutElement(uc, AppVAU, DOMAINNEP5REQ, encodedRequisitionName); if (NeoTrace.INFO) { NPCNEP5Requisition.LogExt("AddRequisition.added", uc); } } else { if (NeoTrace.INFO) { NPCNEP5Requisition.LogExt("AddRequisition.exists", uc); } } results = uc; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddRequisition.results", results); } return(results); }
private static object[] UserAdd(NeoVersionedAppUser AppVAU, object[] args) { object[] results = { -1 }; byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("UserAdd.encodedUsername", encodedUsername); } byte[] encodedPassword = (byte[])args[1]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("UserAdd.encodedPassword", encodedPassword); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (UserCredentials.IsMissing(uc)) // add the unique new user { if (NeoTrace.INFO) { UserCredentials.LogExt("UserAdd.missing", uc); } uc = UserCredentials.New(encodedUsername, encodedPassword); UserCredentials.PutElement(uc, AppVAU, DOMAINUCD, encodedUsername); if (NeoTrace.INFO) { UserCredentials.LogExt("UserAdd.added", uc); } } else { if (NeoTrace.INFO) { UserCredentials.LogExt("UserAdd.exists", uc); } } results = new object[] { uc }; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("UserAdd.results", results); } return(results); }
private static object[] PointDeleteLast(NeoVersionedAppUser AppVAU, object[] args) { object[] results = { -1 }; if (NeoTrace.INFO) { NeoVersionedAppUser.LogExt("PointDeleteLast.AppVAU", AppVAU); } byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("PointDeleteLast.encodedUsername", encodedUsername); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (UserCredentials.IsMissing(uc)) { if (NeoTrace.INFO) { UserCredentials.LogExt("PointDeleteLast.user missing", uc); } } else { if (NeoTrace.INFO) { UserCredentials.LogExt("PointDeleteLast.user exists", uc); } BigInteger nPoints = NeoCounter.GiveBackLastNumber(AppVAU, encodedUsername, NeoCounters.UserPointsCounter); if (NeoTrace.INFO) { NeoTrace.Trace("PointDeleteLast.nPoints", nPoints); } results = new object[] { nPoints }; } if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("PointDeleteLast.results", results); } return(results); }
static readonly byte[] DOMAINUCD = "UCD".AsByteArray(); // User Credentials Directory (UCD) public static UserCredentials CreateUser(NeoVersionedAppUser AppVAU, object[] args) { UserCredentials results = UserCredentials.Null(); byte[] encodedUsername = (byte[])args[0]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddUser.encodedUsername", encodedUsername); } byte[] encodedPassword = (byte[])args[1]; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddUser.encodedPassword", encodedPassword); } UserCredentials uc = FindUser(AppVAU, encodedUsername); if (UserCredentials.IsMissing(uc)) // add the unique new user { if (NeoTrace.INFO) { UserCredentials.LogExt("AddUser.missing", uc); } uc = UserCredentials.New(encodedUsername, encodedPassword); UserCredentials.PutElement(uc, AppVAU, DOMAINUCD, encodedUsername); if (NeoTrace.INFO) { UserCredentials.LogExt("AddUser.added", uc); } } else { if (NeoTrace.INFO) { UserCredentials.LogExt("AddUser.exists", uc); } } results = uc; if (NeoTrace.ARGSRESULTS) { NeoTrace.Trace("AddUser.results", results); } return(results); }