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(...). protocol/sophia_stdlib.md at master · aeternity/protocol · GitHub

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)
2 Likes