Skip to content

Commit

Permalink
fix bank example
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Sep 10, 2024
1 parent 9334f3b commit 833a018
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions examples/milestone/Bank/Bank.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ calculateInterest : Nat -> Nat -> Nat -> Nat
incrAmount (a : Nat) : Nat := div (a * rate) 10000;
in iterate (min 100 periods) incrAmount amount;

--- Asserts some ;Bool; condition.
assert : {A : Type} -> Bool -> A -> A
| c a := ite c a (failwith "assertion failed");

--- Returns a new ;Token;. Arguments are:
---
--- `owner`: The address of the account to issue the token to
Expand All @@ -82,7 +78,7 @@ assert : {A : Type} -> Bool -> A -> A
---
--- `caller`: Who is creating the transaction. It must be the bank.
issue : Address -> Address -> Nat -> Token
| caller owner amount := assert (caller == bankAddress) (mkToken owner 0 amount);
| caller owner amount := assert (caller == bankAddress) >-> mkToken owner 0 amount;

--- Deposits some amount of money into the bank.
deposit (bal : Balances) (token : Token) (amount : Nat) : Token :=
Expand All @@ -102,11 +98,10 @@ withdraw
(rate : Nat)
(periods : Nat)
: Token :=
assert
(caller == bankAddress)
(let
hash : Field := hashAddress recipient;
total : Nat := calculateInterest amount rate periods;
token : Token := mkToken recipient 0 total;
bal' : Balances := decrement hash amount bal;
in runOnChain (commitBalances bal') token);
assert (caller == bankAddress)
>-> let
hash : Field := hashAddress recipient;
total : Nat := calculateInterest amount rate periods;
token : Token := mkToken recipient 0 total;
bal' : Balances := decrement hash amount bal;
in runOnChain (commitBalances bal') token;

0 comments on commit 833a018

Please sign in to comment.