all files / contracts/Inputs/ FundingInputGeneral.sol

100% Statements 11/11
100% Branches 6/6
100% Functions 4/4
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                    235×       235×       235× 234× 232× 231× 231×                       234× 234× 234×      
/*
 
 * @name        General Funding Input Contract
 * @package     BlockBitsIO
 * @author      Micky Socaci <micky@nowlive.ro>
 
*/
 
pragma solidity ^0.4.17;
 
contract FundingInputGeneral {
 
    uint8 public typeId = 0;
    address public FundingAssetAddress;
 
    event EventInputPaymentReceived(address sender, uint amount, uint8 _type);
 
    function FundingInputGeneral() public {
        FundingAssetAddress = msg.sender;
    }
 
    function () public payable {
        buy();
    }
 
    function buy() public payable returns(bool) {
        if(msg.value > 0) {
            if(isContract(FundingAssetAddress)) {
                if(FundingAssetAddress.call.value(msg.value)(bytes4(bytes32(keccak256("receivePayment(address,uint8)"))), msg.sender, typeId)) {
                    EventInputPaymentReceived(msg.sender, msg.value, typeId);
                    return true;
                } else {
                    revert();
                }
            }
            else {
                revert();
            }
        } else {
            revert();
        }
    }
 
    // this call adds 704 gas, good enough to keep
    function isContract(address addr) internal view returns (bool) {
        uint size;
        assembly { size := extcodesize(addr) }
        return size > 0;
    }
}