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

Treat pair as comparable type #251

Closed
carte7000 opened this issue Feb 6, 2020 · 1 comment
Closed

Treat pair as comparable type #251

carte7000 opened this issue Feb 6, 2020 · 1 comment
Projects

Comments

@carte7000
Copy link
Contributor

@carte7000 carte7000 commented Feb 6, 2020

Michelson supports the use of Pair as key for a map and big-map, however, Taquito smart contract abstraction currently throws an error when encoding contract storage that make use of Pair as key in a map

For example

Given the following contract

const keyType = { "prim": "pair", "args": [{ "prim": "string" }, { "prim": "string" }] };

{
    "code": [
      { "prim": "parameter", "args": [{ "prim": "unit" }] },
      { "prim": "storage", "args": [{ "prim": "map", "args": [keyType, { "prim": "string" }] }] },
      {
        "prim": "code",
        "args":
          [[{ "prim": "DUP" }, { "prim": "CDR" },
          { "prim": "NIL", "args": [{ "prim": "operation" }] },
          { "prim": "PAIR" },
          { "prim": "DIP", "args": [[{ "prim": "DROP" }]] }]]
      }],
    "storage": [
      { "prim": "Elt", "args": [{ "prim": "Pair", args: [{ "string": "test2" }, { "string": "test3" }] }, { "string": "test" }] },
      { "prim": "Elt", "args": [{ "prim": "Pair", args: [{ "string": "test2" }, { "string": "test4" }] }, { "string": "test" }] },
    ]
  }

Taquito will throw the following error while encoding the storage into the SC abstract:

this.KeySchema.ToKey is not a function

The problem will be the same for big-map, set and map. This is because Taquito does not treat pair as comparable value (which it is).

A problem to consider while solving this issue:

The current implementation of the SC abstract produces a plain JS object for map. So a map is typically rendered as:

{ key : value}

However, this approach is not suitable for Pair because a JS object would be serialized before use as a key leading to overriding the other.

A few solutions to consider:

Given the following Pair:
{ "prim": "Pair", args: [{ "string": "test2" }, { "string": "test3" }] }

Taquito could serialize pair using a well known format test2_test3 leading to:

{ test2_test3: value }

Taquito could change how it abstracts Pair as key doing:

{ key: { prop1: test2, prop2: test3}, value: "value" }
carte7000 added a commit that referenced this issue Feb 11, 2020
Support pair for big map key
Note: pair are still not supported for map and set

re #251
@jevonearth jevonearth added this to Needs triage in Triage Mar 6, 2020
@jevonearth jevonearth moved this from Needs triage to Closed in Triage Mar 6, 2020
@jevonearth

This comment has been minimized.

Copy link
Collaborator

@jevonearth jevonearth commented Mar 6, 2020

Addressed in release [6.1.0-beta.0][https://github.com/ecadlabs/taquito/releases/tag/6.1.0-beta.0]

@jevonearth jevonearth closed this Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Triage
  
Closed
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.