TezTech / eztz

Tezos JS Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does origination work yet?

whaatt opened this issue · comments

I get weird syntax errors when I try to do eztz.contract.originate:

Failed to parse the request body: No case matched:
  At /kind, unexpected string instead of endorsement
  At /kind, unexpected string instead of seed_nonce_revelation
  At /kind, unexpected string instead of double_endorsement_evidence
  At /kind, unexpected string instead of double_baking_evidence
  At /kind, unexpected string instead of activate_account
  At /kind, unexpected string instead of proposals
  At /kind, unexpected string instead of ballot
  At /kind, unexpected string instead of reveal
  At /kind, unexpected string instead of transaction
  At /script/code, no case matched:
    Unexpected array instead of object
    Unexpected array instead of object
    Unexpected array instead of object
    At [2], no case matched:
      Missing object field int
      Missing object field string
      Missing object field bytes
      Unexpected object instead of array
      At /args[0], no case matched:
        Unexpected array instead of object
        Unexpected array instead of object
        Unexpected array instead of object
        At [3], no case matched:
          Missing object field int
          Missing object field string
          Missing object field bytes
          Unexpected object instead of array
          At /prim, unexpected string value "DUUP" instead of "ADD" , "LE" , "UNIT" , "timestamp" , "signature" , "COMPARE" , "LAMBDA" , "LOOP" , "Elt" , "IMPLICIT_ACCOUNT" , "NONE" , "set" , "pair" , "bytes" , "BLAKE2B" , "address" , "SHA256" , "XOR" , "RENAME" , "MAP" , "SET_DELEGATE" , "DIP" , "PACK" , "or" , "SIZE" , "Right" , "list" , "IF_CONS" , "LSR" , "TRANSFER_TOKENS" , "storage" , "UPDATE" , "CDR" , "SWAP" , "SOME" , "False" , "SHA512" , "CHECK_SIGNATURE" , "BALANCE" , "key_hash" , "unit" , "EMPTY_SET" , "SUB" , "MEM" , "RIGHT" , "ADDRESS" , "option" , "CONCAT" , "big_map" , "string" , "Unit" , "Some" , "UNPACK" , "NOT" , "LEFT" , "mutez" , "AMOUNT" , "DROP" , "ABS" , "bool" , "GE" , "PUSH" , "LT" , "operation" , "NEQ" , "NEG" , "None" , "CONS" , "EXEC" , "NIL" , "ISNAT" , "MUL" , "LOOP_LEFT" , "EDIV" , "SLICE" , "STEPS_TO_QUOTA" , "INT" , "SOURCE" , "CAR" , "CREATE_ACCOUNT" , "LSL" , "OR" , "IF_NONE" , "SELF" , "IF" , "Left" , "contract" , "map" , "SENDER" , "nat" , "DUP" , "EQ" , "NOW" , "key" , "GET" , "lambda" , "int" , "True" , "GT" , "parameter" , "IF_LEFT" , "FAILWITH" , "PAIR" , "ITER" , "Pair" , "CAST" , "EMPTY_MAP" , "CREATE_CONTRACT" , "HASH_KEY" , "CONTRACT" , "code" or "AND"
        Unexpected array instead of object
    Unexpected array instead of object
  At /kind, unexpected string instead of delegation
