-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add a utility to conveniently create UTxO from the return of CIP30 api's getUtxos. #84
Conversation
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. |
Hi @cffls! 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 |
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. |
Interesting, let me try that as well. Thanks @cffls! Also, here are some sample cbor strings.
Stake key of the owning account just in case you need it: stake1uyx92ts3du0shvt7567u4g7kcf4tcacp9apgv42pwdz36fs80m0r0 |
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,
}} |
@cffls that's great! I think we can close this then. |
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. |
@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 |
…creation from CBOR.
There was a problem hiding this 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!
This PR is to:
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.