forked from rust-bitcoin/rust-bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use swap hack rather than hidden public API #7
Draft
Kixunil
wants to merge
8
commits into
tcharding:08-13-script-buf
Choose a base branch
from
Kixunil:script-buf-ext-alternative-design
base: 08-13-script-buf
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Use swap hack rather than hidden public API #7
Kixunil
wants to merge
8
commits into
tcharding:08-13-script-buf
from
Kixunil:script-buf-ext-alternative-design
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In preparation for moving the `ScriptBuf` as a plain old datatype to `primitives`; separate the POD methods into their own impl block. Refactor only, no logic changes.
Before we can move the `ScriptBuf` to `primitives` we need a few ways to mutate the inner vector, currently done by accessing `.0`. Add `push`, `pop`, and `extend_from_slice`. Hide them from the docs and comment that they are not really supposed to be used.
In preparation for adding a private `ScriptBufExtPriv` trait, move the private methods to a separate impl block. Make the `push_slice_no_op` method have the same visibility as the others so that the change in scope does not get hidden in the upcoming patch that introduces the trait. (Note this is basically just a code move and the diff shows move of other methods not the private ones.)
As we did before with `Script`; `rustfmt` does not indent stuff in macros so in preparation for adding extension traits using a macro temporarily wrap the impl blocks in modules so we can run the formatter in a patch on its own.
Run `cargo +nightly fmt`, no other changes.
The `define_extension_trait` cannot be easily extended to handle our current usage of `AsRef<PushBytes>` generic. We can achieve almost the same thing with the `impl` syntax. Note that this is a breaking change because with this change turbo fish syntax is no longer possible.
In preparation for moving the `ScriptBuf` type to the `primitives` crate; introduce two `ScriptBuf` extension traits, one public and one private. Note, the private extension trait has `pub(crate)` where as before this patch was applied we use `pub(in crate::script)`. This is because the macro doesn't handle the latter syntax. Note also, that the build failure when `ScriptBuf::from_hex` is not found may be confusing because of the history of `from_hex` - users may go looking for a `FromHex` trait. We should keep this in mind when documenting how to use all the new extension traits.
A public API even if hidden has potential compatibility risks that we want to avoid. We could come up with better API but we can simply workaround it by temporarily swapping the script with an empty one, then modifying the vec and then swapping it back.
tcharding
reviewed
Aug 17, 2024
Comment on lines
244
to
245
self.as_byte_vec().pop(); | ||
self.push_opcode(opcode); |
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.
That's some trickery - nice one!
tcharding
force-pushed
the
08-13-script-buf
branch
4 times, most recently
from
August 19, 2024 23:36
836a226
to
2bb90b8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I felt like writing up the change. You probably want to incorporate it into previous history rather than leaving things change back and forth.
A public API even if hidden has potential compatibility risks that we want to avoid. We could come up with better API but we can simply workaround it by temporarily swapping the script with an empty one, then modifying the vec and then swapping it back.