Code Monkey home page Code Monkey logo

microgrid-dapp's Introduction

Microgrid Transactive Energy Smart Contract

The microgrid concept stands for the integration of distributed generation (DG) of electricity in an existing mid/low voltage power grid infrastructure. The size fo the microgrid is measured by its power generation capacity, and it can also have other nomenclatures due to this specification, such as mini-grid or nanogrid. Independently of its size, it may operate disconnected from the main grid as well. Either to feed the local point of generation or nearby points of power consumption.

However, the upcoming growth of DGs and the efficiency improvements on distributed energy resources (DER) have giving room to a new approach of the energy market for mid/low voltage power consumers. An opportunity to choose the energy source provider beyond the distribution utility, in other words, flexibility to choose upon energy type and different electricity prices. Unfortunately, proper coordination between this market and the current electric grid operation is a huge challenge.

The transactive energy (TE) is the concept looking to solve this issue. The objective is to have a system to better integrate DERs, to provide transparent energy prices, and to allow consumers of all sizes to trade energy without compromise the quality and reliability of the main electricity grid.

A one-size-fits-all solution is impracticable but blockchain comes in on good rescue. Although electric specifications of the distribution grid are almost the same worldwide, the electric sector directives might follow local energy capacity and potential, economic ambitions and mid-/long-term planning of the govern. This way several blockchain solutions are being developed under the aforementioned requirements.

The current Microgrid Transactive Energy Smart Contract is the result of a master degree on the look for a solution to implement the TE in the Brazilian micro/mini-grid context through a blockchain application. The thesis is also available online at the digital library of UERJ, at the UFRJ GESEL repository, and at the Bibliotecas da Energia's collection. The smart contract developed is only a small step towards a full micro/mini-grid distributed application (Dapp) but enough to assist the power exchange between consumers and prosumers (producers + consumers) through a transparent and secure management platform.

Smart Contract

The current project was designed for interacting with the NEO Blockchain and can be tested online with NeoCompiler Eco at the EcoLab. The C# algorithm implementation is on the folder neo-dapp under the file microgrid-dapp.cs.

As additional language implementations are expected, on the folder pseudo-code can be found generic flowcharts and information of the proposed system, (initially) echoed from the thesis.

Open source license

This project is shared under the MIT License attribution.

SPDX-License-Identifier: MIT License

Contributing guidelines

You're welcome to contribute to the project development! I'm still a newbie on code collaboration but the following Code of Conduct adapted from the Contributor Covenant looks fair for this project. Take a look at it and let's work together. 😎

microgrid-dapp's People

Contributors

dependabot[bot] avatar vncoelho avatar yurigabrich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

microgrid-dapp's Issues

The differences between ID's are still wrong

The crucial classification between ID's created by the MTEsm and by NEO blockchain can be set by the type of the variable. While the former is defined as string, the latter is byte[].
However, they can be easily interchangeable when the variable is passed as object, and all the evaluations defined so far does not reach a good outcome.

