Contract Overview
Balance: 0 Ether
Transactions: 1 txn
[ Download CSV Export  ] 
 Internal Transactions as a result of Contract Execution
View All
ParentTxHash Block Age From To Value
Warning: The compiled contract might be susceptible to EventStructWrongData (very low-severity), NestedArrayFunctionCallDecoder (medium-severity) Solidity compiler bugs.

Contract Source Code Verified (Similar match)
Note: Displaying similar matching verified source code at contract 0xa6a706a6ea534c4662b8b3ed8c1ad00ed442ac43(excluding Constructor Arguments if any)
Contract Name: GreenBuyContract
Compiler Version: v0.4.21+commit.dfe3193c
Optimization Enabled: No
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.21;

contract GreenBuyContract {
    
    uint public kWh;
    uint public kWhDecimal;
    
    address public clientAddress;
    address public producerContractAddress;
    
    bool public active;
    bool public payed;
    bool public validated;
    
    function GreenBuyContract (uint _kWh, uint _kWhDecimal, address _clientAddress, address _producerContractAddress) public {
        kWh = _kWh;
        kWhDecimal = _kWhDecimal;
        clientAddress = _clientAddress;
        producerContractAddress = _producerContractAddress;
        active = false;
        payed = false;
        validated = false;
    }
    
    function activate() public onlyBy(producerContractAddress) {
        active = true;
    }
    
    function validate() public {
        require(msg.sender==producerContractAddress);
        validated = true;
        
        if(payed){
            withdraw();
        }
    }
    
    function withdraw() {
        GreenSellContract sellContract = GreenSellContract(producerContractAddress);
        ERC20 token = ERC20(sellContract.tokenAddress());
            
        uint amount = sellContract.kWhTokenPrice() * kWh;
            
        if(token.transfer(sellContract.producerAddress(), amount)){
            payed = true;
        }
        
    }
    
    function hold() public isActive() {
        require(msg.sender==producerContractAddress);
        
        GreenSellContract sellContract = GreenSellContract(producerContractAddress);
        uint amount = sellContract.kWhTokenPrice() * kWh;
        
        ERC20 token = ERC20(sellContract.tokenAddress());
        
        if(token.transferFrom(clientAddress, address(this), amount)){
            payed = true;
        }
    }
    
    modifier onlyBy(address _account)
    {
        require(msg.sender == _account);
        _;
    }
    modifier isActive()
    {
        require(active);
        _;
    }
}

contract GreenSellContract {
    
    uint public kWhTokenPrice;
    //MAX 3 DECIMALS
    uint public kWhTokenPriceDecimalPart;

    uint public kWhTotal;
    //MAX 3 DECIMALS
    uint public kWhTotalDecimalPart;

    uint public kWhTotalAvailable;
    address public producerAddress;
    address public validatorAddress;
    
    address public tokenAddress;
    
    address[] public buyContracts;
    
    function GreenSellContract (uint _kWhTokenPrice, uint _kWhTokenPriceDecimalPart, uint _kwhTotal, uint _kWhTotalDecimalPart, address _producerAddress, address _validatorAddress, address _tokenAddress) public {
        kWhTokenPrice = _kWhTokenPrice;
        kWhTotal = _kwhTotal;
        kWhTokenPriceDecimalPart = _kWhTokenPriceDecimalPart;
        kWhTotalDecimalPart = _kWhTotalDecimalPart;
        kWhTotalAvailable = _kwhTotal;
        producerAddress = _producerAddress;
        validatorAddress = _validatorAddress;
        tokenAddress = _tokenAddress;
    }

    function getKWHPrice() public constant returns (uint) {
        return kWhTokenPrice;
    }
    
    function addBuyContract(address buyContractAddress) public {
        ERC20 token = ERC20(tokenAddress);
        
        GreenBuyContract buyContract = GreenBuyContract(buyContractAddress);
        
        require(token.allowance(buyContract.clientAddress(), buyContractAddress) >= (buyContract.kWh() * kWhTokenPrice) && kWhTotalAvailable >= buyContract.kWh() && buyContract.kWh() > 0);
        
        kWhTotalAvailable -= buyContract.kWh();
        
        buyContracts.push(buyContract);
        
        buyContract.activate();
        buyContract.hold();
    }
    
    function validateContract(address buyContractAddress){
        require(msg.sender==validatorAddress);
        
        GreenBuyContract buyContract = GreenBuyContract(buyContractAddress);
        buyContract.validate();
    }
}

