contract ChargingGas is RequiringAuthorization, SafeMath {
	/** 1 EDG has 5 decimals **/
	uint public constant oneEDG = 100000;
	/** the price per kgas and GWei in tokens (with decimals) */
	uint public gasPrice;
	/** the amount of gas used per transaction in kGas */
	mapping(bytes4 => uint) public gasPerTx;
	/** the number of tokens (5 decimals) payed by the users to cover the gas cost */
	uint public gasPayback;
	
	function ChargingGas(uint kGasPrice) internal{
		//deposit, withdrawFor, updateChannel, updateBatch, transferToNewContract
	    bytes4[5] memory signatures = [bytes4(0x3edd1128),0x9607610a, 0xde48ff52, 0xc97b6d1f, 0x6bf06fde];
	    //amount of gas consumed by the above methods in GWei
	    uint[5] memory gasUsage = [uint(146), 100, 65, 50, 85];
	    setGasUsage(signatures, gasUsage);
	    setGasPrice(kGasPrice);
	}
	/**
	 * sets the amount of gas consumed by methods with the given sigantures.
	 * only called from the edgeless casino constructor.
	 * @param signatures an array of method-signatures
	 *        gasNeeded  the amount of gas consumed by these methods
	 * */
	function setGasUsage(bytes4[5] signatures, uint[5] gasNeeded) public onlyOwner {
		require(signatures.length == gasNeeded.length);
		for (uint8 i = 0; i < signatures.length; i++)
			gasPerTx[signatures[i]] = gasNeeded[i];
	}

	/**
	 * updates the price per 1000 gas in EDG.
	 * @param price the new gas price (with decimals, max 0.1 EDG)
	 **/
	function setGasPrice(uint price) public onlyAuthorized {
		require(price < oneEDG/10);
		gasPrice = price;
	}

	/**
	 * returns the gas cost of the called function.
	 * */
	function getGasCost() internal view returns(uint) {
		return safeMul(safeMul(gasPerTx[msg.sig], gasPrice), tx.gasprice) / 1000000000;
	}

}
function getGasCost() internal view returns(uint) {
	return safeMul(safeMul(gasPerTx[msg.sig], gasPrice), tx.gasprice) / 1000000000;
}

/**
 	 * returns the gas cost of the called function.
 	 * */