Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/erc7730/convert/resolved/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions src/erc7730/model/resolved/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.",
Expand Down
32 changes: 25 additions & 7 deletions tests/convert/resolved/data/literal_values_resolved.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,32 @@
"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"
},
"label": "Test - addressName",
"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"
},
Expand All @@ -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 }
Expand Down
Loading