-
Notifications
You must be signed in to change notification settings - Fork 0
/
deadManSwitch.sol
46 lines (37 loc) · 1.21 KB
/
deadManSwitch.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
pragma solidity ^0.5.1;
contract DeadSwitch {
address creatorOfContract;
struct File {
address fileOwner;
string ipfsHash;
string key;
string ping;
}
uint numFiles;
mapping (uint => File) public files;
constructor() public {
creatorOfContract = msg.sender;
}
modifier onlyCreator() {
require(msg.sender == creatorOfContract, "Access denied. Sender not creator.");
// If caller is not creator, it reverts
_;
// Otherwise, it continues.
}
modifier onlyFileOwner(uint _fileId) {
require(files[_fileId].fileOwner == msg.sender, "Access denied. Sender not owner.");
// If caller is not fileOwner, it reverts
_;
// Otherwise, it continues
}
function addFile(string memory _ipfsHash, address _creator) public onlyCreator returns (uint fileId) {
fileId = numFiles++;
files[fileId] = File(_creator, _ipfsHash, "", "");
}
function pubishKey(string memory _key, uint _fileID) public onlyCreator{
files[_fileID].key = _key;
}
function ping(string memory _ping, uint _fileID) public onlyFileOwner(_fileID) {
files[_fileID].ping = _ping;
}
}