diff --git a/src/erc7730/convert/resolved/values.py b/src/erc7730/convert/resolved/values.py index f02cd7a..b93629b 100644 --- a/src/erc7730/convert/resolved/values.py +++ b/src/erc7730/convert/resolved/values.py @@ -108,7 +108,7 @@ def resolve_path_or_constant_value( if (raw := encode_value(value, abi_type, out)) is None: return None - return ResolvedValueConstant(value=value, raw=raw) + return ResolvedValueConstant(type_family=abi_type, type_size=len(raw) // 2 - 1, value=value, raw=raw) return None diff --git a/src/erc7730/model/resolved/display.py b/src/erc7730/model/resolved/display.py index dfc825d..a981116 100644 --- a/src/erc7730/model/resolved/display.py +++ b/src/erc7730/model/resolved/display.py @@ -3,6 +3,7 @@ from eip712.model.schema import EIP712Type from pydantic import Discriminator, Field, Tag +from erc7730.common.abi import ABIDataType from erc7730.model.base import Model from erc7730.model.display import ( AddressNameType, @@ -48,6 +49,15 @@ class ResolvedValueConstant(Model): description="The value type identifier (discriminator for values discriminated union).", ) + type_family: ABIDataType = Field( + title="Type family", + description="Type family of the value", + ) + + type_size: int | None = Field( + default=None, title="Type size", description="Size of the type (in bytes)", ge=0, le=255 + ) + value: ScalarType = Field( title="Value", description="The constant value.", diff --git a/tests/convert/resolved/data/literal_values_resolved.json b/tests/convert/resolved/data/literal_values_resolved.json index 43c923f..06b8905 100644 --- a/tests/convert/resolved/data/literal_values_resolved.json +++ b/tests/convert/resolved/data/literal_values_resolved.json @@ -18,13 +18,15 @@ "0x5ca8f297": { "fields": [ { - "value": { "type": "constant", "value": "Hello world", "raw": "0x48656c6c6f20776f726c64" }, + "value": { "type": "constant", "type_family": "string", "type_size": 11, "value": "Hello world", "raw": "0x48656c6c6f20776f726c64" }, "label": "Test - raw", "format": "raw" }, { "value": { "type": "constant", + "type_family": "address", + "type_size": 20, "value": "0x0000000000000000000000000000000000000Bbb", "raw": "0x0000000000000000000000000000000000000bbb" }, @@ -32,10 +34,16 @@ "format": "addressName", "params": { "types": ["eoa"], "sources": ["ens"] } }, - { "value": { "type": "constant", "value": 1337, "raw": "0x0539" }, "label": "Test - amount", "format": "amount" }, + { + "value": { "type": "constant", "type_family": "uint", "type_size": 2, "value": 1337, "raw": "0x0539" }, + "label": "Test - amount", + "format": "amount" + }, { "value": { "type": "constant", + "type_family": "bytes", + "type_size": 20, "value": "0x0000000000000000000000000000000000000Bbb", "raw": "0x0000000000000000000000000000000000000bbb" }, @@ -44,44 +52,54 @@ "params": { "callee": { "type": "constant", + "type_family": "address", + "type_size": 20, "value": "0x0000000000000000000000000000000000000001", "raw": "0x0000000000000000000000000000000000000001" } } }, { - "value": { "type": "constant", "value": 1732003058, "raw": "0x673c44f2" }, + "value": { "type": "constant", "type_family": "uint", "type_size": 4, "value": 1732003058, "raw": "0x673c44f2" }, "label": "Test - date", "format": "date", "params": { "encoding": "timestamp" } }, - { "value": { "type": "constant", "value": 7200000, "raw": "0x6ddd00" }, "label": "Test - duration", "format": "duration" }, { - "value": { "type": "constant", "value": 42, "raw": "0x2a" }, + "value": { "type": "constant", "type_family": "uint", "type_size": 3, "value": 7200000, "raw": "0x6ddd00" }, + "label": "Test - duration", + "format": "duration" + }, + { + "value": { "type": "constant", "type_family": "uint", "type_size": 1, "value": 42, "raw": "0x2a" }, "label": "Test - nftName", "format": "nftName", "params": { "collection": { "type": "constant", + "type_family": "address", + "type_size": 20, "value": "0x0000000000000000000000000000000000000001", "raw": "0x0000000000000000000000000000000000000001" } } }, { - "value": { "type": "constant", "value": 127, "raw": "0x7f" }, + "value": { "type": "constant", "type_family": "uint", "type_size": 1, "value": 127, "raw": "0x7f" }, "label": "Test - tokenAmount", "format": "tokenAmount", "params": { "token": { "type": "constant", + "type_family": "address", + "type_size": 20, "value": "0x0000000000000000000000000000000000000001", "raw": "0x0000000000000000000000000000000000000001" } } }, { - "value": { "type": "constant", "value": 42, "raw": "0x2a" }, + "value": { "type": "constant", "type_family": "uint", "type_size": 1, "value": 42, "raw": "0x2a" }, "label": "Test - unit", "format": "unit", "params": { "base": "km/h", "decimals": 2, "prefix": true }