Moving on, let’s deconstruct how a listing object looks like.
The listing
The listings are made by the users who intend to sell their surplus power. They can decide how much they can sell from the amount they have in their store, which means they can sell anywhere from a minimum amount of 0.1 kWh (100 Wh, the average minimum energy to transfer in most smartgrids) to the upper limit being 5-10 kWh lesser than the amount they have in store. Let me illustrate this with an example. I know that on average a household can consume anywhere from 2-5 kWh per hour under typical usage. So if a seller household has 20 kWh in store and they want to sell it, they can only sell around 10 kWh of it, because they wouldn’t have any more to sell accounting for the C-rate and the time to transfer that energy.
This actually requires some more thought. But this will suffice for the MVP. I need to get this app up before I can make changes to it.
So when the user is making the listing, we give them a slider with an input box to allow them to choose how much energy to sell.
A problem with the listings is that I cannot store them under the account that makes it. There will be no way for me to retrieve them in that case. So I’m going to create a vector of active listings on the smart contract itself (a state variable), and when someone makes a new listing, I’ll just push it to this vector. When the listing has been satisfied, I will pop it and store it in another history vector within the marketplace (Is this actually necessary or does the blockchain already log this? have to check) This vector is only a set of Listing structs. Lets define the Listing struct.
- Energy: A fixed amount of kWh’s that the seller wants to sell. (I will make this a range later, but for the MVP this should do it.)
- Rate: 1 kWh to how much ever APT the seller deems it.
- isActive: a boolean to, well, self explanatory. This will be turned to false after the sale has been made.
- Price: This is just calculated from the above values, but helps to store it I guess?
- Seller address: self explanatory
- Seller’s smart grid ID
- timestamp: this is the exact time this listing was made, to add this, I am planning to use the timestamp functions in the aptos framework (gotta look into this)