cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Brainstorming the typing of .tokenCategory

Open mr-zwets opened this issue 11 months ago • 1 comments

This issue is mainly just brainstorming about the type system for CashScript

tokenCategory example

consider the following example

bytes tokenCategoryResultInput0 = tx.inputs[0].tokenCategory;
bytes32 tokenCategoryInput0, bytes capabilityInput0 = tokenCategoryResultInput0.split(32)

tokenCategoryResultInput0 or capabilityInput0 can not be more specific than just bytes because they don't fit the bytesX type.

However in reality tokenCategoryResultInput0 is the union type of bytes0 | bytes32 | bytes33 and we know the type of capabilityInput0 to be 0x | 0x01 | 0x02 or more generic bytes0 | byte

but union types don't exist in CashScript and neither does bytes0 or as const typing

as an aside I noticed

The type byte has been removed. It was an alias of bytes1.

https://docs.soliditylang.org/en/v0.8.3/080-breaking-changes.html#silent-changes-of-the-semantics

mr-zwets avatar Mar 12 '25 16:03 mr-zwets

Something similar is the case for signatures, where signatures the sighash flag/type is appended at the end, see #310

Potentially this could also be made clear through the typesystem

mr-zwets avatar Aug 17 '25 07:08 mr-zwets