Limit nodes visited per hop in recursion

Hey!

I am trying a model similar to a real Blockchain. I am trying to query what transactions and addresses may be related to a particular person, and for that, I was trying to do a recursive query. But due to the large nature of something like this, I wanted to limit the number of visited Transaction nodes to an arbitrary number.

I was thinking something of like what was asked in this StackOverflow [post].(neo4j - How can I Limit nodes on each level of children in tree with cypher query - Stack Overflow)

I wanted to do something like a mix of these two queries:

MATCH (address:Address)-[:SENDS|RECEIVES]->(tx:Transaction)<-[:SENDS|RECEIVES]-(other_address:Address)
WITH address, tx, tx.timestamp AS timestamp, other_address
ORDER BY timestamp DESC LIMIT 5   // limit to 5 transactions for each address
RETURN address, tx, other_address

This one would be the filtering of the transactions, and this one the actual recursive query:

MATCH path=(a:Address)-[:SENDS|RECEIVES*1..3]-(t:Transaction)<-[:SENDS|RECEIVES]-(other:Address)
RETURN path

Is there maybe an apoc procedure that I can use? I tried using the apoc spanning tree but it cant limit the size of the extended leafs. Thanks in advance!

The apoc path expand procedures allow you to define the alternating rel-types and node-lables and also allow to specify BFS, and different uniqueness (like node-global) and the maxDepth too.

Expand paths with config - APOC Documentation

Yes i saw that, but i wanted to limit the bfs to only explore at max five nodes. So for example starting from the parent node i would visit 5 Transaction nodes, then visit all Addresses, then visit 5 Transaction nodes. Repeating like this for a limited max depth, is that possible with this?