contract MainContract is Ownable {
    using SafeMath for uint; 

    address myAddress = address(this);
    address myOwnerAddress = msg.sender;

    KEDRON public token = new KEDRON(myAddress, 'KERD Token', 'KEDR');
    ExternalStorage public exStorage = new ExternalStorage(myOwnerAddress);



    modifier isRPAdmin (address _addr) {
        require(exStorage.isRPAdminF(_addr) == true, "Access denied");
        _;
    }


    constructor() public {
        
    }



    function transferTokenOwnerShip(address _newOwnerContract)public onlyOwner {
        token.transferOwnership(_newOwnerContract);
    }

    function confirmTokenOwnerShip() public onlyOwner {
        token.confirmOwnership();
    }
    /**
     * RPadmin functions for deposit control
     */

    function transferTokens(address _addrInvestor, uint256 _projectID, uint256 _amount, string memory _comment) public isRPAdmin(msg.sender) {
        require (_addrInvestor != address(0));
        require (_amount >= 1);
        exStorage.addDeposit (_addrInvestor, _projectID, _amount, msg.sender) ;
        token.mint(_addrInvestor, _amount, _comment);
    }
    
    function revokeTokens(address _addrInvestor, uint256 _projectID, uint256 _amount, string memory _comment) public isRPAdmin(msg.sender) {
        // the function take tokens from _investor to contract
        // the sum is entered in whole tokens (1 = 1 token)
        require (_amount >= 1);
        exStorage.revokeDeposit (_addrInvestor, _projectID, _amount, msg.sender) ;
        token.burn(_addrInvestor, _amount, _comment);    
    }     
    
    function withdrawFunds (address payable _to, uint256 _value) public onlyOwner {
        require(_to != address(0),"Invalid address");
        require (myAddress.balance >= _value,"Value is more than balance");
        _to.transfer(_value);
    }


}
function transferTokens(address _addrInvestor, uint256 _projectID, uint256 _amount, string memory _comment) public isRPAdmin(msg.sender) {
        require (_addrInvestor != address(0));
        require (_amount >= 1);
        exStorage.addDeposit (_addrInvestor, _projectID, _amount, msg.sender) ;
        token.mint(_addrInvestor, _amount, _comment);
    }
/**
 * RPadmin functions for deposit control
 */