-
Notifications
You must be signed in to change notification settings - Fork 14
/
Group.rho
175 lines (174 loc) · 7.07 KB
/
Group.rho
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
new
Group,
groupMapCh,
deployId(`rho:rchain:deployId`),
deployerId(`rho:rchain:deployerId`),
RevAddress(`rho:rev:address`),
stdout(`rho:io:stdout`),
lookup(`rho:registry:lookup`),
insertArbitrary(`rho:registry:insertArbitrary`),
deployerRevAddr,
uriCh,
ret,
ack
in {
insertArbitrary!(bundle+{*Group},*uriCh) |
for ( @uri <- uriCh ) {
stdout!(["#define $Group", uri]) |
deployId!(uri)
} |
groupMapCh!({}) |
contract deployerRevAddr(memberDeployerId,return) = {
new revAddrCh, deployerPubKeyBytesCh, DeployerIdOps(`rho:rchain:deployerId:ops`) in {
stdout!(" getting deployer rev address") |
DeployerIdOps!("pubKeyBytes", *memberDeployerId, *deployerPubKeyBytesCh) |
for (@deployerPubKeyBytes <- deployerPubKeyBytesCh) {
// stdout!(["got pub key",deployerPubKeyBytes]) |
RevAddress!("fromPublicKey", deployerPubKeyBytes, *revAddrCh) |
for (@deployerRevAddr <- revAddrCh) {
stdout!({ "deployer REV address": deployerRevAddr, "pubKeyBytes": deployerPubKeyBytes }) |
return!(deployerRevAddr)
}
}
}
} |
contract Group (@"new", @name, inbox, return) = {
new
admin,
inboxURIsCh,
revAddrsCh,
userlistCh,
allowedRevAddrsCh,
memberRevAddrsCh,
ret,
dirCh
in {
userlistCh!([]) | inboxURIsCh!({}) | allowedRevAddrsCh!(Set()) | revAddrsCh!({}) |
stdout!("creating Group.") |
for (@groups <- groupMapCh ) {
if ( groups.get(name) != Nil ) {
stdout!("error: Group with that name already exists") |
groupMapCh!(groups) |
return!(Nil)
} else {
for(@{"read": *masterRead, ..._} <<- @[*deployerId, "dictionary"]) {
stdout!({"read": *masterRead}) |
masterRead!("Directory", *ret)
} |
for ( Directory <- ret ) {
stdout!(["got directory", *Directory]) |
// Create Group member directory
Directory!(*dirCh) |
for ( @{"read": *read, "write": *write, "grant": *grant, ..._ } <- dirCh ) {
stdout!(groups.set(name, { "info": {"request": *inbox }, "admin": *admin, "read": *read, "write": *write, "grant": *grant})) |
groupMapCh!(groups.set(name, { "info": {"request": *inbox }, "admin": *admin, "read": *read, "write": *write, "grant": *grant})) |
return!({"admin": *admin, "read": *read, "write": *write, "grant": *grant}) |
contract admin(@"add info", @key, @value, return) = {
for (@{"info": *info, ...rest} <- groupMapCh) {
stdout!(["info", *info, "rest", rest]) |
groupMapCh!({"info": *info.set(key, value)} ++ rest)
}
} |
contract admin(@"add user", @username, revAddr, @inbox, return, log) = {
log!(["entering add user", username, *revAddr, inbox]) |
//TODO see if already a member
read!(username, *ret) |
for ( @list <- userlistCh; @map <- revAddrsCh; isThere <- ret) {
log!(["userlist", list, "revmap", map, "isThere", *isThere]) |
if ( map.contains(*revAddr) or *isThere != Nil) {
log!("Sorry, username " ++ username ++ " already exists.") |
revAddrsCh!(map) |
userlistCh!(list) |
return!(Nil)
} else {
if ( list.length() == 0 ) {
log!(["first user being added", [username]]) |
userlistCh!([username]) |
write!(username, {"inbox": inbox, "delegate": Nil, "revAddr": *revAddr}, *log)
} else {
log!(["adding one more user", [list.slice(1,list.length()) ++ [ username, list.nth(0)]]]) |
userlistCh!(list.slice(1,list.length()) ++ [ username, list.nth(0)]) |
write!(username, {"inbox": inbox, "revaddr": *revAddr, "delegate": list.nth(0)}, *log)
} |
revAddrsCh!(map.set(*revAddr,username)) |
grant!(username, *ret) |
for ( updateself <- ret ) {
log!(["grant", *updateself]) |
return!({"selfupdate": *updateself})
}
}
}
} |
contract admin(@"registerSet", revaddrset, log) = {
for ( allowed <- allowedRevAddrsCh) {
log!("adding") |
allowedRevAddrsCh!(*allowed.union(*revaddrset))
}
} |
contract admin(@"unregister", revaddr, log) = {
for ( allowed <- allowedRevAddrsCh) {
log!("removing") |
allowedRevAddrsCh!(*allowed.delete(*revaddr))
}
} |
contract admin(@"request", @name, @userid, memberInbox, revAddr, return, log) = {
log!("adding " ++ userid ++ " to " ++ name) |
for ( allowed <<- allowedRevAddrsCh) {
log!({"allowed": *allowed.contains(*revAddr), "all": *allowed.toList()}) |
if (*allowed.contains(*revAddr)) {
log!(["revAddr is registered, adding.", *revAddr])
} else {
log!(["revAddr not registered, adding anyway for now.", *revAddr])
}
} |
admin!("add user", userid, *revAddr, *memberInbox, *return, *log)
}
}
}
}
}
}
} |
stdout!("request") |
contract Group (@"request", @name, @userid, memberInbox, @deployerId, return, log) = {
new ch in {
log!("adding " ++ userid) |
// call request methos for group
// TODO: get the deployers rev address and add if allowed
deployerRevAddr!(deployerId,*ch) |
for ( revAddr <<- ch; @{map /\ {=name: {"info": {"request": *inbox, ..._}, "admin": *admin, ..._}, ..._}} <<- groupMapCh ) {
log!(["map",map]) |
inbox!(["GroupRequest", name, {"username": userid, "revAddress": *revAddr, "inbox": *memberInbox}],*log)|
admin!("request", name, userid, *memberInbox, *revAddr, *return, *log)
}
}
} |
// stdout!("lookup") |
contract Group (@"lookup", @name, return) = {
for ( @{map /\ {=name: *infoCh, ..._}} <<- groupMapCh ) {
for ( info <<- infoCh ) {
//stdout!(*info) |
return!(*info)
}
}
} |
// stdout!("lookup2") |
contract Group (@"lookup", return) = {
for ( @map <<- groupMapCh ) {
//stdout!(map) |
return!(map.keys())
}
} |
new return(`rho:io:stdout`), ret, ret2 in {
stdout!("testing,") |
Group!("new","test", Nil, *ret) |
Group!("new","test2", Nil, *ret2) |
for ( @{"admin": admin, "read": read, "write": write, "grant": grant} <- ret; _ <- ret2 ) {
stdout!("got em") |
Group!("lookup","test",*stdout) |
Group!("lookup","test2",*stdout) |
Group!("lookup",*stdout) |
Group!("request", "test", "zorro", `rho:id:xxxxxxx`, *deployerId, *stdout, *stdout)
}
}
}