-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoinDriveRight.sol
63 lines (42 loc) · 2 KB
/
CoinDriveRight.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
pragma solidity ^0.5.5;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/drafts/Counters.sol";
import "./ICoinDriveRight.sol";
contract CoinDriveRight is ICoinDriveRight {
using Counters for Counters.Counter;
Counters.Counter copyright_ids;
struct Work {
address owner;
string uri;
}
mapping(uint => Work) public copyrights;
event Copyright(uint copyright_id, address owner, string reference_uri);
event OpenSource(uint copyright_id, string reference_uri);
event Transfer(uint copyright_id, address new_owner);
modifier onlyCopyrightOwner(uint copyright_id) {
require(copyrights[copyright_id].owner == msg.sender, "You do not have permission to alter this copyright!");
_;
}
function copyrightWork(string memory reference_uri) public {
copyright_ids.increment();
uint id = copyright_ids.current();
copyrights[id] = Work(msg.sender, reference_uri);
emit Copyright(id, msg.sender, reference_uri);
}
function openSourceWork(string memory reference_uri) public {
copyright_ids.increment();
uint id = copyright_ids.current();
copyrights[id].uri = reference_uri;
// no need to set address(0) in the copyrights mapping as this is already the default for empty address types
emit OpenSource(id, reference_uri);
}
function transferCopyrightOwnership(uint copyright_id, address new_owner) public onlyCopyrightOwner(copyright_id) {
// Re-maps a given copyright_id to a new copyright owner.
copyrights[copyright_id].owner = new_owner;
emit Transfer(copyright_id, new_owner);
}
function renounceCopyrightOwnership(uint copyright_id) public onlyCopyrightOwner(copyright_id) {
// Re-maps a given copyright_id to the 0x0000000000000000000000000000000000000000
transferCopyrightOwnership(copyright_id, address(0));
emit OpenSource(copyright_id, copyrights[copyright_id].uri);
}
}