Skip to content

Commit

Permalink
Merge pull request #243 from Thetta/dev2
Browse files Browse the repository at this point in the history
dev2 -> dev
  • Loading branch information
AnthonyAkentiev committed Aug 1, 2018
2 parents 76ecfcf + 6f84571 commit a30336a
Show file tree
Hide file tree
Showing 60 changed files with 10,172 additions and 8,926 deletions.
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ npm install -g truffle@4.1.12
# test
npm run test

# coverage via coveralls.io
npm run coveralls
# coverage via coveralls.io, run only for master and dev branches
if [ "$CI_BRANCH" == "master" ] || [ "$CI_BRANCH" == "dev" ]; then npm run coveralls; fi
```
56 changes: 33 additions & 23 deletions contracts/DaoBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./IDaoBase.sol";

import "zeppelin-solidity/contracts/ownership/Ownable.sol";


/**
* @title DaoBase
* @dev This is the base contract that you should use.
Expand Down Expand Up @@ -67,55 +68,63 @@ contract DaoBase is IDaoBase, Ownable {
function upgradeDaoContract(IDaoBase _new) public isCanDo(UPGRADE_DAO_CONTRACT) {
emit DaoBase_UpgradeDaoContract(_new);
// call observers.onUpgrade() for all observers
for(uint i=0; i<store.getObserverCount(); ++i){
for(uint i=0; i<store.getObserverCount(); ++i) {
IDaoObserver(store.getObserverAtIndex(i)).onUpgrade(_new);
}

// transfer ownership of the store (this -> _new)
store.transferOwnership(_new);

// transfer ownership of all tokens (this -> _new)
for(i=0; i<store.getAllTokenAddresses().length; ++i){
for(i=0; i<store.getAllTokenAddresses().length; ++i) {
store.getAllTokenAddresses()[i].transferOwnership(_new);
}
}

// Groups:
function getMembersCount(string _groupName) public constant returns(uint){
function getMembersCount(string _groupName) public view returns(uint) {
return store.getMembersCount(keccak256(abi.encodePacked(_groupName)));
}

function addGroupMember(string _groupName, address _a) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AddGroupMember(_groupName, _a);
store.addGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}
function getGroupMembers(string _groupName) public constant returns(address[]){

function getGroupMembers(string _groupName) public view returns(address[]) {
return store.getGroupMembers(keccak256(abi.encodePacked(_groupName)));
}
function removeGroupMember(string _groupName, address _a) public isCanDo(MANAGE_GROUPS){

function removeGroupMember(string _groupName, address _a) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_RemoveGroupMember(_a);
store.removeGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}
function isGroupMember(string _groupName,address _a)public constant returns(bool) {

function isGroupMember(string _groupName,address _a) public view returns(bool) {
return store.isGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}

function getMemberByIndex(string _groupName, uint _index) public view returns (address) {
return store.getMemberByIndex(keccak256(abi.encodePacked(_groupName)), _index);
}

// Actions:
function allowActionByShareholder(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS){
function allowActionByShareholder(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AllowActionByShareholder(_what, _tokenAddress);
store.allowActionByShareholder(_what, _tokenAddress);
}
function allowActionByVoting(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS){

function allowActionByVoting(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AllowActionByVoting(_what, _tokenAddress);
store.allowActionByVoting(_what,_tokenAddress);
}

function allowActionByAddress(bytes32 _what, address _a) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AllowActionByAddress(_what, _a);
store.allowActionByAddress(_what,_a);
}
function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) public isCanDo(MANAGE_GROUPS){

function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AllowActionByAnyMemberOfGroup(_what, _groupName);
store.allowActionByAnyMemberOfGroup(_what, keccak256(abi.encodePacked(_groupName)));
}
Expand All @@ -131,34 +140,34 @@ contract DaoBase is IDaoBase, Ownable {
* b. caller is voting and it is succeeded -> allow
* 4. deny
*/
function isCanDoAction(address _a, bytes32 _permissionNameHash) public constant returns(bool){
function isCanDoAction(address _a, bytes32 _permissionNameHash) public view returns(bool) {
// 0 - is can do by address?
if(store.isCanDoByAddress(_permissionNameHash, _a)){
if(store.isCanDoByAddress(_permissionNameHash, _a)) {
return true;
}

// 1 - check if group member can do that without voting?
if(store.isCanDoByGroupMember(_permissionNameHash, _a)){
if(store.isCanDoByGroupMember(_permissionNameHash, _a)) {
return true;
}

for(uint i=0; i<store.getAllTokenAddresses().length; ++i){
for(uint i=0; i<store.getAllTokenAddresses().length; ++i) {

// 2 - check if shareholder can do that without voting?
if(store.isCanDoByShareholder(_permissionNameHash, store.getAllTokenAddresses()[i]) &&
(store.getAllTokenAddresses()[i].balanceOf(_a)!=0)){
(store.getAllTokenAddresses()[i].balanceOf(_a)!=0)) {
return true;
}


// 3 - can do action only by starting new vote first?
bool isCan = store.isCanDoByVoting(_permissionNameHash, store.getAllTokenAddresses()[i]);
if(isCan){
if(isCan) {
bool isVotingFound = false;
bool votingResult = false;
(isVotingFound, votingResult) = store.getProposalVotingResults(_a);

if(isVotingFound){
if(isVotingFound) {
// if this action can be done by voting, then Proposal can do this action
// from within its context
// in this case msg.sender is a Voting!
Expand All @@ -170,7 +179,7 @@ contract DaoBase is IDaoBase, Ownable {
bool isInMajority =
(store.getAllTokenAddresses()[i].balanceOf(_a)) >
(store.getAllTokenAddresses()[i].totalSupply()/2);
if(isInMajority){
if(isInMajority) {
return true;
}
}
Expand All @@ -185,19 +194,19 @@ contract DaoBase is IDaoBase, Ownable {
store.addNewProposal(_proposal);
}

function getProposalAtIndex(uint _i)public constant returns(IProposal){
function getProposalAtIndex(uint _i)public view returns(IProposal) {
return store.getProposalAtIndex(_i);
}

function getProposalsCount()public constant returns(uint){
function getProposalsCount()public view returns(uint) {
return store.getProposalsCount();
}

// Tokens:
function issueTokens(address _tokenAddress, address _to, uint _amount)public isCanDo(ISSUE_TOKENS) {
emit DaoBase_IssueTokens(_tokenAddress, _to, _amount);
for(uint i=0; i<store.getAllTokenAddresses().length; ++i){
if(store.getAllTokenAddresses()[i]==_tokenAddress){
for(uint i=0; i<store.getAllTokenAddresses().length; ++i) {
if(store.getAllTokenAddresses()[i]==_tokenAddress) {
// WARNING:
// token ownership should be transferred to the current DaoBase to do that!!!
store.getAllTokenAddresses()[i].mintFor(_to, _amount);
Expand All @@ -209,10 +218,10 @@ contract DaoBase is IDaoBase, Ownable {
revert();
}

function burnTokens(address _tokenAddress, address _who, uint _amount)public isCanDo(BURN_TOKENS){
function burnTokens(address _tokenAddress, address _who, uint _amount)public isCanDo(BURN_TOKENS) {
emit DaoBase_BurnTokens(_tokenAddress, _who, _amount);

for(uint i=0; i<store.getAllTokenAddresses().length; ++i){
for(uint i=0; i<store.getAllTokenAddresses().length; ++i) {
if(store.getAllTokenAddresses()[i]==_tokenAddress){
// WARNING:
// token ownership should be transferred to the current DaoBase to do that!!!
Expand All @@ -226,6 +235,7 @@ contract DaoBase is IDaoBase, Ownable {
}
}


/**
* @title DaoBaseWithUnpackers
* @dev Use this contract instead of DaoBase if you need DaoBaseAuto.
Expand Down
7 changes: 4 additions & 3 deletions contracts/DaoBaseAuto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./utils/GenericCaller.sol";

// TODO: convert to library?


/**
* @title DaoBaseAuto
* @dev This contract is a helper that will create new Proposal (i.e. voting) if the action is not allowed directly.
Expand All @@ -24,15 +25,15 @@ contract DaoBaseAuto is GenericCaller {
{
}

function addGroupMemberAuto(string _group, address _a) public returns(address proposalOut){
function addGroupMemberAuto(string _group, address _a) public returns(address proposalOut) {
bytes32[] memory params = new bytes32[](2);
params[0] = bytes32(keccak256(abi.encodePacked(_group)));
params[1] = bytes32(_a);

return doAction(MANAGE_GROUPS, dao, msg.sender,"addGroupMemberGeneric(bytes32[])",params);
}

function issueTokensAuto(address _token, address _to, uint _amount) public returns(address proposalOut){
function issueTokensAuto(address _token, address _to, uint _amount) public returns(address proposalOut) {
bytes32[] memory params = new bytes32[](3);
params[0] = bytes32(_token);
params[1] = bytes32(_to);
Expand All @@ -41,7 +42,7 @@ contract DaoBaseAuto is GenericCaller {
return doAction(ISSUE_TOKENS, dao, msg.sender,"issueTokensGeneric(bytes32[])",params);
}

function upgradeDaoContractAuto(address _newMc) public returns(address proposalOut){
function upgradeDaoContractAuto(address _newMc) public returns(address proposalOut) {
bytes32[] memory params = new bytes32[](1);
params[0] = bytes32(_newMc);

Expand Down
8 changes: 4 additions & 4 deletions contracts/DaoBaseImpersonated.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "zeppelin-solidity/contracts/ECRecovery.sol";

// TODO: convert to library?


/**
* @title ImpersonationCaller
* @dev This is a convenient wrapper that is used by the contract below (see DaoBaseImpersonated). Do not use it directly.
Expand All @@ -23,8 +24,7 @@ contract ImpersonationCaller is DaoClient {
* @param _hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
* @param _sig bytes signature, the signature is generated using web3.eth.sign()
*/
function doActionOnBehalfOf(bytes32 _hash, bytes _sig,
bytes32 _action, string _methodSig, bytes32[] _params) internal {
function doActionOnBehalfOf(bytes32 _hash, bytes _sig, bytes32 _action, string _methodSig, bytes32[] _params) internal {

// 1 - get the address of the client
address client = ECRecovery.recover(_hash, _sig);
Expand All @@ -45,6 +45,7 @@ contract ImpersonationCaller is DaoClient {

// TODO: convert to library?


/**
* @title DaoBaseImpersonated
* @dev This contract is a helper that will call the action is not allowed directly (by the current user) on behalf of the other user.
Expand All @@ -60,8 +61,7 @@ contract DaoBaseImpersonated is ImpersonationCaller {
{
}

function issueTokensImp(bytes32 _hash, bytes _sig,
address _token, address _to, uint _amount) public {
function issueTokensImp(bytes32 _hash, bytes _sig, address _token, address _to, uint _amount) public {
bytes32[] memory params = new bytes32[](3);
params[0] = bytes32(_token);
params[1] = bytes32(_to);
Expand Down
Loading

0 comments on commit a30336a

Please sign in to comment.