ecadlabs / taquito

A library for building dApps on the Tezos Blockchain - JavaScript / TypeScript
https://taquito.io
Apache License 2.0
298 stars 116 forks source link

More support for packing #2259

Open zamrokk opened 1 year ago

zamrokk commented 1 year ago

Hi Taquito team :smiley: Is it possible to bring more tooling around packing Ligo variants ? Not the first time I need to play with Michelson and pack all myself like this

async function packAction(action: Action): Promise<string> {
    const p = new MichelCodecPacker();
    let actionbytes: PackDataParams = {
      data: action.stone
        ? { prim: "Right", args: [{ prim: "Unit" }] }
        : action.cisor
        ? { prim: "Left", args: [{ prim: "Left", args: [{ prim: "Unit" }] }] }
        : { prim: "Left", args: [{ prim: "Right", args: [{ prim: "Unit" }] }] },
      type: {
        prim: "Or",
        annots: ["%action"],
        args: [
          {
            prim: "Or",
            args: [
              { prim: "Unit", annots: ["%cisor"] },
              { prim: "Unit", annots: ["%paper"] },
            ],
          },
          { prim: "Unit", annots: ["%stone"] },
        ],
      },
    };
    return (await p.packData(actionbytes)).packed;
  }

Is it possible to have a special taquito class for variants, so I can just pass this class while packing to bytes ?

Maybe is also a 2-question in 1, when generating Typescript types with taqueria plugin, only storage is exported, not intermediary types inside the storage definition itself. Most of the type I need to redefine locally an nested type from storage type to be able to use it on my code. The example above is variant that is stored somewhere on the storage, but I need to pass it "packed" on one of the entrypoint (that is a bit of context from above example)

The perfect DX would be to have this variant exported on a taqueria generated type along with the storage (in this example type action = {...} ) and then be able to pass it to the Michelson encoder pack function (without the need to do all manual trick above that requires too high level knowledge of Michelson for a standard developer :/ )

BearCooder commented 1 year ago

Followup from Slack:

Rodrigo Quelhas: You could use this: https://romarq.github.io/michelson-sdk/types#variant https://romarq.github.io/michelson-sdk/taquito

zamrokk commented 1 year ago

It would be great to integrate this types on the taqueria plugin generating the classes