Skip to content

Commit

Permalink
Remove all and merge it's logic in transfer_sender_check
Browse files Browse the repository at this point in the history
Problem: the `all` function is based on `List.fold` and is used only
in one place on a list created from a `List.map`.
This results in an (unnecessary) double traversing of the list.

Solution: remove the `all` function and merge its logic inside the one
that uses it (`transfer_sender_check`) in order to traverse the list a
single time and reduce its transaction gas cost.
  • Loading branch information
pasqu4le committed Dec 21, 2020
1 parent 17843b0 commit 956f2e3
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions ligo/stablecoin/actions.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ function call_assert_receivers
end
} with operations


(*
* Returns `True` if all booleans in the list are `True`,
* or `False` otherwise.
*)
function all(const xs: list(bool)): bool is
List.fold
( function(const acc: bool; const x: bool) is acc and x
, xs
, True
)

(*
* Assert that all addresses in a list are equal,
* fails with `err_msg` otherwise.
Expand Down Expand Up @@ -265,12 +253,12 @@ function transfer_sender_check
) : storage is block
{ // check if the sender is either the owner or an approved operator for all transfers
const is_approved_operator_for_all : bool =
all(
List.map(
function(const p : transfer_param) : bool is is_approved_operator(p, store.operators),
params
List.fold
( function(const acc: bool; const p : transfer_param) is
acc and is_approved_operator(p, store.operators)
, params
, True
)
)
} with
if is_approved_operator_for_all then
store
Expand Down

0 comments on commit 956f2e3

Please sign in to comment.