0

I get error when I try to call this function AvailableEnergyAdvert with energy_produced greater value > 1.

pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/access/AccessControl.sol";

contract PowerGrid is Ownable,AccessControl {
........................
uint256 public energy_surplus = 0;
address payable public _owner ;
uint256 public Price1;
uint256 public Price2;
uint256[] pricerange;
uint256 net_total;
address payable public ProducerAddress;
..........
constructor () public payable
  {
    _owner= msg.sender;
  }
function AvailableEnergyAdvert(uint256  energy_produced, uint256  proposedprice ) public payable returns (bool check){ 
require(hasRole(Producers,msg.sender),"Not a Producer");
emit energyGenerated(msg.sender);
uint invokeTime = now;
timealive.push(invokeTime);
uint Time1 = invokeTime + 1 hours;
timealive.push(Time1);
uint Time2 = invokeTime + 2 hours;
timealive.push(Time2);
uint Time3 = invokeTime + 3 hours;
timealive.push(Time3);
emit TimeCalc(timealive);
if(energy_surplus == 990)
revert();
energy_surplus += energy_produced;
emit energyMoved(energy_produced);
pricerange.push(proposedprice);
Price1 = proposedprice + (proposedprice * 1 / 10);
pricerange.push(Price1);
Price2 = proposedprice + (proposedprice * 2 / 10);
pricerange.push(Price2);
emit PriceCalc(pricerange);
uint taxpaid = (proposedprice * energy_produced) / 2;
_owner.transfer(taxpaid);
emit confirmation(taxpaid);
return true;
}
  • I suggest you 1) format your code properly, it's barely readable as it is 2) Try to remove some lines and see if you can narrow down the problem – Lauri Peltonen Jan 11 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.