-
-
Save frankhillard/361a791d66ce29cda930c59c7fa46f82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This contract is an update of the counter.tz contract. | |
# It now keep the previous counter before each update. | |
# It has two entrypoints : | |
# - increaseCounterBy : storage.previousCounter = storage.counter, storage.counter = storage.counter + value | |
# - decreaseCounterBy : storage.previousCounter = storage.counter, storage.counter = storage.counter - value | |
parameter (or (int %increaseCounterBy) (int %decreaseCounterBy)); | |
storage (pair (int %counter) (int %previousCounter)); | |
code { | |
UNPAIR; | |
SWAP; | |
CAR @newPreviousCounter; | |
SWAP; | |
DIP { DUP @currentCounter; }; | |
IF_LEFT { | |
ADD @newCounter; | |
} | |
{ | |
SWAP; | |
SUB @newCounter; | |
}; | |
PAIR; | |
NIL operation; | |
PAIR; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment