Expose colonyNetwork constants for reference by other contracts

#1

I am working on a dapp that adds at least one additional contract on top of colony. This contract needs to be able to interface with hasUserRole to determine if an address has the necessary role(s).

I can successfully access hasUserRole through an abstract contract pointed to the deployed colony contract like this:

contract AbstractColony {
   hasUserRole(address who, uint256 where, uint8 role) public view returns (bool);

}

I was hoping to be able to look up the correct values for the different roles from the authority contract like this:

contract AbstractColonyAuthority {
  uint8 constant FUNDING_ROLE;
  uint8 constant ADMINISTRATION_ROLE;
  uint8 constant ARBITRATION_ROLE;
  uint8 constant ARCHITECTURE_ROLE;
  uint8 constant ARCHITECTURE_SUBDOMAIN_ROLE;
  uint8 constant ROOT_ROLE;
}

Unfortunately accessing these constants from an external contract is not currently possible with solidity. See this open issue: https://github.com/ethereum/solidity/issues/1290

Could you expose these constants through functions as suggested by that same issue as a temporary workaround in the meantime?

If not, can you provide a reference of the values that these constants have in the official documentation so that there can be no confusion?

Please let me know if I should create a Github ticket for this.

Clearly, getting roles correct is essential for correct functioning and security. Thank you.

1 Like
#2

In the colonyNetwork contacts, the colony roles are enumerated. The names for the constants as listed in your example are the names we gave them in the colonyJS library.

This is what they are in the colonyNetwork contracts (also here for reference):

enum ColonyRole { Recovery, Root, Arbitration, Architecture, ArchitectureSubdomain, Funding, Administration }

This is how we name the constants in the colonyJS library:


export const COLONY_ROLE_ADMINISTRATION = 'ADMINISTRATION';
export const COLONY_ROLE_ARBITRATION = 'ARBITRATION';
export const COLONY_ROLE_ARCHITECTURE = 'ARCHITECTURE';
export const COLONY_ROLE_ARCHITECTURE_SUBDOMAIN = 'ARCHITECTURE_SUBDOMAIN';
export const COLONY_ROLE_FUNDING = 'FUNDING';
export const COLONY_ROLE_RECOVERY = 'RECOVERY';
export const COLONY_ROLE_ROOT = 'ROOT';

export const COLONY_ROLES = {
  [COLONY_ROLE_RECOVERY]: 0,
  [COLONY_ROLE_ROOT]: 1,
  [COLONY_ROLE_ARBITRATION]: 2,
  [COLONY_ROLE_ARCHITECTURE]: 3,
  [COLONY_ROLE_ARCHITECTURE_SUBDOMAIN]: 4,
  [COLONY_ROLE_FUNDING]: 5,
  [COLONY_ROLE_ADMINISTRATION]: 6,
};

Colony Roles was intended to match but is currently incorrect. This is my fault. I will fix this and make it more clear the relation the numbers have to the colonyNetwork contracts.

Feel free to open a PR in colonyNetwork but using the same enum will work in the meantime.