Failed to parse the request body: No case matched:
  At /kind, unexpected string instead of endorsement
  At /kind, unexpected string instead of seed_nonce_revelation
  At /kind, unexpected string instead of double_endorsement_evidence
  At /kind, unexpected string instead of double_baking_evidence
  At /kind, unexpected string instead of activate_account
  At /kind, unexpected string instead of proposals
  At /kind, unexpected string instead of ballot
  At /kind, unexpected string instead of reveal
  At /kind, unexpected string instead of transaction
  At /script/code, no case matched:
    Unexpected array instead of object
    Unexpected array instead of object
    Unexpected array instead of object
    At [2], no case matched:
      Missing object field int
      Missing object field string
      Missing object field bytes
      Unexpected object instead of array
      At /args[0], no case matched:
        Unexpected array instead of object
        Unexpected array instead of object
        Unexpected array instead of object
        At [3], no case matched:
          Missing object field int
          Missing object field string
          Missing object field bytes
          Unexpected object instead of array
          At /prim, unexpected string value "DUUP" instead of "ADD" , "LE" , "UNIT" , "timestamp" , "signature" , "COMPARE" , "LAMBDA" , "LOOP" , "Elt" , "IMPLICIT_ACCOUNT" , "NONE" , "set" , "pair" , "bytes" , "BLAKE2B" , "address" , "SHA256" , "XOR" , "RENAME" , "MAP" , "SET_DELEGATE" , "DIP" , "PACK" , "or" , "SIZE" , "Right" , "list" , "IF_CONS" , "LSR" , "TRANSFER_TOKENS" , "storage" , "UPDATE" , "CDR" , "SWAP" , "SOME" , "False" , "SHA512" , "CHECK_SIGNATURE" , "BALANCE" , "key_hash" , "unit" , "EMPTY_SET" , "SUB" , "MEM" , "RIGHT" , "ADDRESS" , "option" , "CONCAT" , "big_map" , "string" , "Unit" , "Some" , "UNPACK" , "NOT" , "LEFT" , "mutez" , "AMOUNT" , "DROP" , "ABS" , "bool" , "GE" , "PUSH" , "LT" , "operation" , "NEQ" , "NEG" , "None" , "CONS" , "EXEC" , "NIL" , "ISNAT" , "MUL" , "LOOP_LEFT" , "EDIV" , "SLICE" , "STEPS_TO_QUOTA" , "INT" , "SOURCE" , "CAR" , "CREATE_ACCOUNT" , "LSL" , "OR" , "IF_NONE" , "SELF" , "IF" , "Left" , "contract" , "map" , "SENDER" , "nat" , "DUP" , "EQ" , "NOW" , "key" , "GET" , "lambda" , "int" , "True" , "GT" , "parameter" , "IF_LEFT" , "FAILWITH" , "PAIR" , "ITER" , "Pair" , "CAST" , "EMPTY_MAP" , "CREATE_CONTRACT" , "HASH_KEY" , "CONTRACT" , "code" or "AND"
        Unexpected array instead of object
    Unexpected array instead of object
  At /kind, unexpected string instead of delegation

on the following Michelson:

parameter unit;
storage (pair string nat);
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DUUP @storage ;
       DUP ;
       CAR ;
       SWAP ;
       DROP ;
       DIP { DROP } ;
       PUSH nat 1 ;
       DUUUP ;
       DIIIP { DROP } ;
       CDR ;
       ADD ;
       SWAP ;
       PAIR @storage ;
       NIL operation ;
       PAIR };

The contract works if deployed directly from the tezos-client.

