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

Reference UTxOs are UTxOs (not TransactionInputs) #181

Merged
merged 3 commits into from
Mar 18, 2023

Conversation

nielstron
Copy link
Contributor

Reference UTxOs have been so much requested by Smart Contract developers because they grant the Smart Contract access to the content (i.e. corresponding output, datums, scripts) of the referenced input.

This implies that the whole UTxO is actually required to build the ScriptContext properly. This PR changes the structure of the TxBuilder class such that it stores the entire reference UTxO instead of just the TransactionInput, enabling generating the ScriptContext for redeemers from it (see OpShin/opshin#92)

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2023

Codecov Report

Merging #181 (f284423) into main (8f29313) will decrease coverage by 0.45%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #181      +/-   ##
==========================================
- Coverage   86.23%   85.78%   -0.45%     
==========================================
  Files          26       26              
  Lines        2767     2814      +47     
  Branches      655      672      +17     
==========================================
+ Hits         2386     2414      +28     
- Misses        287      296       +9     
- Partials       94      104      +10     
Impacted Files Coverage Δ
pycardano/txbuilder.py 90.49% <100.00%> (-0.15%) ⬇️

... and 7 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines 109 to 108
reference_inputs: Set[TransactionInput] = field(
init=False, default_factory=lambda: set()
)
reference_inputs: List[UTxO] = field(init=False, default_factory=lambda: list())
Copy link
Collaborator

@cffls cffls Mar 16, 2023

Choose a reason for hiding this comment

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

This will be a backward-imcompatible change. The reason of using set was to avoid input duplication. What do you think of changing the type to Set[Union[TransactionInput, UTxO]] or Union[Set[TransactionInput], Set[UTxo]] instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I resolve the duplication when building the tx. I think UTxOs are not hashable either.

Copy link
Collaborator

Choose a reason for hiding this comment

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

UTxOs are in fact hashable:

def __hash__(self):
return hash(
blake2b(self.input.to_cbor("bytes") + self.output.to_cbor("bytes"), 32)
)

It would be less amount of change to keep using Set as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I will make it a Set of UTxOs.

If we allow Union[TransactionInput, UTxO] we need to filter out again later too. Also building the ScriptContext fails then. But it could be desirable if someone just wants to make sure another transaction is in the UTxO while this tx is being processed.

Copy link
Collaborator

@cffls cffls left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for making this change!

@cffls cffls merged commit 985a2b6 into Python-Cardano:main Mar 18, 2023
@cffls cffls added the enhancement New feature or request label Mar 29, 2023
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.

3 participants