Skip to content

Instantly share code, notes, and snippets.

@frankhillard

frankhillard/snippet6.tz Secret

Created Nov 22, 2019
Embed
What would you like to do?
# 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
You can’t perform that action at this time.