pyteal icon indicating copy to clipboard operation
pyteal copied to clipboard

Overload `+` to Concat byte strings

Open barnjamin opened this issue 3 years ago • 2 comments

Problem

Make it more natural to add byte strings

Solution

define the + operator on the abi.Bytes class to do concat

barnjamin avatar Aug 05 '22 11:08 barnjamin

A large barrier to this is the fact that we need to know at compile time whether the types are bytes or uint64 -- if bytes, use concat; if uint64, use +. But there are situations in which we cannot know the type of a value at compile time, e.g. when reading from local/global state, when loading the scratch space from a previous transaction, or (and this is something we have the power to fix) when accepting an Expr subroutine argument.

jasonpaulos avatar Aug 05 '22 15:08 jasonpaulos

Another issue I am aware of deriving from https://github.com/algorand/pyteal/issues/369, how are we handling case for Bytes("bytes-a") + Bytes("bytes-b")? Do we expect resulting to be Bytes("bytes-abytes-b"), or something else? I remembered we contain quote sign in bytes tho.

ahangsu avatar Aug 05 '22 18:08 ahangsu