pycardano
pycardano copied to clipboard
Add wallet classes
This is still a WIP but I wanted to get the ball rolling on this! Lots of basic functionality is now here, along with the first few tests and examples. See /examples/wallet.py for some examples of the most basic functionality.
Current capabilities:
- [x] Generate keys
- [x] Load keys
- [x] Query utxos
- [x] Send ada
- [x] Send specific UTxOs
- [x] Get senders of all UTxOs
- [x] Get metadata for all held tokens
- [x] Get utxo block times and sort utxos
- [x] Mint / Burn tokens
- [x] Automatically load in token polices where wallet is a signer
- [x] Automatically create BlockFrost Chain Context (mainnet, preprod, and preview)
- [x] Attach messages to transactions
- [x] Sign messages
- [x] Add custom metadata fields
- [x] Multi-output transactions
- [x] Register wallet
- [x] Stake wallet
- [x] Withdraw rewards
- [x] Generate fully manual transactions that can do any / all of the above
- [x] Integrate strict type checking
- [ ] Write tests
- [ ] Add more examples
Future additions (possibly later PRs):
- [ ] Draft and sign multi-sig transactions
- [ ] Interaction with native scripts
- [ ] Interaction with plutus scripts
- [ ] Load wallets with mnemonic phrase (integrating
HDWallet)
Now currently figuring out how to write tests for the transaction methods, using test_transaction.py for inspiration.
Hi Jerry,
Thanks for the helpful review. I concur with everything suggested and I especially like using the decorator for blockfrost-only contexts. I'll make the changes soon.
And my apologies about the formatting, I often forget 😅
Thanks again!
Codecov Report
Attention: Patch coverage is 67.62115% with 294 lines in your changes missing coverage. Please review.
Project coverage is 80.88%. Comparing base (
2bb4820) to head (22583c3).
| Files | Patch % | Lines |
|---|---|---|
| pycardano/wallet.py | 67.08% | 220 Missing and 72 partials :warning: |
| pycardano/backend/blockfrost.py | 33.33% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #89 +/- ##
==========================================
- Coverage 83.98% 80.88% -3.10%
==========================================
Files 29 30 +1
Lines 3733 4636 +903
Branches 941 1229 +288
==========================================
+ Hits 3135 3750 +615
- Misses 433 650 +217
- Partials 165 236 +71
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
In reference to commit c30fba1: @cffls I have the code generate wallet keys using the format:
name.skey name.vkey name.stake.skey name.stake.vkeyThis is to make it easy for a wallet to load unique staking keys. Let me know what you think of this format.
Thinking about this more I now realize I should also add kwargs so one can directly specify the path to each for the four keyfiles individually.
The naming looks good to me. Thank you!
Great, thanks! I believe I've addressed all the comments for now. Next step is to write more tests. I'll have to look in detail at the ones you've already written for how to properly test functions that are meant to submit transactions to the chain.
Great, thanks! I believe I've addressed all the comments for now. Next step is to write more tests. I'll have to look in detail at the ones you've already written for how to properly test functions that are meant to submit transactions to the chain.
Nice! You can take a look at integration tests, where a local chain will be created through docker compose and you can submit a bunch of real transactions to the chain.
FYI, the main branch now enforces stronger type hint in the Github ci/cd pipeline.
I would advise rebasing this branch on top of the latest main branch to ensure the newly added wallet.py module passes all static analyses.
Done! I will work on straightening out the type hints, thank you!
Hey Jarred,
thanks for the big chunk of new features! Looks very promising to me!
However, I'd like to bring one thing up for a discussion...
You are introducing a new class Wallet as part of the public API. I like that because it is abstracting a lot of things which makes it easy to use.
Now here is what caught my eye. For some weeks now we also have a class HDWallet https://github.com/Python-Cardano/pycardano/blob/88894e2cc97a8b01fed9a9fc99f2ff2861beac4b/pycardano/crypto/bip32.py#L78. Without looking into the details I would not understand why do we have Wallet and HDWallet and they don't provide the same / a similar interface.
First of all I am wondering what your thoughts are regarding the two in regards to the user/developer experience.
Secondly, I am wondering if it makes sense to extend the high-level Wallet class to support HDWallet keys (out of scope for this PR).
Happy to hear what you're going to say :)
Hi @robinboening,
Thanks for pointing out the HDWallet class. I think it would be a really nice idea to integrate into Wallet. I think some might appreciate the option to create a wallet using a mnemonic or having full control over the generation of keys, so I don't think it's out of scope for this class. I've updated the todo list above to specify the integration of HDWallet. In the end it might come in another PR later but I think it would be really nice to include.
Quick update-- I've finally managed to integrate mypy so that the checks do not fail anymore. In addition I've gotten coverage up to ~44%. Still some tests to write but I'm closing in on this. 🔜
How can I help with this? I can't see the logs for the failed checks as it was too long ago. I am working on a project that would benefit from having the wallet stuff abstracted away into PyCardano.
@KINGH242 that's great! This PR is staled and I completely forget about it.. I think a few type checks are failing. If those are fixed we should be able to merge it.
Hey all, I dropped the ball a bit on this one!
I think I got stuck with test writing-- I recall that I mainly had trouble with the mocking of the blockfrost API and tx submission as it's something I had no experience with.
Also happy to help out wherever possible and finally get this done.
Hey @astrojarred, I added some test and fixed a few things to allow it to work with the latest changes. I submitted a PR here https://github.com/astrojarred/pycardano/pull/33