Skip to content

Commit a44d296

Browse files
committed
refactor: move ttl logic to separate function
1 parent da06828 commit a44d296

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

contracts/xyz/XYZBroadcaster.vy

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ def __init__(_admins: AdminSet):
6969
log ApplyAdmins(_admins)
7070

7171

72+
@internal
73+
@pure
74+
def _get_ttl(agent: Agent, ttl: uint256) -> uint256:
75+
if agent == Agent.EMERGENCY:
76+
# Emergency votes should be brisk
77+
if ttl == 0:
78+
ttl = DAY # default
79+
assert ttl <= WEEK
80+
else:
81+
if ttl == 0:
82+
ttl = WEEK # default
83+
assert DAY <= ttl and ttl <= 3 * WEEK
84+
return ttl
85+
86+
7287
@external
7388
def broadcast(_chain_id: uint256, _messages: DynArray[Message, MAX_MESSAGES], _ttl: uint256=0):
7489
"""
@@ -79,16 +94,7 @@ def broadcast(_chain_id: uint256, _messages: DynArray[Message, MAX_MESSAGES], _t
7994
"""
8095
agent: Agent = self.agent[msg.sender]
8196
assert agent != empty(Agent) and len(_messages) > 0
82-
ttl: uint256 = _ttl
83-
if agent == Agent.EMERGENCY:
84-
# Emergency votes should be brisk
85-
if ttl == 0:
86-
ttl = DAY # default
87-
assert ttl <= WEEK
88-
else:
89-
if ttl == 0:
90-
ttl = WEEK # default
91-
assert DAY <= ttl and ttl <= 3 * WEEK
97+
ttl: uint256 = self._get_ttl(agent, _ttl)
9298

9399
digest: bytes32 = keccak256(_abi_encode(_messages))
94100
nonce: uint256 = self.nonce[agent][_chain_id]

0 commit comments

Comments
 (0)