forked from pacta-app/vote-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibAssembly.sol
More file actions
83 lines (73 loc) · 2.31 KB
/
Copy pathLibAssembly.sol
File metadata and controls
83 lines (73 loc) · 2.31 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
pragma solidity >=0.0;
import "./libsign.sol";
import "./Shares.sol";
import "./Voting.sol";
library LibAssembly {
struct Data {
Shares shares; // shareholder token
mapping(string => address) registrations; // users that registered, maps secret to address
mapping(address => string) shareholders; // list of registered shareholders
string[] secrets; // list of registered secrets
address[] votings; // list of votings
string identifier; // you may set any text here, e.w. the assembly purpose
}
function construct(
Data storage data,
string memory _identifier
) public {
data.identifier = _identifier;
data.shares = new Shares();
}
// shareholder's access, security by signed messages
function register(
Data storage data,
string memory secret,
address a,
uint8 v,
bytes32 r,
bytes32 s
) public {
address shareholder = libsign.verify(abi.encode(secret, a), v, r, s);
require(
data.registrations[secret] == address(0x0),
"secret has already been used"
);
require(
bytes(data.shareholders[shareholder]).length == 0,
"you are already registered"
);
data.registrations[secret] = shareholder;
data.shareholders[shareholder] = secret;
data.secrets.push(secret);
}
// administration, restricted to assembly owner
function setShareholder(
Data storage data,
address shareholder,
uint256 shares
) public {
data.shares.setShareholder(shareholder, shares);
}
function setShareholders(
Data storage data,
address[] memory shareholders,
uint256[] memory shares
) public {
data.shares.setShareholders(shareholders, shares);
}
function newVoting(
Data storage data,
string memory title,
string memory proposal,
address signatory,
address payable owner
) public returns (address) {
Voting voting = new Voting(title, proposal, data.shares, signatory);
voting.changeOwner(owner);
data.votings.push(address(voting));
return address(voting);
}
function lock(Data storage data) public {
data.shares.lock();
}
}