How to iterate all transaction in a list inside a record account

ho can iterate the transaction history

     contract LipaAccount=
                  record account = {
                     name    : string,
                     balance : int,
                     history : list(transaction) 
                      }

             record transaction = {
                          id : int,
                          amount: int,
                          txt_id : string //random hash string
                                 }

what i want is to get account and iterate all the transactions history

1 Like

Hello, there is multiple ways you can do, e.g. using the list standard library with include "List.aes" and then using List.map(...), List.foldr(...), List.fold(...), List.foreach(...) or , List.flat_map(...). https://github.com/aeternity/protocol/blob/master/contracts/sophia_stdlib.md#List

Otherwise you can recursively iterate manually.

function loop_history(history : list(transaction)) =
  switch(history)
    [] => ()
    one_tx :: remaining_txs =>
      do_something(one_tx )
      loop_history(remaining_txs)
1 Like