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

refactor contract to let editors just publish stuff #90

Merged
merged 6 commits into from
Apr 23, 2018
Merged
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
61 changes: 12 additions & 49 deletions packages/contracts/contracts/newsroom/Newsroom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,21 @@ pragma solidity ^0.4.19;
import "./ACL.sol";

contract Newsroom is ACL {
event ContentProposed(address indexed author, uint indexed id);
event ContentApproved(uint id);
event ContentDenied(uint id);
event RevisionPublished(address indexed editor, uint indexed id, string uri);
event NameChanged(string newName);

string private constant ROLE_REPORTER = "reporter";
string private constant ROLE_EDITOR = "editor";

uint private latestId;
mapping(uint => Content) private content;
mapping(uint => bool) private waiting;
mapping(uint => bool) private approved;
mapping(uint => Revision) public content;

string public name;

function Newsroom(string newsroomName) ACL() public {
setName(newsroomName);
}

function author(uint contentId) public view returns (address) {
return content[contentId].author;
}

function uri(uint contentId) public view returns (string) {
return content[contentId].uri;
}

function timestamp(uint contentId) public view returns (uint) {
return content[contentId].timestamp;
}

function isProposed(uint contentId) public view returns (bool) {
return waiting[contentId];
}

function isApproved(uint contentId) public view returns (bool) {
return approved[contentId];
}

function setName(string newName) public onlyOwner() {
require(bytes(newName).length > 0);
name = newName;
Expand All @@ -56,41 +32,28 @@ contract Newsroom is ACL {
_removeRole(who, role);
}

function proposeContent(string contentUri) public requireRole(ROLE_REPORTER) returns (uint) {
function publishRevision(string contentUri, bytes32 contentHash) public requireRole(ROLE_EDITOR) returns (uint) {
require(bytes(contentUri).length > 0);
require(contentHash.length > 0);

uint id = latestId;
latestId++;

content[id] = Content(
content[id] = Revision(
contentHash,
contentUri,
msg.sender,
now
now,
0x0
);

waiting[id] = true;
ContentProposed(msg.sender, id);
RevisionPublished(msg.sender, id, contentUri);
return id;
}

function approveContent(uint id) public requireRole(ROLE_EDITOR) {
require(waiting[id] == true);
require(content[id].author != 0x0);
delete waiting[id];
approved[id] = true;
ContentApproved(id);
}

function denyContent(uint id) public requireRole(ROLE_EDITOR) {
require(waiting[id] == true);
delete waiting[id];
delete content[id];
ContentDenied(id);
}

struct Content {
struct Revision {
bytes32 hash;
string uri;
address author;
uint timestamp;
address author;
}
}
7 changes: 5 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:solidity": "solium --dir contracts/",
"migrate": "truffle migrate",
"migrate:ganache": "run-s 'truffle migrate --network=ganache' build:stripArtifacts",
"test": "truffle test --network ganache",
"test": "tsc && truffle test --network ganache",
"clean": "rimraf build/",
"prepare": "truffle install",
"truffle": "truffle",
Expand All @@ -31,8 +31,8 @@
"@joincivil/dev-utils": "^1.2.2",
"@joincivil/doxity": "^0.0.1",
"@joincivil/tslint-rules": "^2.6.1",
"@joincivil/utils": "^1.1.4",
"@joincivil/typescript-types": "^1.0.0",
"@joincivil/utils": "^1.1.4",
"@types/chai": "^4.0.10",
"@types/chai-as-promised": "^7.1.0",
"@types/glob": "^5.0.34",
Expand All @@ -56,5 +56,8 @@
"typescript": "^2.7.2",
"web3": "^0.20.3",
"zeppelin-solidity": "1.7.0"
},
"dependencies": {
"@joincivil/typescript-types": "^1.0.0"
}
}
Loading