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

Helper function to obtain the hash of a global constant #1206

Open roxaneletourneau opened 2 years ago

roxaneletourneau commented 2 years ago

As Taquito user, I want to calculate the hash of a global constant having its Michelson expression, so that I can easily retrieve the hash of an already registered expression.

Acceptance criteria:

Out of scope Validate if the expression is registered as a global constant.

Additional context To produce the hash: 1- forge the Michelson expression using valueEncoder from @taquito/local-forging 2- hash using blake2b + b58cencode + appends expr prefix (this can by done with encodeExpr from @taquito/utils)

example:

const forgedValue = valueEncoder({prim: "Pair", args: [{int:"999"},{int:"999"}]}) // 070700a70f00a70f
encodeExpr(forgedValue) // exprvNeeFGy8M7xhmaq7bkQcd3RsXc7ogv2HwL1dciubXdgPHEMRH2
dsawali commented 2 years ago

Hello @roxaneletourneau, what would be the expected behaviour if the util function receives an empty Michelson expression, is that even a scenario we would like to take into account?

roxaneletourneau commented 2 years ago

Hi @dsawali, I suggest throwing an exception if the expression is empty.

dsawali commented 2 years ago

The implementation of this function currently depends on the valueEncoder() function in the @taquito/local-forging package. Importing that function creates a circular dependency which results in the build failing.

Rewriting the valueEncoder() function in @taquito/utils would result in duplication of code.

This issue will be put back into the ready for work pile until a more elegant solution is formulated