Skip to content

Add a utility to conveniently create UTxO from the return of CIP30 api's getUtxos. #84

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

Merged
merged 2 commits into from
Sep 16, 2022
Merged

Add a utility to conveniently create UTxO from the return of CIP30 api's getUtxos. #84

merged 2 commits into from
Sep 16, 2022

Conversation

mrvfino
Copy link
Contributor

@mrvfino mrvfino commented Sep 13, 2022

This PR is to:

  • make it easier to convert the utxos coming from the frontend via CIP30 api

I got this idea while looking for a way to save on blockfrost api calls, & a way to get utxos from the account itself to use in the tx builder as an alternative to add_input_address when an unused address i provided.

@cffls
Copy link
Collaborator

cffls commented Sep 13, 2022

Thanks for raising this PR! Regarding the cbor of UTxO, is there a spec for it documented somewhere? I am wondering if it is specific to a frontend wallet.

@mrvfino
Copy link
Contributor Author

mrvfino commented Sep 15, 2022

Hi @cffls!

Is this it?https://cips.cardano.org/cips/cip30/#apigetutxosamountcborvalueundefinedpaginatepaginateundefinedpromisetransactionunspentoutputnull

Based on my understanding, all frontend wallets that are CIP30 compatible should follow the same return.

EDIT: Perhaps the function could have better naming, yes? like convert_from_CIP30_cbor

@cffls
Copy link
Collaborator

cffls commented Sep 15, 2022

Thanks @markrufino ! I think this could be simplified by making UTxO as a child class of ArrayCBORSerializable, something like this:

@dataclass(repr=False)
class UTxO(ArrayCBORSerializable):
    ...
    # rest of the code will be the same

and you will be able to deserialize a UTxO cbor string like the following:

utxo = UTxO.from_cbor(my_cbor_string)

If you can provide me with a CBOR string example, I am happy to test it.

@mrvfino
Copy link
Contributor Author

mrvfino commented Sep 16, 2022

Interesting, let me try that as well. Thanks @cffls!

Also, here are some sample cbor strings.

[
    "828258207e4858f94be25d27e5d12ec779c5ace21f97f5051785ce90c3031685bb86eff40082583901316762a13a4587945d254cf8d35621d98c60ce739ad5d2d88e2955070c552e116f1f0bb17ea6bdcaa3d6c26abc77012f4286554173451d261a25ab8e00",
    "82825820b07182d18ee49f02908bf7c92b2fc25027c2d43f6c83a0cf3bd082f5a10f5d0a0082583901316762a13a4587945d254cf8d35621d98c60ce739ad5d2d88e2955070c552e116f1f0bb17ea6bdcaa3d6c26abc77012f4286554173451d261a054e0840"
]

Stake key of the owning account just in case you need it: stake1uyx92ts3du0shvt7567u4g7kcf4tcacp9apgv42pwdz36fs80m0r0

@cffls
Copy link
Collaborator

cffls commented Sep 16, 2022

Thanks! Looks like it works:

>>> UTxO.from_cbor("828258207e4858f94be25d27e5d12ec779c5ace21f97f5051785ce90c3031685bb86eff40082583901316762a13a4587945d254cf8d35621d98c60ce739ad5d2d88e2955070c552e116f1f0bb17ea6bdcaa3d6c26abc77012f4286554173451d261a25ab8e00")
{'input': {
  'index': 0,
  'transaction_id': TransactionId(hex='7e4858f94be25d27e5d12ec779c5ace21f97f5051785ce90c3031685bb86eff4'),
},
 'output': {
  'address': addr1qyckwc4p8fzc09zay4x0356ky8vcccxwwwddt5kc3c542pcv25hpzmclpwchaf4ae23adsn2h3mszt6zse25zu69r5nqhnmggr,
  'amount': {'coin': 632000000, 'multi_asset': {}},
  'datum': None,
  'datum_hash': None,
  'script': None,
}}

>>> UTxO.from_cbor("82825820b07182d18ee49f02908bf7c92b2fc25027c2d43f6c83a0cf3bd082f5a10f5d0a0082583901316762a13a4587945d254cf8d35621d98c60ce739ad5d2d88e2955070c552e116f1f0bb17ea6bdcaa3d6c26abc77012f4286554173451d261a054e0840")
{'input': {
  'index': 0,
  'transaction_id': TransactionId(hex='b07182d18ee49f02908bf7c92b2fc25027c2d43f6c83a0cf3bd082f5a10f5d0a'),
},
 'output': {
  'address': addr1qyckwc4p8fzc09zay4x0356ky8vcccxwwwddt5kc3c542pcv25hpzmclpwchaf4ae23adsn2h3mszt6zse25zu69r5nqhnmggr,
  'amount': {'coin': 89000000, 'multi_asset': {}},
  'datum': None,
  'datum_hash': None,
  'script': None,
}}

@mrvfino
Copy link
Contributor Author

mrvfino commented Sep 16, 2022

@cffls that's great! I think we can close this then.

@cffls
Copy link
Collaborator

cffls commented Sep 16, 2022

We still this change below to make it work:

@dataclass(repr=False)
class UTxO(ArrayCBORSerializable):
    ...
    # rest of the code will be the same

If you want to contribute to the project, you can modify this PR to use this change. :D Otherwise, I will add this change in the next release.

@mrvfino
Copy link
Contributor Author

mrvfino commented Sep 16, 2022

@cffls I will do add it in then! Haha would really love to be a contributor for a project I enjoy using.

EDIT: pushed the minor change! :D

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.

Thank you for contributing!

@cffls cffls merged commit 8c6b401 into Python-Cardano:main Sep 16, 2022
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.

2 participants