contract ERC20 {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}

    Contract ABI  
[{"constant":false,"inputs":[],"name":"hold","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"active","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"activate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"producerContractAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"clientAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"payed","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"validate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"kWhDecimal","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"validated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kWh","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_kWh","type":"uint256"},{"name":"_kWhDecimal","type":"uint256"},{"name":"_clientAddress","type":"address"},{"name":"_producerContractAddress","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]

  Contract Creation Code Switch To Opcodes View
6060604052341561000f57600080fd5b604051608080610ae383398101604052808051906020019091908051906020019091908051906020019091908051906020019091905050836000819055508260018190555081600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600360146101000a81548160ff0219169083151502179055506000600360156101000a81548160ff0219169083151502179055506000600360166101000a81548160ff021916908315150217905550505050506109a98061013a6000396000f3006060604052600436106100ae576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168062e0c53f146100b357806302fb0c5e146100c85780630f15f4c0146100f557806311c9a94e1461010a5780632c2ab5ea1461015f5780633ccfd60b146101b457806356e4bc1f146101c95780636901f668146101f6578063cfba97ff1461020b578063efb37a3914610234578063f1fd979014610261575b600080fd5b34156100be57600080fd5b6100c661028a565b005b34156100d357600080fd5b6100db61055c565b604051808215151515815260200191505060405180910390f35b341561010057600080fd5b61010861056f565b005b341561011557600080fd5b61011d6105ea565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561016a57600080fd5b610172610610565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156101bf57600080fd5b6101c7610636565b005b34156101d457600080fd5b6101dc6108b4565b604051808215151515815260200191505060405180910390f35b341561020157600080fd5b6102096108c7565b005b341561021657600080fd5b61021e61095e565b6040518082815260200191505060405180910390f35b341561023f57600080fd5b610247610964565b604051808215151515815260200191505060405180910390f35b341561026c57600080fd5b610274610977565b6040518082815260200191505060405180910390f35b6000806000600360149054906101000a900460ff1615156102aa57600080fd5b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561030657600080fd5b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692506000548373ffffffffffffffffffffffffffffffffffffffff1663ec2a68eb6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561039157600080fd5b5af1151561039e57600080fd5b505050604051805190500291508273ffffffffffffffffffffffffffffffffffffffff16639d76ea586040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561040e57600080fd5b5af1151561041b57600080fd5b5050506040518051905090508073ffffffffffffffffffffffffffffffffffffffff166323b872dd600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1630856040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b151561051f57600080fd5b5af1151561052c57600080fd5b5050506040518051905015610557576001600360156101000a81548160ff0219169083151502179055505b505050565b600360149054906101000a900460ff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105cc57600080fd5b6001600360146101000a81548160ff02191690831515021790555050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000806000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1692508273ffffffffffffffffffffffffffffffffffffffff16639d76ea586040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156106c357600080fd5b5af115156106d057600080fd5b5050506040518051905091506000548373ffffffffffffffffffffffffffffffffffffffff1663ec2a68eb6040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b151561074257600080fd5b5af1151561074f57600080fd5b505050604051805190500290508173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8473ffffffffffffffffffffffffffffffffffffffff16636b6dffa76040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156107db57600080fd5b5af115156107e857600080fd5b50505060405180519050836040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200182815260200192505050602060405180830381600087803b151561087757600080fd5b5af1151561088457600080fd5b50505060405180519050156108af576001600360156101000a81548160ff0219169083151502179055505b505050565b600360159054906101000a900460ff1681565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561092357600080fd5b6001600360166101000a81548160ff021916908315150217905550600360159054906101000a900460ff161561095c5761095b610636565b5b565b60015481565b600360169054906101000a900460ff1681565b600054815600a165627a7a72305820752a2f147c3eba12090d4f63b311e0e8e7e3567f84c6bd576a092ced1417fd4c0029000000000000000000000000000000000000000000000000000000000000008300000000000000000000000000000000000000000000000000000000000000000000000000000000000000005f926ce38c952fd0da595fbe5165984447b2e53e0000000000000000000000002cee920560f8d24371d423292af104a3df699815

   Swarm Source:
bzzr://752a2f147c3eba12090d4f63b311e0e8e7e3567f84c6bd576a092ced1417fd4c

 

View All
Block Age txn Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward