contract DappVolumeHearts {

	dappVolumeHearts firstContract;

	using SafeMath for uint256;

	// set contract owner
	address public contractOwner;
	// set last address transacted
	address public lastAddress;
	// set first contracts address
	address constant public firstContractAddress = 0x6ACD16200a2a046bf207D1B263202ec1A75a7D51;
	// map dapp ids with heart totals ( does not count first contract )
	mapping(uint256 => uint256) public totals;

	// only contract owner
	modifier onlyContractOwner {
		require(msg.sender == contractOwner);
		_;
	}

	// set constructor
	constructor() public {
		contractOwner = msg.sender;
		lastAddress = msg.sender;
		firstContract = dappVolumeHearts(firstContractAddress);
	}


	// withdraw funds to contract creator
	function withdraw() public onlyContractOwner {
		contractOwner.transfer(address(this).balance);
	}

	// update heart count
	function update(uint256 dapp_id) public payable {
		require(msg.value >= 2000000000000000);
		require(dapp_id > 0);
		totals[dapp_id] = totals[dapp_id].add(msg.value);
		// send 50% of the money to the last person
		lastAddress.send(msg.value.div(2));
		lastAddress = msg.sender;
	}

	// get total hearts by id with legacy contract totaled in
	function getTotalHeartsByDappId(uint256 dapp_id) public view returns(uint256) {
		return totals[dapp_id].add(firstContract.getTotalHeartsByDappId(dapp_id));
	}

	// get contract balance
	function getBalance() public view returns(uint256){
		return address(this).balance;
	}

}
// Allows users to "heart" (like) a DAPP by dapp id
// 1 Like = XXXXX eth will be set on front end of site
// 50% of each transaction gets sent to the last liker
function withdraw() public onlyContractOwner {
	contractOwner.transfer(address(this).balance);
}

// withdraw funds to contract creator