From 956f2e304940e9d11cb4ee672505a4f2f089114d Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 18 Dec 2020 19:39:58 +0100 Subject: [PATCH] Remove `all` and merge it's logic in `transfer_sender_check` 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. --- ligo/stablecoin/actions.ligo | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/ligo/stablecoin/actions.ligo b/ligo/stablecoin/actions.ligo index c9920cb6..b7982491 100644 --- a/ligo/stablecoin/actions.ligo +++ b/ligo/stablecoin/actions.ligo @@ -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. @@ -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