-
Notifications
You must be signed in to change notification settings - Fork 41
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
Allow construction of new objects #981
Comments
What is the motivation for those constructors? Any example ? Why BigInt is in the list? |
You already can do bigInt("") For compile-time creation of objects of (AvlTree, Header, Box, BigInt, GroupElement) you can use deserializeRaw from hardcoded bytes. Creating header from fields in runtime ? Any useful example ? |
The motivation is to have single ErgoTree encoding for different use cases. CreateAvlTree is one example. Another is BigInt maybe not the best example, as there is already |
This only allow constant argument, where as NewObject will allow any expressions in arguments. |
yes, key words are
|
I guess these constructors can be done on the compiler level anyway, so under the hood the compiler will replace a constructor with expression which is building a bytestring and then do Thus I am moving it to 6.x |
So, of some arguments come from GetVar, then they should be serialized and then concatenated to the rest of the bytes? And this will happen during contract execution? |
It depends on usage, I haven't seen any use-case still. Especially considering that in practice you can go the other way, so instead of constructing e.g. a box with certain fields, expect for a box being provided and then calculate predicates over its fields (which is what most of apps are doing btw) |
I described the usecase where parameters can come from different sources. And the most natural way is to have constructor call. |
But where do you need for constructing e.g. box from multiple sources instead of checking a box of interest ? Even smaller chance to find an use case for a header. |
I have wanted to make a reusable function with an option as parameter, which works fine when feeding it the result of an option producing function, but sometimes it is an actual value and creating a Some out of that would be nice. |
cmon, what kind of argument it is? Users found use cases for almost all language features I've put into the language. The same is here, NewObject is generic feature which will work for any type. |
As no use-cases provided, I can move it to 7.0 or leave for 6.x. Frontend only implementation looks promising, as it is better not to touch consensus-critical level when possible |
No use case for Header, but what about AvlTree, which we started from. |
For AvlTree byte machinery is not hard:
so here you have fields coming from different sources etc the example is artificial though, as in practice (keyLength, valueLength) are coming from the same source as digest |
To your point, if they come say from a register as AvlTree, then
The this examples not only much easier to understand/read, but also always works, while your code is only good while values fit into single bytes, user need to take care about format, and also know how to encode. |
But there is simpler solution:
|
Yes, that is because AvlTree have only fields. |
updateOperations(flags) is constructing an object, and then you can call any tree method on it |
Problem
Currently there is no way in ErgoScript to create objects of pre-defined types such as AvlTree, Header, Box, etc. It is possible to introduce new objects only by deserializing from context var or from register.
But this is very limited approach and more like a workaround.
Solution
NewObject[T <: SType](args: Seq[SValue], tpe: T) extends Value[T]
operation to ErgoTree which constructs a new object from args by calling the default constructor.val tree = AvlTree(digest, flags, keyLength, valueLength)
i.e. the same way constructors are called in Scala3 by using type name.The text was updated successfully, but these errors were encountered: