The sample contract serves as a demonstration of general QVM logic.
It is capable of:
registering users into the database
storing the last registered user's name in the database
echoing the previous user's name to STDOUT
incrementing the total registered user count
storing above counter in the database
Sample code
usingSystem;publicclassContract{privatestaticStringgetEnv(String key,String deft) {String? val =Environment.GetEnvironmentVariable(key);if (val ==null||val.Length==0) {return deft; }return val; }privatestaticintatoi(String val) {try {returnInt32.Parse(val); }catch (FormatException) {return0; } }publicstaticintMain(String[] args) { // THIS SAMPLE ONLY SUPPORTS THE "register" FUNCTIONif (args.Length==2&&args[0] =="register") { // GET THE CURRENT USER'S NAME OR DEFAULT TO "unknown" IF THIS IS THE FIRST CALLString? previousName =getEnv("DB_USER_CURRENT","unknown"); // GET THE TOTAL USER COUNTint totalUserCount =atoi(getEnv("DB_TOTALUSERS","0")); // WRITE PREVIOUS USER NAME TO STDOUTConsole.Out.WriteLine($"OUT=prevname: {previousName}"); // UPDATE CURRENT USER NAME BY WRITING IT TO DBConsole.Out.WriteLine($"DBW=USER_CURRENT={args[1]}"); // STORE USER NAME UNDER A STORAGE SLOT FOR PERSISTENCE (CURRENT GETS OVERWRITTEN ON EACH CALL)Console.Out.WriteLine($"DBW=USER_{totalUserCount}={args[1]}"); // INCREMENT THE TOTAL USER COUNTConsole.Out.WriteLine($"DBW=TOTALUSERS={totalUserCount+1}");return0; }if (args.Length>=1) {Console.Error.WriteLine("Wrong CMD: "+args[0]);return1; }Console.Error.WriteLine("Wrong args!");return1; }}
Save the contract
Open a text editor and save above sample contract as main.cs file.