Skip to content

Code Style: Solidity

Anthony Akentiev edited this page Aug 21, 2018 · 2 revisions
// RULES:
// 1 - Use tabs instead of spaces! 

// 2 - Spaces around brackets and modifiers
function getRevenueEndpoint() public view returns(IWeiReceiver) {
	return rootReceiver;
}

// 3 - Spaces around operators
contract FallbackToWeiReceiver {
	address output = 0x0;

	constructor(address _output) public {
		output = _output;
	}

	function() public payable {
		IWeiReceiver iwr = IWeiReceiver(output);
		iwr.processFunds.value(msg.value)(msg.value);
	}
}

// 4 - Spaces around conditionals
function callActionIfEnded(VotingStorage storage _store) public {
	if(!_store.finishedWithYes && isFinished(_store) && isYes(_store)) { 
		// should not be callable again!!!
		_store.finishedWithYes = true;
		emit CallAction();
		_store.proposal.action(); // can throw!
	}
}		

// 5 - long lines
constructor(
	IDaoBase _dao,
	IProposal _proposal,
	address _origin,
	VotingLib.VotingType _votingType,
	uint _minutesToVote,
	string _groupName,
	uint _quorumPercent,
	uint _consensusPercent,
	address _tokenAddress) public
	{
		store.generalConstructor(
			_dao,
			_proposal,
			_origin,
			_votingType,
			_minutesToVote,
			_groupName,
			_quorumPercent,
			_consensusPercent,
			_tokenAddress);
	}

// 6 - Naming:
// Parameters should be named starting with underscore
function setStdDaoTokenVotingID(uint _stdDaoTokenVotingID) public;

// Events should be named starting with UpperCase 
event MoneyFlowWithdrawDonations(address _by, address _to, uint _balance);

// Constants
bytes32 constant public WITHDRAW_DONATIONS = keccak256("withdrawDonations");
Clone this wiki locally