Part 2 - Building the smart contracts
=====================================

This is the second part of the project where we will 
actually implement the smart contract that will manage
all orders between our virtual power plant participants.

Phase 1 - Designing the smart contract
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Your contract should include a function that will match selling and buying orders. 
This function could be called periodically by a python script. Think in advance how
this function could work (the "algorithmic part") and try to describe it in a few lines. 
Thinking about the behavior of a function without writing the actual code can help a lot
for the implementation. 

This market system will be implemented as a smart contract hosted on a blockchain.
Define the key functions your contract will need. You may need to think about adding
some "helpers" function that could help a software interact with your system to have 
insights about it like "how many orders have been emitted?" or "how many orders have 
not been satisfied?". Think about the final python script that will interact with your 
smart contracts. What will it needs to be able to simulate our scenario and print all 
interesting informations?

Considering all those functions, what data should the contract manage? In other words,
what should you include as variables in the contract? 


Phase 2 - Implementing the smart contract
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Compilation and deployment
--------------------------
Write first the core structure of your smart contracts : 

-   The variables used by the contract
-   The structure (struct https://solidity-by-example.org/structs/) representing the orders 
-   The different functions your contract will have

You can then try to implement the different functions.

.. tip:: 
    In solidity, a contract can store addresses (https://docs.soliditylang.org/en/latest/types.html#address) 
    of a given account. In particular, a function can knows what address called it 
    by using the function "msg.sender"

Find the base :download:`here </_static/project.sol>`
