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

feat: use SDK type for tx in TransactionResponse #960

Merged
merged 9 commits into from
Jun 9, 2023

Conversation

MujkicA
Copy link
Contributor

@MujkicA MujkicA commented May 12, 2023

Closes #959

I've explored several approaches to make our API consistent here.

One option was to have TransactionResponse hold a `Box, but because of the object safety requirements, this had the following downsides:

  • No Into<FuelTransaction> super trait possible, this would need to become a separate method
  • TransactionResponse would no longer be Clone
  • Box needs to be cloned internally to keep with_ methods + a Box would have to be returned which could cause confusion
  • And the worst one, a user would need to downcast the tx from a TransactionResponse to either Script or Create

The second option was to use an enum for the implementors of Transaction and then have the enum implement it too. The downside here is that we get a lot of repeated match statements to delegate every method of Transaction to the corresponding variant. Macros didn't provide a significant improvement here either.

Ultimately I decided to keep the enum but not implement Transaction for it. This means that we don't change our API anywhere else but also that the user has to potentially match the enum every time to use the underlying Transaction methods.

Checklist

  • I have linked to any relevant issues.
  • I have added necessary labels.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@MujkicA MujkicA added the enhancement New feature or request label May 12, 2023
@MujkicA MujkicA self-assigned this May 12, 2023
@MujkicA MujkicA requested a review from a team May 12, 2023 11:56
@MujkicA MujkicA changed the title add TransactionType enum feat: add TransactionType enum May 12, 2023
@MujkicA MujkicA changed the title feat: add TransactionType enum feat: use SDK type for tx in TransactionResponse May 12, 2023
hal3e
hal3e previously approved these changes May 12, 2023
Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Br1ght0ne
Br1ght0ne previously approved these changes May 12, 2023
iqdecay
iqdecay previously approved these changes May 19, 2023
Copy link
Contributor

@iqdecay iqdecay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't make up my mind. Hate that the user has to always match before doing anything useful with the type.

But then again I can imagine how ugly the delegation might have looked.

Besides the impact on maintenance cost, is there any other reason for not implementing the delegating methods so that it may be used as is?

@iqdecay
Copy link
Contributor

iqdecay commented May 20, 2023

Can't make up my mind. Hate that the user has to always match before doing anything useful with the type.

Good catch, didn't realise myself. I'd like to know as well before merging.

@hal3e
Copy link
Contributor

hal3e commented Jun 1, 2023

@FuelLabs/sdk-rust did we decide what to do with this PR ?

@MujkicA MujkicA requested a review from Salka1988 as a code owner June 5, 2023 10:12
@MujkicA MujkicA dismissed stale reviews from hal3e, iqdecay, and Br1ght0ne via 27c0adb June 6, 2023 14:46
@MujkicA
Copy link
Contributor Author

MujkicA commented Jun 6, 2023

Can't make up my mind. Hate that the user has to always match before doing anything useful with the type.

But then again I can imagine how ugly the delegation might have looked.

Besides the impact on maintenance cost, is there any other reason for not implementing the delegating methods so that it may be used as is?

It was only about the maintenance. IMO matching isn't that bad considering that this type is only used when fetching a TransactionResponse. I imagine that's not that common of a use case.

The last commit has the changes with delegation.

Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be confusing down the line to have Transaction trait and TransactionType type

But we'll solve it if it becomes an issue.

Copy link
Member

@Salka1988 Salka1988 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MujkicA MujkicA merged commit f41dd3a into master Jun 9, 2023
@MujkicA MujkicA deleted the mujkica/use-fuels-tx-for-tx-response branch June 9, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TransactionResponse uses fuel_tx Transaction type
6 participants