pragma solidity ^0.8.6; import "@openzeppelin/contracts/access/Ownable.sol"; import "./GHGNFT.sol"; import "./GHGERC20.sol"; import "./GHGTOKEN.sol"; contract GHGAggregation is Ownable { GHGToken ghgToken; GHGERC20 ghgSavings; GHGERC20 ghgEmissions; GHGERC20 ghgSurplus; GHGNFT ghgCertificates; GHGERC20 public ghgCompensation; uint256 public savings=0; uint256 public emissions=0; uint256 public surplus=0; uint256 public cntNFTs=0; uint256 public cntAggregations=0; uint256 public creationTime=0; uint256 public lastTime=0; mapping (uint256 => uint256) public idToNft; mapping (uint256 => address) public adToNft; mapping (address => uint256) public approvedContributors; event AddedNFT(uint256 indexed _blockId, uint256 indexed _time,uint256 _totalEmissions,uint256 _totalSavings,uint256 _totalSurplus); event TransferedNFT(uint256 indexed _blockId, uint256 indexed _time,uint256 _totalEmissions,uint256 _totalSavings,uint256 _totalSurplus); constructor(GHGToken _ghgToken,GHGERC20 _compensationToken) { ghgToken = _ghgToken; ghgSavings = _ghgToken.ghgSavings(); ghgEmissions = _ghgToken.ghgEmissions(); ghgCertificates = _ghgToken.ghgCertificates(); ghgSurplus = _ghgToken.ghgSurplus(); ghgCompensation =_compensationToken; creationTime = block.timestamp; lastTime = block.timestamp; } function compensation() public view returns(uint256) { return ghgCompensation.balanceOf(address(this)); } function approveContributor(address _contributor) public onlyOwner { approvedContributors[_contributor] = 1; } function declineContributor(address _contributor) public onlyOwner { approvedContributors[_contributor] = 0; } function addNFT(uint256 _tokenId) public { if ((msg.sender != owner()) && (approvedContributors[msg.sender] == 0)) { revert(); } if(ghgCertificates.ownerOf(_tokenId) == address(this)) { for(uint256 i=0;i= bytes1('0') && bytes1(c) <= bytes1('9')) { return c - uint8(bytes1('0')); } if (bytes1(c) >= bytes1('a') && bytes1(c) <= bytes1('f')) { return 10 + c - uint8(bytes1('a')); } if (bytes1(c) >= bytes1('A') && bytes1(c) <= bytes1('F')) { return 10 + c - uint8(bytes1('A')); } return 0; } function hexStringToAddress(string memory s) public pure returns (bytes memory) { bytes memory ss = bytes(s); require(ss.length%2 == 0); // length must be even bytes memory r = new bytes(ss.length/2); for (uint i=0; i= 1 + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), 1)), 0x1000000000000000000000000) } return tempAddress; } }