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

Add type parameter to fromBase16 #814

Open
aslesarenko opened this issue Jun 25, 2022 · 0 comments
Open

Add type parameter to fromBase16 #814

aslesarenko opened this issue Jun 25, 2022 · 0 comments
Labels
A-frontend Area: ErgoScript compiler (source -> ErgoTree) P2-medium Priority: Medium
Milestone

Comments

@aslesarenko
Copy link
Member

aslesarenko commented Jun 25, 2022

The task is to generalize existing implementation of fromBase16 to allow embedding of arbitrary constants in ErgoScript sources.

val c = fromBase16[(Coll[Byte], Int)]("<base 16 string>")
c._1.size > 0 && x._2 > 0

Implementation hints:

  • You need to implement PredefinedFunc("fromBase16", correctly (generalize existing implementation)
    See val DeserializeFunc = PredefinedFunc("deserialize",
    for an example of how to obtain SType value for the type T.
  • The type T should already be parsed by the parser.
  • there is already Base16 decoder, you can reuse is to get decodedBytes from String.
  • Then having decodedBytes and tpe: SType for T you can use ConstantSerializer to parse the bytes to obtain a value of type T ( as instance of ConstantNode(value, tpe))
@aslesarenko aslesarenko added A-frontend Area: ErgoScript compiler (source -> ErgoTree) P2-medium Priority: Medium labels Jun 25, 2022
@aslesarenko aslesarenko added this to the v5.x milestone Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: ErgoScript compiler (source -> ErgoTree) P2-medium Priority: Medium
Projects
None yet
Development

No branches or pull requests

1 participant