Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make changes needed for TCR #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions contracts/RegistryApp.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma solidity ^0.4.15;

import "@aragon/core/contracts/apps/App.sol";
import "@aragon/os/contracts/apps/AragonApp.sol";
import "./interfaces/IRegistry.sol";


/**
* A generic registry app.
Expand All @@ -11,49 +13,63 @@ import "@aragon/core/contracts/apps/App.sol";
* the rules for who can add and remove entries in the registry, it becomes
* a powerful building block (examples are token-curated registries and stake machines).
*/
contract RegistryApp is App {
contract RegistryApp is IRegistry, AragonApp {
// The entries in the registry.
mapping(bytes32 => bytes32) entries;
mapping(bytes32 => bytes) entries;

// Fired when an entry is added to the registry.
event EntryAdded(bytes32 id);
// Fired when an entry is removed from the registry.
event EntryRemoved(bytes32 id);

bytes32 public constant ADD_ENTRY_ROLE = bytes32(1);
bytes32 public constant REMOVE_ENTRY_ROLE = bytes32(2);
bytes32 public constant ADD_ENTRY_ROLE = bytes32("ADD_ENTRY_ROLE");
bytes32 public constant REMOVE_ENTRY_ROLE = bytes32("REMOVE_ENTRY_ROLE");

/**
* @notice Initialize App
*/
function initialize() onlyInit external {
initialized();
}

/**
* Add an entry to the registry.
* @param _data The entry to add to the registry
*/
function add(
bytes32 _data
) public auth(ADD_ENTRY_ROLE) returns (bytes32 _id) {
function add(bytes _data) isInitialized public auth(ADD_ENTRY_ROLE) returns (bytes32 _id) {
_id = keccak256(_data);
entries[_id] = _data;
require(!exists(_id));

entries[_id] = _data;
EntryAdded(_id);
}

/**
* Remove an entry from the registry.
* @param _id The ID of the entry to remove
*/
function remove(
bytes32 _id
) public auth(REMOVE_ENTRY_ROLE) {
function remove(bytes32 _id) isInitialized public auth(REMOVE_ENTRY_ROLE) {
require(exists(_id));

delete entries[_id];
EntryRemoved(_id);
}

/**
* Get an entry from the registry.
* @param _id The ID of the entry to get
* @return The entry data
*/
function get(
bytes32 _id
) public constant returns (bytes32) {
function get(bytes32 _id) isInitialized public view returns (bytes) {
return entries[_id];
}

/**
* Check if an entry is in the registry.
* @param _id The ID of the entry to get
* @return True if it's in the registry, false otherwise
*/
function exists(bytes32 _id) public view returns (bool) {
return entries[_id].length > 0;
}
}
16 changes: 16 additions & 0 deletions contracts/interfaces/IRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity ^0.4.18;


interface IRegistry {
function add(bytes _data) public returns (bytes32 _id);
function remove(bytes32 _id) public;
function exists(bytes32 _id) public view returns (bool);
}


contract FakeRegistry {
// to work around coverage issue
function fake() public pure {
// for lint
}
}
Loading