-
Notifications
You must be signed in to change notification settings - Fork 1
/
CallistoFS.sol
57 lines (45 loc) · 1.58 KB
/
CallistoFS.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
pragma solidity ^0.4.19;
import './safeMath.sol';
contract Callisto_FS {
using SafeMath for uint256;
mapping (string => entity) files;
struct entity
{
uint256 deposit;
address owner;
uint256 size;
}
event FileUpload(string indexed _hash, uint256 indexed _deposit, uint256 indexed _size);
event FileWithdrawn(string indexed _hash, uint256 indexed _remaining);
function upload(string _hash, uint256 _size) payable
{
files[_hash].owner = msg.sender;
files[_hash].deposit = files[_hash].deposit.add(msg.value);
files[_hash].size = _size;
emit FileUpload(_hash, msg.value, _size);
}
function deposit(string _hash) payable
{
files[_hash].deposit = files[_hash].deposit.add(msg.value);
}
function withdraw(string _hash, uint256 _amount) only_owner(_hash)
{
files[_hash].deposit = files[_hash].deposit.sub(_amount);
msg.sender.transfer(_amount);
emit FileWithdrawn(_hash, files[_hash].deposit);
}
function reallocate(string _hash, string _new_hash, uint256 _new_size) only_owner(_hash)
{
files[_new_hash].deposit = files[_hash].deposit;
files[_hash].deposit = 0;
files[_new_hash].owner = msg.sender;
files[_new_hash].size = _new_size;
emit FileUpload(_new_hash, files[_new_hash].deposit, _new_size);
emit FileWithdrawn(_hash, 0);
}
modifier only_owner(string _hash)
{
require(msg.sender == files[_hash].owner);
_;
}
}