Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Prevent reinitialising the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
nullun committed Oct 17, 2022
1 parent 4c04870 commit 28d98ef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions staking/contracts/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Constants
ADMIN_ADDRESS = Bytes("A")
INIT_FLAG = Bytes("I")
PAUSED_FLAG = Bytes("P")
STAKED_ASSET = Bytes("SA")
AMOUNT_STAKED = Bytes("AS")
Expand Down Expand Up @@ -262,6 +263,9 @@ def deploy(
Assert(Gt(end.get(), begin.get())),
App.globalPut(END_TIMESTAMP, end.get()),

# Set init flag
App.globalPut(INIT_FLAG, Int(1)),

# Success
Approve(),
)
Expand All @@ -278,6 +282,10 @@ def init(
# Check if admin is initializing the contract
is_admin(),

# Only allow calling once, when the init flag is set
Assert(App.globalGet(INIT_FLAG)),
App.globalDel(INIT_FLAG),

# Check previous transaction is a payment transaction
Assert(pay.get().type_enum() == TxnType.Payment),

Expand Down

0 comments on commit 28d98ef

Please sign in to comment.