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

Refactoring send.rs by introducing transfer trait #3728

Closed

Conversation

twosatsmaxi
Copy link
Contributor

@twosatsmaxi twosatsmaxi commented May 5, 2024

Motivation

Catching bugs early for example:

Code Quality

  • More extensibility, for example, the most requested features in ordicord like splitting rune or send to many can have its own transfer trait implementation without bloating send.rs file.
  • Cleaner code, for example:
    • sending_inscription boolean can be moved out of the create_unsigned_send_satpoint_transaction method and to its trait implementation (not a big deal but just a bit cleaner code)
    • send.rs is now just 52 lines of code after the refactor and super readable ❤️

@onchainguy-btc
Copy link
Contributor

Maybe we can merge #3437 before? 👀 It allows for different features to be built on top like #3025 or #3640

@twosatsmaxi twosatsmaxi marked this pull request as ready for review May 7, 2024 13:46
@twosatsmaxi
Copy link
Contributor Author

twosatsmaxi commented May 8, 2024

@raphjaph @casey this ^ is ready for review now, no functionality changes, just refactoring.

@casey
Copy link
Collaborator

casey commented May 14, 2024

I personally don't think this is a huge increase in readability, since there's just more indirection in figuring out what's going on.

@casey casey closed this May 14, 2024
@twosatsmaxi
Copy link
Contributor Author

I personally don't think this is a huge increase in readability.

But do you think though that it's a bit more readable?

@twosatsmaxi
Copy link
Contributor Author

twosatsmaxi commented May 14, 2024

since there's just more indirection in figuring out what's going on.

It simplify things a bit for new folks who want to read about what's going on in send.rs.

@casey Some more Context on why I went ahead with this refactor: I wanted to implement the Even Split command for rune where I can split 10k of runes into 100 each, send.rs was a big and going through that code with different branches was lots of to-and-fro. If it had been like this, understanding what's going through would be much less time consuming for new contributors and can start checking in more features like split command quickly.

image

@twosatsmaxi
Copy link
Contributor Author

twosatsmaxi commented May 14, 2024

I feel that even if it adds a bit more readability and simplicity, there is no harm in checking in to main branch since all unit tests are passing, unless it adds more complexity, which I don't think so.

@twosatsmaxi
Copy link
Contributor Author

twosatsmaxi commented May 14, 2024

We were a way past "Rule Of Three" and the refactoring was a due in my opinion. Currently, there are 5 sends.

image

@casey
Copy link
Collaborator

casey commented May 14, 2024

To be clear: I closed this PR because I think it's a net negative and makes the code harder to read.

The rule of three is about deduplication. The PR is net +107 lines of code, and replaces a match statement which calls three different functions, with a trait with five different implementations. It is not deduplicating anything.

I think it's much worse and more complicated.

@casey
Copy link
Collaborator

casey commented May 14, 2024

This bug was fixed with a change to create_unsigned_send_runes_transaction. In this PR, this function was just moved from one place to another. I don't see that would have helped find that bug.

  • More extensibility, for example, the most requested features in ordicord like splitting rune or send to many can have its own transfer trait implementation without bloating send.rs file.

Having six functions in a file is fine.

  • send.rs is now just 52 lines of code after the refactor and super readable ❤️

It's super readable, but reading it doesn't tell you anything about what it does.

@twosatsmaxi
Copy link
Contributor Author

twosatsmaxi commented May 14, 2024

The PR is net +107 lines of code.

but does # of lines code really matter in such cases? # of lines of code would increases if a piece of code is moved to different files with new imports, new functions definitions, empty lines tends to add to net # of loc.

In this PR, this function was just moved from one place to another.

The function wasn't moved to another place as is, only just implementation was moved. The function method signature was changed to adhere to method contract create_unsigned_transaction in the transfer trait.

This bug (the postage not being used for send runes) was fixed with a change to create_unsigned_send_runes_transaction. In this PR, this function was just moved from one place to another. I don't see that would have helped find that bug.

It's true that It wouldn't have helped finding that bug, but while writing the new "send rune" implementation itself, it would have enforced the author to use postage (due to trait contract for transer being there) In the absense of the transfer contract, there is no way to enforce/nudge that postage need to be used. The bug was later fixed by adding postage to create_unsigned_send_runes_transaction function here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants