-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
No Script #438
Conversation
My motivation for this is mostly interchange between libraries. I wanted to be able to agnostically work with scripts, and yet most of the |
All of the assert changes / typeforce changes to this PR makes this more painful to review... granularity ftw :) While I've always thought Script was a useful abstraction, I understand the motivation, especially regarding interoperability. So I am OK with this. Would like to know what @weilu thinks. |
Did you check the comparison link? (See noassert...noscript) |
Waiting on ACK for #434 before merge. |
return compile(chunks) | ||
} | ||
|
||
function compile (chunks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the name compile
/decompile
come from? Would it help inferring the input and output types better by calling them chunkArrayToBuffer
and bufferToChunkArray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chunks
are essentially uncompiled byte code, which is then compiled to a Buffer
for serialization in a Transaction
.
Seeing as we have to parse a Buffer
to de-serialize it, using the OP_CODE
byte codes, it seemed like a fitting analogy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my point of view, it's not obvious what are the input and output types just by reading the function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A script
in this sense should be synonymous with a Buffer
.
In all cases a Script
was a valid, a Buffer
should now be used.
compile
is the only exception to this, it takes an Array
of chunks to be serialized into a Buffer
.
chunks
are the byte codes in their uncompiled form.
toASM
takes a Buffer
and transpiles it back to its human readable equivalent (ASM).
fromASM
takes a string of human readable opcodes (ASM) and compiles it to a Buffer
.
For internal usage and performance reasons, it is also possible to interchangeably use a chunks
Array
to avoid constant decompilation/compilation.
Overall this change does enable the use of primitive/native types, but at the cost of abstraction. It used to be Script is an abstraction with two forms of representation -- chunks and buffer. Now that's no longer the case. I personally still find the version with the Script abstraction easier to reason, but it could be just me. |
Granted I don't work with script enough, so if @dcousens feels strong enough to merge this, then go ahead :) |
After further discussion of I think if we are going to change The questions I wonder then, are there any other places where the return type is ambiguous? Should we being doing this consistently? How much is this just a symptom of there being no documentation? |
Rebased on master |
All nits/tests fixed. |
|
Ref: #407 (comment)
Overall, this is part of #407.
The performance is the same, we just stopped using
Script
as a data interchange.You are now either explicitly dealing with the decompilation result of a script (aka, chunks) after a
scripts.decompile
, or you are dealing with aBuffer
which is a script.This also means you can now pass your script directly to
Transaction
without having to decompile it first.I also merged
Script
andscripts
, which makes the interface smaller and cleaner IMHO, open to feedback though.Chained on #434 , but not dependent.
Comparison link: noassert...noscript