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

Error while calling complex endpoint contract #1648

Closed zamrokk closed 2 years ago

zamrokk commented 2 years ago

Description I am trying to call a specific endpoint from a rollup contract and it fails with "invalid handle data"

The entry point is here : "withdraw" https://ithacanet.tzkt.io/KT1Khg4z7dW2hN1k7Uw7cQ7epdcESK3Ez5cg/entrypoints

Michelson def : (pair %withdraw (pair (contract %callback (ticket (bytes %data))) (pair %handle (pair (pair (nat %amount) (bytes %data)) (pair (nat %id) (address %owner))) (address %ticketer))) (pair (bytes %handles_hash) (list %proof (pair bytes bytes))))

Steps To Reproduce Steps to reproduce the behavior:

  1. Running this part of code
let param : RollupParameters = 
            rollupType === ROLLUP_TYPE.DEKU ? new RollupParametersDEKU(process.env["REACT_APP_CONTRACT"]!+"%withdrawDEKU", quantity,tokenType == TOKEN_TYPE.XTZ ? await TOKEN_TYPE.XTZ.getBytes() : await TOKEN_TYPE.FA12.getBytes(process.env["REACT_APP_CTEZ_CONTRACT"]!) ,0,l1Address,process.env["REACT_APP_CONTRACT"]!,proof) 
                    : new RollupParametersTORU()
             console.log("param",param);
             console.log("c.methods",rollupContract.methods);
             type StringDictionary<T> = { [key: string]: T };
             const signatures: string[][] = rollupContract.parameterSchema.ExtractSignatures();
                let signatureDict: StringDictionary<string[]> = {};
                for (let i = 0; i < signatures.length; i++) {
                    // 0th element is key, the rest are values of the dict
                    signatureDict[signatures[i][0]] = signatures[i];
                    signatureDict[signatures[i][0]].shift();
                }
                console.log("signatures",signatures);
             //let inspect = rollupContract.methods.withdraw(...Object.values(param)).toTransferParams();
             //console.log("inspect",inspect);    
             //console.log("parameter signature",rollupContract.parameterSchema.ExtractSignatures());
            const op = await rollupContract.methods.withdraw(...Object.values(param)).send();
            await op.confirmation();
  1. I display the outputs before running the execution to the chain

image image

  1. I get this error :
 {
  "name": "TransactionInvalidBeaconError",
  "title": "Transaction Invalid",
  "message": "[TRANSACTION_INVALID_ERROR]:The transaction is invalid and the node did not accept it.",
  "description": "The transaction is invalid and the node did not accept it.",
  "data": [
    {
      "kind": "temporary",
      "id": "proto.012-Psithaca.michelson_v1.runtime_error",
      "contract_handle": "KT1Khg4z7dW2hN1k7Uw7cQ7epdcESK3Ez5cg"
    },
    {
      "kind": "temporary",
      "id": "proto.012-Psithaca.michelson_v1.script_rejected",
      "location": 85,
      "with": {
        "string": "invalid handle data"
      }
    }
  ]
}
  1. I look at the Beacon data that is sent on Temple Wallet
[
  {
    "destination": "KT1Khg4z7dW2hN1k7Uw7cQ7epdcESK3Ez5cg",
    "kind": "transaction",
    "amount": 0,
    "parameters": {
      "entrypoint": "withdraw",
      "value": {
        "prim": "Pair",
        "args": [
          {
            "prim": "Pair",
            "args": [
              {
                "string": "KT19ppxinsqKocGGRHyVATHpUX2Aki8xpxQj%withdrawDEKU"
              },
              {
                "prim": "Pair",
                "args": [
                  {
                    "prim": "Pair",
                    "args": [
                      {
                        "prim": "Pair",
                        "args": [
                          {
                            "int": "7"
                          },
                          {
                            "bytes": "050505030b"
                          }
                        ]
                      },
                      {
                        "prim": "Pair",
                        "args": [
                          {
                            "int": "0"
                          },
                          {
                            "string": "tz1VApBuWHuaTfDHtKzU3NBtWFYsxJvvWhYk"
                          }
                        ]
                      }
                    ]
                  },
                  {
                    "string": "KT19ppxinsqKocGGRHyVATHpUX2Aki8xpxQj"
                  }
                ]
              }
            ]
          },
          {
            "prim": "Pair",
            "args": [
              {
                "bytes": "2fd7a4c98e6ab20fef428b204b673c6d786e81ffc790228adae064cd475db0d5"
              },
              []
            ]
          }
        ]
      }
    }
  }
]

from this javascript object type I have defined

export class RollupParametersDEKU extends RollupParameters {

    callback : string; //contract endpoint
    amount : number; // nat
    data : string ; // bytes
    id : number; //nat
    owner : string ;//address
    ticketer : string; //address
    handles_hash : string ; //bytes proof will be converted to CHAR
    proof : Array<string> = []; //bytes array
    ...
  1. I compare the structure trees between the Michelson def to this one that is sent. Apart of the translation of types taquito javascript to Michelson types, all seems to be aligned

Expected behavior

Transaction should be accepted

Question Is there an issue with the Michelson "contract" type with taquito to do callback ? Is really the error around the "handle" field like the error says ?

zamrokk commented 2 years ago

"@taquito/beacon-wallet@^12.1.0": version "12.1.0"

"@airgap/beacon-dapp@^3.0.0": version "3.0.0"

zamrokk commented 2 years ago

Expected Michelson

image

zamrokk commented 2 years ago

hum... maybe it just work, it could be the error coming from smart contract XD

zamrokk commented 2 years ago

found it. Coming from Smart contract error, all the rest was passing well. Fixed :)