Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agree on type alias to decode int as Number instead of BigInt #232

Open
davidyuk opened this issue Aug 19, 2023 · 2 comments
Open

Agree on type alias to decode int as Number instead of BigInt #232

davidyuk opened this issue Aug 19, 2023 · 2 comments

Comments

@davidyuk
Copy link
Member

Was initially discussed in aeternity/aesophia#351

I propose to decode returned value to Number instead of BigInt if calldata finds a shortint (not sure about name) aliased to int while type resolving.

For example for the contract

contract C =
  type shortint = int
  record rec = { x: shortint }

  entrypoint f(s : shortint) : shortint =
    s * 42

  entrypoint f2() : rec =
    { x = 42 }

ACI would be

[
  {
    "contract": {
      "functions": [
        {
          "arguments": [
            {
              "name": "s",
              "type": "C.shortint"
            }
          ],
          "name": "f",
          "payable": false,
          "returns": "C.shortint",
          "stateful": false
        },
        {
          "arguments": [],
          "name": "f2",
          "payable": false,
          "returns": "C.rec",
          "stateful": false
        }
      ],
      "kind": "contract_main",
      "name": "C",
      "payable": false,
      "typedefs": [
        {
          "name": "shortint",
          "typedef": "int",
          "vars": []
        },
        {
          "name": "rec",
          "typedef": {
            "record": [
              {
                "name": "x",
                "type": "C.shortint"
              }
            ]
          },
          "vars": []
        }
      ]
    }
  }
]

And it looks like ACI preserves enough info to track int alias even in complex structures. Of course, this feature is not urgent.

@dincho
Copy link
Member

dincho commented Aug 21, 2023

I'm not sure I get it? You're asking to handle a custom type that's not a buildin into Sophia ?

@davidyuk
Copy link
Member Author

Yep! For js developers' convenience 🙂 I'm not sure how this feature is important. The thing is that BigInt is not very handy. For example, it complains if mixed with numbers (1 * 1n), and it can't be serialized to JSON (JSON.stirngify({ a: 1n })). A developer may need to convert BigInts to Numbers by himself, and I'm proposing to have an agreement instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants