algo-builder icon indicating copy to clipboard operation
algo-builder copied to clipboard

Find transaction in transaction group by id

Open MetaB0y opened this issue 3 years ago • 5 comments

Without this change txn GroupIndex can inappropriately return -1 despite all fields of tx being the same as all fields of gtxns[x]. Apparently, the reason is that either tx or gtxns can be overwritten at some point by the same content but stored in a different memory location (indexOf uses === which compares objects by reference).

I had this problem when providing liquidity twice in a row in Pact smart contract

This change looks pretty safe, but I don't know if the root cause (change of memory locations) should be found and eliminated in addition or instead of this commit.

MetaB0y avatar Sep 06 '22 09:09 MetaB0y

Oh, actually it doesn't work for contract-to-contract calls (or inner txs in general) because they don't have ids. Not sure if they should though

MetaB0y avatar Sep 07 '22 08:09 MetaB0y

We should definitely look based on tx id. However yes - we probably need more inspection into that. Thanks for the update!

robert-zaremba avatar Sep 08 '22 10:09 robert-zaremba

I've updated the PR by using gtxns.find instead of map + indexOf

robert-zaremba avatar Sep 08 '22 10:09 robert-zaremba

it seams this breaks our tests.

robert-zaremba avatar Sep 08 '22 12:09 robert-zaremba

I've updated the PR by using gtxns.find instead of map + indexOf

But find returns an element, not index. So it doesn't work after this change.

MetaB0y avatar Oct 05 '22 13:10 MetaB0y