For instance, the current method to distinguish them (box code below) considers the input variable object as type string, and checks the first letter of the variable. So, if the member address APLJBPhtRg2XLhtpxEHd6aRNL7YSLGH2ZL is correctly invoked, i.e., the variable is passed on the Main() as a scripthash equal to 52eaab8b2aab608902c651912db34de36e7a2b0f, the function evaluates the hash as Rê«�*«`��ÆQ�-³Mãnz+�. Consequently, the result is wrong.

private static bool IsValidId( object id )
{
return ( (((string)id)[0] == 'P') || (((string)id)[0] == 'R') );
}

Other alternative is to evaluate the size of the variable. Such as the commit b44cd74 has tried to do (reproduced below).
Again, the output may be wrong, since a variable like RT9vtMQDGVS5uKFD4bLLChXEKAcPLh, which corresponds to a referendum ID (i.e. a string), could be evaluated as a byte[] with scripthash equal to aa49805a44e08e67c0c5f92da3d21fdbba829416, and then the size of the variable will be 20 too.

private static object Summary( object id, string opt = "" )
{
// If 'id' is a 'byte[]' == member.
if ( ((byte[])id).Length == 20 )

private static object Change( object id, params object[] opts )
{
// A referendum must start in case the change needs group's consensus.
string rID;
// If 'id' is a 'byte[]' == member.
if ( ((byte[])id).Length == 20 )

With this in mind, what the main difference between this variables?

Fix all the --PENDING--

The code still have a lot of minor bugs and decisions waiting to be fixed. At commit ecd4b01 there are 25 --PENDING-- "tags". The list below tracks all of them accordingly with different scopes:

Business subjects

  • :53 Define the factor between 1kW and 1SEB. And then, review at PowerUP() last operations if its right (pay attention to units).
  • :935 Review calculation of 'tokens' (pay attention to units).
  • :938 Review calculation of 'quota' (pay attention to units).
  • :1319 When refunding a member, the Trade() unit is SEB or R$? Is there missing some more operation?
  • :1326 Why delete a crowdfunding process data when its not succeeded? Why not keep this information?

NEO API feature

  • :62 How to identify the smart contract caller?
  • :112 Dependent on the caller address.

Lack of expertise on coding

  • :77 How to guarantee to the first contract invoker (the contract owner) to automatically be the first member? How to allow this operation to happen only once?
  • :95 CheckWitness requires a variable of type byte[] but members' address are being registered as string.
  • :128 CheckWitness requires a variable of type byte[] but members' address are being registered as string.
  • :144 CheckWitness requires a variable of type byte[] but members' address are being registered as string.
  • :169 CheckWitness requires a variable of type byte[] but members' address are being registered as string.
  • :306 Review dataset of each 'key' after the modifications made on the storage configuration. 'Key' is of type string and might represent the ID of a member, a PP or a Referendum.
  • :834 Should split the variable 'notes' to get further information.

Missing code validation

  • :231 Test second argument of Change() because of its length (array of arrays).
  • :712 Test variable convertion.
  • :714 Test variable convertion.
  • :753 Something to review when updating a member registration data. ("missing dependency"?)
  • :793 Something to review when updating a PP data. ("missing dependency"?)
  • :1048 Review how to definitely remove a member data from the private storage.
  • :1160 Review how to definitely remove a PP data from the private storage.
  • :1193 Review what variable type is returned from GetRef(). byte[] or object? This influences on other operations along the smart contract.
  • :1251Review what variable type is returned from UpCrowd(). byte[] or object? This influences on other operations along the smart contract.
  • :1257 Review what variable type is returned from UpBid(). Should it return something?
  • :1271 Still missing to update other 'crowd' values (!?) when doing a UpBid().

Review the definition of 'private' and 'public' functions and variables

The NeoCompiler automatic identifies all the functions and variables defined as public and displays an invoke option to it following the order they appear on the algorithm.

However, how can it confuse a user to select the right operation described on the smart contract through the Main?

The dual behaviour of an 'Address'

  1. May an address be differently invoked depending on the function used? In other words, sometimes the variable is passed as a byte[] (hexstring), and sometimes as string(Base58).
    Does it hurt usability?

  2. How can I use the CheckWitness and evaluate if the address is a member at the same time?

if ( (((string)args[1])[0] != 'A') || (((string)args[1]).Length == 0) )
throw new InvalidOperationException("Provide a valid destiny address.");

  1. May I use the dual behaviour of an Address at the same invoke function with a conversion such as .AsByteArray()? Or an explicit conversion like the below is enough?

if ( (((string)args[1])[0] != 'A') || (((string)args[1]).Length == 0) )
throw new InvalidOperationException("Provide a valid destiny address.");
if ( GetMemb((byte[])args[1]).AsString().Length != 0 )
throw new InvalidOperationException("The address you are transaction to must be a member too.");

Evaluate "object" as "string"

All the statements made so far that use the operator is to evaluate a string against an object are wrong, since is evaluates if one variable can be converted to the other (ref). Therefore all the clauses must be rewrote to keep the algorithm behaviour reliable.

In total, there are 6 cases concerning this, and all of them share the attribute of testing an object "id". In summary, they can be found at:

  1. Discern PPid (string) and address (byte[]). operation option change

    if ( (args[0] is string) & (((string)args[0])[0] == 'P') ) // Should be a PP ID.

  2. Discern the change of a bid (BigInteger) to other PP change operations (string) operation option change

    if ( !(opt[0] is string) )

  3. Discern PPid (string), Refid (string) and address (byte[]) function Summary()

    if (!(id is string))

  4. Discern PPid (string) and address (byte[]) function Change()

    if (!(id is string))

  5. To limit the change of a member profile data (string, up to personal decision) to a member registration data (BigInteger, upon request to the group) function Change()

    if ( opts[1] is string )

    if ( opts[1] is BigInteger )

  6. Discern PPid (string) and address (byte[]) function ShowContributedValues()

    if (lookForID is string) // --PENDING!-- não sei se isso vai funcionar direito!

Format code by "classes"

Reorganize the algorithm by the structure of 'classes' in order to provide inheritance and better readability.

😉 Get note from here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.