Skip to content

Commit

Permalink
Workarounds created.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurigabrich committed Jun 15, 2020
1 parent 0d7ea95 commit d341d6d
Showing 1 changed file with 74 additions and 28 deletions.
102 changes: 74 additions & 28 deletions neo-dapp/microgrid-dapp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ public static object Main ( byte[] address, string operation, params object[] ar
(string)args[1] ); // utility
}

if ( operation == "admission war" )
{
return RefWar( (string)args[2], // rID
(string)args[0], // fullName
(string)args[1], // utility
address ); // invoker/caller address
}

// Partially restricted operation.
if ( operation == "summary" )
{
Expand Down Expand Up @@ -290,6 +298,15 @@ public static object Main ( byte[] address, string operation, params object[] ar
opt ); // array with desired values
}

if ( operation == "change war" )
{
return RefWar( (string)args[2], // rID
"Change register_", // proposal
(string)args[0], // register variable = "quota"
address, // member ID
(int)args[1] ); // new quota value
}

if ( operation == "power up" )
{
if ( args.Length != 4 )
Expand Down Expand Up @@ -339,6 +356,11 @@ public static object Main ( byte[] address, string operation, params object[] ar
return AdmissionResult( (string)args[0] ); // Referendum ID
}

if ( operation == "admission result war" )
{
return AdmissionResultWar( (string)args[0] ); // Referendum ID
}

if ( operation == "change result" )
{
if ( args.Length != 1 )
Expand Down Expand Up @@ -642,16 +664,18 @@ private static bool AdmissionResult( string rID )

// Retrives the address from private storage.
byte[] address = (byte[])GetRef(rID, "address");

if ( Str2Bool( (string)GetRef(rID, "outcome") ) )
{
// Retrives the member data from private storage.
string fullName = (string)GetRef(rID, "proposal");
string utility = (string)GetRef(rID, "notes");

// string fullName = (string)GetRef(rID, "proposal");
// string utility = (string)GetRef(rID, "notes");
// Adds a new member after the group approval.
Member( address, fullName, utility, 0, 0 );
Membership( address, "Welcome on board!" );
// Member( address, fullName, utility, 0, 0 );
// Membership( address, "Welcome on board!" );

// Wait for the second step.
return true;
}

Expand All @@ -660,6 +684,21 @@ private static bool AdmissionResult( string rID )
DelMemb( address );
return false;
}

private static bool AdmissionResultWar( string rID )
{
// Retrives the address from private storage.
byte[] address = (byte[])GetRef(rID, "address");

// Retrives the member data from private storage.
string fullName = (string)GetRef(rID, "proposal");
string utility = (string)GetRef(rID, "notes");

// Adds a new member after the group approval.
Member( address, fullName, utility, 0, 0 );
Membership( address, "Welcome on board!" );
return true;
}

private static bool ChangeResult( string rID )
{
Expand Down Expand Up @@ -1417,35 +1456,42 @@ private static void DelPP( string ppID )
private static string Ref( string proposal, string notes, byte[] address, int cost = 0, uint time = 0 )
{
string id = ID( "\x5A", true, new string[] {proposal, notes, Int2Str(cost)} );

// Workaround!

// Notifies about the creation of the referendum ID.
Process(id, "The referendum process has started.");
return id;
}

private static bool RefWar( string rID, string proposal, string notes, byte[] address, int cost = 0, uint time = 0 )
{
// Stores the practical values.
RefData.Proposal.Put(id, proposal);
RefData.Notes.Put(id, notes);
RefData.Outcome.Put(id, Bool2Str(false));
RefData.StartTime.Put(id, InvokedTime());
RefData.EndTime.Put(id, InvokedTime() + timeFrameRef);

RefData.Proposal.Put(rID, proposal);
RefData.Notes.Put(rID, notes);
RefData.Outcome.Put(rID, Bool2Str(false));
RefData.StartTime.Put(rID, InvokedTime());
RefData.EndTime.Put(rID, InvokedTime() + timeFrameRef);
// Evaluates the values before stores them since it is expensive to store null values.
if ( address.Length != 0 ) RefData.Address.Put(id, address);
if ( cost != 0 ) RefData.Cost.Put(id, cost);
if ( time != 0 ) RefData.Time.Put(id, time);
if ( address.Length != 0 ) RefData.Address.Put(rID, address);
if ( cost != 0 ) RefData.Cost.Put(rID, cost);
if ( time != 0 ) RefData.Time.Put(rID, time);

// Just states the other values since it is expensive to store null values.
// RefData.MoneyRaised.Put(id, 0);
// RefData.NumOfVotes.Put(id, 0);
// RefData.CountTrue.Put(id, 0);
// RefData.HasResult.Put(id, 0);
// RefData.MoneyRaised.Put(rID, 0);
// RefData.NumOfVotes.Put(rID, 0);
// RefData.CountTrue.Put(rID, 0);
// RefData.HasResult.Put(rID, 0);

// Increases the total number of referendum processes.
BigInteger temp = NumOfRef()+1;
Storage.Put("numofref", temp);
// Increases the total number of referendum processes. (limited by the number of operations, max. 6)
// BigInteger temp = NumOfRef()+1;
// Storage.Put("numofref", temp);

// Stores the ID of each referendum.
RefData.ID.Put( Int2Str((int)temp), id );

// Notifies about the creation of the referendum ID.
Process(id, "The referendum process has started.");
return id;
// Stores the ID of each referendum. (limited by the number of operations, max. 6)
// RefData.ID.Put( Int2Str((int)temp), rID );

return true;
}

// The function to vote on a referendum is declared above.
Expand Down

0 comments on commit d341d6d

Please sign in to comment.