Skip to content

Commit d446e59

Browse files
author
Ivo Georgiev
authored
Merge pull request #205 from AdExNetwork/issue-202-anyone-to-withdraw
Issue #202 Allow anyone to CLOSE in the withdraw period
2 parents e5ecb73 + 02bbb12 commit d446e59

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

sentry/src/access.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::Session;
1212
pub enum Error {
1313
OnlyCreatorCanCloseChannel,
1414
ChannelIsExpired,
15-
ChannelIsPastWithdrawPeriod,
15+
ChannelIsInWithdrawPeriod,
1616
RulesError(String),
1717
}
1818

@@ -28,21 +28,28 @@ pub async fn check_access(
2828
Event::Close => true,
2929
_ => false,
3030
};
31-
32-
// Check basic access rules
33-
// only the creator can send a CLOSE
34-
if session.uid != channel.creator && events.iter().any(is_close_event) {
35-
return Err(Error::OnlyCreatorCanCloseChannel);
36-
}
37-
3831
let current_time = Utc::now();
32+
let is_in_withdraw_period = current_time > channel.spec.withdraw_period_start;
3933

4034
if current_time > channel.valid_until {
4135
return Err(Error::ChannelIsExpired);
4236
}
4337

44-
if current_time > channel.spec.withdraw_period_start && !events.iter().all(is_close_event) {
45-
return Err(Error::ChannelIsPastWithdrawPeriod);
38+
// We're only sending a CLOSE
39+
// That's allowed for the creator normally, and for everyone during the withdraw period
40+
if events.iter().all(is_close_event)
41+
&& (session.uid == channel.creator || is_in_withdraw_period)
42+
{
43+
return Ok(());
44+
}
45+
46+
// Only the creator can send a CLOSE
47+
if session.uid != channel.creator && events.iter().any(is_close_event) {
48+
return Err(Error::OnlyCreatorCanCloseChannel);
49+
}
50+
51+
if is_in_withdraw_period {
52+
return Err(Error::ChannelIsInWithdrawPeriod);
4653
}
4754

4855
let default_rules = [

0 commit comments

Comments
 (0)