pyteal icon indicating copy to clipboard operation
pyteal copied to clipboard

Adding abi.Bytes alias

Open fabrice102 opened this issue 3 years ago • 2 comments

Problem

Currently, for dynamic byte arrays byte[] we need to write abi.DynamicArray(abi.Byte), which is quite long. Same for static array.

Solution

Add some type aliases. Propositions:

  • abi.Bytes and abi.Bytes[32] for dynamic and 32-byte static array.
  • abi.DynamicByteArray and abi.StaticByteArray[32]

Dependencies

n/a

Urgency

nice to have

fabrice102 avatar Aug 09 '22 21:08 fabrice102

I believe the abi.DynamicByteArray can be solved by using abi.String.

For fixed length byte array, if you want 32 byte array, we can try abi.Address.

If we want other fixed length byte array, we can try to create a abi.ByteArray for fixed length byte array.

ahangsu avatar Aug 11 '22 17:08 ahangsu

I believe the abi.DynamicByteArray can be solved by using abi.String.

For fixed length byte array, if you want 32 byte array, we can try abi.Address.

This would technically work, but the problem is that abi.String and abi.Address have type-specific meanings. An abi.Address would not be appropriate for storing a non-address 32-byte array, such as a hash output or random seed.

Same thing for abi.String -- if you use this type, observers of the blockchain will assume that its value is valid UTF-8 and can be shown as a user-friendly string. goal app method will attempt to show a string if your method returns this type. So I would not recommend storing arbitrary bytes in it.

I think PR #500 takes a good approach to addressing this issue.

jasonpaulos avatar Aug 11 '22 17:08 jasonpaulos