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

Enable ordered outputs for OP_RETURN use cases (SLP...) #298

Merged
merged 4 commits into from
May 22, 2023

Conversation

PiRK
Copy link
Collaborator

@PiRK PiRK commented May 19, 2023

#272 implemented shuffling of outputs in transactions, with no consideration for the type of the output.

The previous implementation before that used a deterministic sorting based on the output amount and script, which by shear luck resulted in OP_RETURN outputs always being the first output because it has a zero amount.

This PR restores this behavior of putting the OP_RETURN always first, and adds a way to keep the other outputs sorted when using OP_RETURN. This is needed for crafting SLP transactions (see https://www.youtube.com/watch?v=TU1LBd9aVlc)

We want to be able to disable one without necessarily disabling the other.
@PiRK PiRK force-pushed the order_ouputs_if_op_returnwq branch from 9e0e50e to 325f82b Compare May 19, 2023 15:00
PiRK added 3 commits May 22, 2023 07:43
Using a namedtuple is an intermediate step before creating a proper class for this. It encapsulate the 3-tuples and makes the code easier to read (attributes rather than indices)

backport of spesmilo#4596 and removal of a bunch of code Transaction methods that are unused.
There are use cases that require the op_return to be the first output in a transaction (e.g. SLP), and I'm not aware of any use case that requires it to not be in that position.
The intended use case for this is sending SLP token using a hex encoded op_return payload.

Test plan:
Check that the new checkbox is only enabled if something is typed into the op_return payload field, and disabled when this payload is deleted.

Add multiple outputs in the send tab, leave the op_return field blank. Click "Preview" multiple times and make sure the outputs are shuffled (no matter if the new checkbox is checked or not).

Type something in the op_return field, and repeat the above test. Now the shuffling behavior must depend on the checkbox. The op_return output should always be first. The other outputs should be shuffled if the checkbox is checked. If it is unchecked, then the change output must be last, and preceded by the other outputs in the specified order.

Click send and check the order in a block explorer.
@PiRK PiRK force-pushed the order_ouputs_if_op_returnwq branch from 325f82b to 22b5d08 Compare May 22, 2023 05:43
@PiRK PiRK merged commit c5e62a6 into Bitcoin-ABC:master May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant