Skip to content

Instantly share code, notes, and snippets.

@frankhillard
Created November 22, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankhillard/361a791d66ce29cda930c59c7fa46f82 to your computer and use it in GitHub Desktop.
Save frankhillard/361a791d66ce29cda930c59c7fa46f82 to your computer and use it in GitHub Desktop.
# 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