Here is my code (I have a fork at @whaatt/eztz that adds some small things to make EZTZ work in Node, like require-ing XMLHttpRequest:

const fs = require('fs')
const init = fs.readFileSync('helloworld.liq.init.tz', 'utf8')
const code = fs.readFileSync('helloworld.liq.tz', 'utf8')
console.log(init)
console.log(code)

const eztz = require('eztz').eztz
eztz.node.setProvider('http://127.0.0.1:18731')
const sk = 'edsk3gUfUPyBSfrS9CCgmCiQsTCHGkviBDusMxDJstFtojtc1zcpsh'
const keys = eztz.crypto.extractKeys(sk);

eztz.contract.originate(keys, 2000, code, init, false, false, null, 500)
  .then(console.log).catch(console.error)

Thanks!

Thanks so much - I do have a nodejs cli version, it's just not included in the build process - I'll merge your changes into that and get that posted as well (it usually lives in the dist folder).

Re michelson - the parsing script in eztz can't handle any of the syntactic macrons (e.g. DUUP, DIIP, CDAR etc). You can other manually change to DIP{DUP}; DIP{DIP{}}; etc.

One of the next major updates will be focusing on the Michelson compiler (to Micheline)

Thanks for the reply; that's what I originally figured. However, even after translating the syntactic macros (based on the output of tezos-client originate itself), I get the following error:

Failed to parse the request body: No case matched:
  At /kind, unexpected string instead of endorsement
  At /kind, unexpected string instead of seed_nonce_revelation
  At /kind, unexpected string instead of double_endorsement_evidence
  At /kind, unexpected string instead of double_baking_evidence
  At /kind, unexpected string instead of activate_account
  At /kind, unexpected string instead of proposals
  At /kind, unexpected string instead of ballot
  At /kind, unexpected string instead of reveal
  At /kind, unexpected string instead of transaction
  At /script/code, no case matched:
    Unexpected array instead of object
    Unexpected array instead of object
    Unexpected array instead of object
    At [2], no case matched:
      Missing object field int
      Missing object field string
      Missing object field bytes
      Unexpected object instead of array
      At /args[0], no case matched:
        Unexpected array instead of object
        Unexpected array instead of object
        Unexpected array instead of object
        At [3], no case matched:
          Missing object field int
          Missing object field string
          Missing object field bytes
          Unexpected object instead of array
          At /prim, unexpected string value "" instead of "ADD" , "LE" , "UNIT" , "timestamp" , "signature" , "COMPARE" , "LAMBDA" , "LOOP" , "Elt" , "IMPLICIT_ACCOUNT" , "NONE" , "set" , "pair" , "bytes" , "BLAKE2B" , "address" , "SHA256" , "XOR" , "RENAME" , "MAP" , "SET_DELEGATE" , "DIP" , "PACK" , "or" , "SIZE" , "Right" , "list" , "IF_CONS" , "LSR" , "TRANSFER_TOKENS" , "storage" , "UPDATE" , "CDR" , "SWAP" , "SOME" , "False" , "SHA512" , "CHECK_SIGNATURE" , "BALANCE" , "key_hash" , "unit" , "EMPTY_SET" , "SUB" , "MEM" , "RIGHT" , "ADDRESS" , "option" , "CONCAT" , "big_map" , "string" , "Unit" , "Some" , "UNPACK" , "NOT" , "LEFT" , "mutez" , "AMOUNT" , "DROP" , "ABS" , "bool" , "GE" , "PUSH" , "LT" , "operation" , "NEQ" , "NEG" , "None" , "CONS" , "EXEC" , "NIL" , "ISNAT" , "MUL" , "LOOP_LEFT" , "EDIV" , "SLICE" , "STEPS_TO_QUOTA" , "INT" , "SOURCE" , "CAR" , "CREATE_ACCOUNT" , "LSL" , "OR" , "IF_NONE" , "SELF" , "IF" , "Left" , "contract" , "map" , "SENDER" , "nat" , "DUP" , "EQ" , "NOW" , "key" , "GET" , "lambda" , "int" , "True" , "GT" , "parameter" , "IF_LEFT" , "FAILWITH" , "PAIR" , "ITER" , "Pair" , "CAST" , "EMPTY_MAP" , "CREATE_CONTRACT" , "HASH_KEY" , "CONTRACT" , "code" or "AND"
        Unexpected array instead of object
    Unexpected array instead of object
  At /kind, unexpected string instead of delegation

Any ideas what this might be? This is my new Michelson:

parameter unit ;
storage (pair string nat) ;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       { DIP { DUP @storage } ; SWAP } ;
       DUP ;
       CAR ;
       SWAP ;
       DROP ;
       DIP { DROP } ;
       PUSH nat 1 ;
       { DIP { DIP { DUP } ; SWAP } ; SWAP } ;
       { DIP { DIP { DIP { DROP } } } } ;
       CDR ;
       ADD ;
       SWAP ;
       PAIR @storage ;
       NIL operation ;
       PAIR } }

@storage - the parser can't handle the naming convention as well

Ah, I see. Is there an easy workaround? (Apologies for my poor knowledge of Michelson, the project I'm working on is compiling from Liquidity.) If not, I'll use tezos-client to deploy in the meantime until the parser is upgraded.

I went through and did the folllowing:

  • Removed the @ annotations
  • Removed the root level {} (e.g. change {DIP{...}}; to DIP{};

The new code I have is:

parameter unit ;
storage (pair string nat) ;
code { DUP ;
       DIP { CDR } ;
       CAR ;
       DIP { DUP } ; SWAP ;
       DUP ;
       CAR ;
       SWAP ;
       DROP ;
       DIP { DROP } ;
       PUSH nat 1 ;
       DIP { DIP { DUP } ; SWAP } ; SWAP ;
       DIP { DIP { DIP { DROP } } } ;
       CDR ;
       ADD ;
       SWAP ;
       PAIR ;
       NIL operation ;
       PAIR } }

It seems to validate ok:
eztz.rpc.typecheckCode(parameter unit ; storage (pair string nat) ; code { DUP ; DIP { CDR } ; CAR ; DIP { DUP } ; SWAP ; DUP ; CAR ; SWAP ; DROP ; DIP { DROP } ; PUSH nat 1 ; DIP { DIP { DUP } ; SWAP } ; SWAP ; DIP { DIP { DIP { DROP } } } ; CDR ; ADD ; SWAP ; PAIR ; NIL operation ; PAIR } }).then(console.log)

This should work for originating as well.

Yup, works! Thanks for the help! (Also, excited for future updates to eztz.)

@whaatt can you share what you've got in your init file?

(Pair "hello world" 0)

thanks @whaatt