Skip to content

Add wallet classes #89

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

Open
wants to merge 146 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
f690c16
Add beginnings of easy class
astrojarred Jun 29, 2022
c76a8ff
Rename base Amount class
astrojarred Jun 29, 2022
58647e7
Update Imports
astrojarred Jul 1, 2022
f27b750
Check Token metadata for issues
astrojarred Jul 1, 2022
c6646de
Automatically add blockfrost context if correct env vars are set
astrojarred Jul 1, 2022
2c5c5d6
Add methods for sending transactions
astrojarred Jul 1, 2022
ae84ee0
Start adding a mint token class
astrojarred Jul 2, 2022
21ee7a8
Add TokenPolicy class
astrojarred Jul 4, 2022
0e27088
Add bytes_name() to Token
astrojarred Jul 4, 2022
a025a95
Add message option to transactions
astrojarred Jul 4, 2022
8aa8d71
Add working token minter
astrojarred Jul 4, 2022
14ad5f0
Add id property to token policy
astrojarred Jul 4, 2022
85e3838
Remove policy datafield from Wallet
astrojarred Jul 4, 2022
17c1ce9
Add method to fetch conchain metadata for Tokens
astrojarred Jul 4, 2022
c87d906
Remove unneeded import
astrojarred Jul 4, 2022
72c98ad
Add method to get all wallet token metadata
astrojarred Jul 4, 2022
a3164de
Automatically load in all wallet policies for which it is a signer
astrojarred Jul 4, 2022
d6e2489
Get Wallet utxos block times and sort
astrojarred Jul 4, 2022
ed5d42b
Add burning capabilities to mint_tokens
astrojarred Jul 6, 2022
9f2238e
Merge branch 'cffls:main' into add-ease-classes
astrojarred Jul 6, 2022
eb89412
Merge branch 'cffls:main' into add-ease-classes
astrojarred Jul 7, 2022
dc2d9eb
Add full manual transactions
astrojarred Jul 14, 2022
d63666f
Allow return of signed tx without submission
astrojarred Jul 17, 2022
942cdff
Automatically create stake credentials
astrojarred Jul 17, 2022
1928fd5
Format with Black
astrojarred Jul 17, 2022
aeb0b1f
Support signing messages with stake keys
astrojarred Jul 17, 2022
a37319c
Update todo list
astrojarred Jul 17, 2022
30ea14b
Add script interaction
astrojarred Jul 17, 2022
08a5997
Update when stake keys are generated
astrojarred Jul 17, 2022
ea24571
Add Policy script property
astrojarred Jul 17, 2022
2bd2247
Rename sign message to sign data
astrojarred Jul 17, 2022
f551bd1
Change print to debug statement
astrojarred Jul 17, 2022
dabd052
Add example notebook
astrojarred Jul 17, 2022
4e9019f
Fix many type errors
astrojarred Jul 21, 2022
9a77f33
Add stake registration, delegation, and withdrawal
astrojarred Jul 21, 2022
0a8df7b
Add stake features to manual mode
astrojarred Jul 21, 2022
bd5e7f1
rename manual to transact
astrojarred Jul 21, 2022
91248d0
Merge branch 'cffls:main' into add-ease-classes
astrojarred Aug 16, 2022
4cabb3f
Fix some typos
astrojarred Aug 24, 2022
6599108
Start adding docstrings
astrojarred Aug 25, 2022
23053c7
Start commenting in the code
astrojarred Aug 29, 2022
997ed0f
Add all docstrings
astrojarred Aug 30, 2022
71ba3a5
Merge branch 'cffls:main' into add-ease-classes
astrojarred Aug 30, 2022
8bc0452
Update todo list
astrojarred Aug 30, 2022
1246584
Merge branch 'add-ease-classes' of https://github.com/astrojarred/pyc…
astrojarred Aug 30, 2022
15f341d
Fix typo in Token docs
astrojarred Sep 24, 2022
93be468
Merge branch 'cffls:main' into add-ease-classes
astrojarred Sep 24, 2022
a219f49
Fix typo is Ada.as_ada()
astrojarred Sep 25, 2022
d85d34d
Add first tests for Wallet class
astrojarred Sep 25, 2022
78cce6e
Catch non-integer lovelace values
astrojarred Sep 25, 2022
4214625
Add preview and preprod net functionality
astrojarred Sep 27, 2022
37e0a80
Update first methods to use transact directly
astrojarred Sep 27, 2022
0fc796d
Make outputs and optional param for transact
astrojarred Sep 27, 2022
eacc6ee
Update withdraw method to use transact
astrojarred Sep 27, 2022
ca916aa
Rewrite wallet minting method to use transact
astrojarred Sep 27, 2022
9ca4edc
Remove unfinished tests
astrojarred Sep 27, 2022
5d84148
Remove unused test functions
astrojarred Sep 27, 2022
bb2cc74
Add tests for wallet policy and token
astrojarred Sep 28, 2022
a4c010a
Fix order in which token policy is loaded
astrojarred Sep 28, 2022
b3b87c2
Set default amount to 0
astrojarred Sep 28, 2022
d92e2dc
Add method for auto burning tokens
astrojarred Sep 28, 2022
a4019ed
Update min lovelace calculations
astrojarred Sep 28, 2022
3ccf395
Update todo list
astrojarred Sep 28, 2022
4571579
Format with black
astrojarred Sep 28, 2022
0c88796
Remove example notebook
astrojarred Sep 28, 2022
76105b4
Add wallet example code
astrojarred Sep 28, 2022
01a454f
Add further clarification about transaction kwargs
astrojarred Sep 28, 2022
78b1095
Fix input bug on mint/burn tokens
astrojarred Oct 7, 2022
8ee307a
Fix bug in mint/burn input variable
astrojarred Oct 7, 2022
221b130
Add blockfrost context checker as function wrapper
astrojarred Oct 9, 2022
e6d2fb9
Convert Amount and subclasses to frozen dataclass
astrojarred Oct 9, 2022
b153ebd
Rename query_utxos to sync
astrojarred Oct 9, 2022
75b35a1
Rename withdraw to withdraw_rewards
astrojarred Oct 9, 2022
0f73616
Rename call of query_utxos to sync
astrojarred Oct 9, 2022
a7463cb
Remove all independent checks for BF chain context
astrojarred Oct 9, 2022
24081c6
Remove call of logging function
astrojarred Oct 9, 2022
005e552
import dataclass needed for Amount
astrojarred Oct 9, 2022
c237618
Remove another independent check for BF context
astrojarred Oct 9, 2022
dafa084
Remove final independent check for BF chain context
astrojarred Oct 9, 2022
1f0360d
Remove unused variable
astrojarred Oct 9, 2022
dd38172
Clean code and format with makefile
astrojarred Oct 9, 2022
9973e82
Format and clean code
astrojarred Oct 9, 2022
fc54cd0
Merge in utxo fix from remote
astrojarred Oct 9, 2022
f06c839
Push suggested fixes of PR89 review
astrojarred Oct 9, 2022
c30fba1
Add example payment staking keys under new names
astrojarred Oct 9, 2022
c2c8be8
Add last_block_slot to FixedChainContext
astrojarred Oct 23, 2022
4d002b2
Remove unnecessary math operators
astrojarred Oct 23, 2022
719a5f4
Create easily testable get_now() method
astrojarred Oct 23, 2022
abda6e1
Add coverage for Amount and TokenPolicy
astrojarred Oct 23, 2022
e8cf33d
Make signing a tx optional
astrojarred Oct 23, 2022
34d67fe
Add tests for token metadata
astrojarred Oct 23, 2022
5cacd41
Remove unused imports
astrojarred Oct 23, 2022
cb8166e
Return objects of wallet key hashes instead of str
astrojarred Oct 23, 2022
03a78d9
Merge branch 'Python-Cardano:main' into add-wallet-classes
astrojarred Oct 28, 2022
bdb72a3
Merge branch 'Python-Cardano:main' into add-wallet-classes
astrojarred Oct 30, 2022
6c2b440
Only add token policies if not already in tx
astrojarred Oct 30, 2022
671adc6
Fix bug in blockfrost_only function wrapper
astrojarred Oct 30, 2022
5b4e026
Replace 'sign' transaction parameter with 'build_only'
astrojarred Oct 30, 2022
a71bf4e
Add change address option to token burning
astrojarred Nov 4, 2022
8574e05
Add an example script which automatically mints a CIP-27 royalty token
astrojarred Nov 4, 2022
cef5535
Increase coverage of TokenPolicy and Token classes
astrojarred Nov 5, 2022
3f902cc
Format automatic royalty example
astrojarred Nov 5, 2022
ba1ec7d
Remove manual typecheck in Output class
astrojarred Nov 5, 2022
5a5514a
Add tests for Output class
astrojarred Nov 5, 2022
bbb77f7
Add test for wallet without stake
astrojarred Nov 5, 2022
bb4bda3
Remove unneeded if statement
astrojarred Nov 5, 2022
6e12a8c
Add tests for wallet init
astrojarred Nov 5, 2022
6dff7fc
Format code
astrojarred Nov 5, 2022
8495eb8
Remove blockfrost_only decorator in favor of strict typechecking
astrojarred Nov 13, 2022
9085077
Add tests for onchain token metadata
astrojarred Nov 13, 2022
91f0a6a
Add patching for mocking blockfost
astrojarred Nov 13, 2022
154b70b
Format
astrojarred Nov 13, 2022
ea4b818
Format
astrojarred Nov 13, 2022
53b0a3e
Merge branch 'Python-Cardano:main' into add-wallet-classes
astrojarred Nov 13, 2022
fe9cf8d
Merge branch 'add-wallet-classes' of https://github.com/astrojarred/p…
astrojarred Nov 13, 2022
8a83a8d
Format tests
astrojarred Nov 13, 2022
04dfdec
Add typechecking to all helper classes
astrojarred Nov 13, 2022
64df216
Change type hints from List to Sequence
astrojarred Nov 13, 2022
328d0dc
Merge branch 'Python-Cardano:main' into add-wallet-classes
astrojarred Nov 15, 2022
cb4bc51
Merge branch 'add-wallet-classes' of https://github.com/astrojarred/p…
astrojarred Nov 15, 2022
6801ada
Add strict typing with mypy
astrojarred Nov 15, 2022
a7cf5ce
Update native script typing with Sequence
astrojarred Nov 15, 2022
8f435d7
Test required signatures when non sig scripts are present
astrojarred Nov 16, 2022
e66fa81
Add __all__
astrojarred Nov 16, 2022
41de108
Add note about bad isinstance
astrojarred Nov 16, 2022
c93d327
Fix policy script not being passed properly to ttl
astrojarred Nov 25, 2022
527e818
Remove full address property
astrojarred Nov 25, 2022
b0afc63
Add Wallet.to_address method to return full addr
astrojarred Nov 25, 2022
2c9f400
Format with black
astrojarred Nov 25, 2022
17de247
Update usage of input parameters for TokenPolicy
astrojarred Nov 25, 2022
ab26c48
Test a policy with multiple conditions
astrojarred Jun 29, 2023
2cc0969
Test a policy with multiple conditions
astrojarred Jun 29, 2023
1f256fc
set wallet context to null to avoid auto-checking chain
astrojarred Jun 29, 2023
c948fbd
Try using the blockfrost patch to check chain
astrojarred Jun 29, 2023
efd1f3d
Merge remote-tracking branch 'upstream/main' into add-wallet-classes
astrojarred Jun 29, 2023
312a88f
Fix typechecking issue with getting stake address
astrojarred Jun 29, 2023
8021ebe
Format and style
astrojarred Jun 29, 2023
8c2860b
Remove burn tokens from outputs in mint transactions
astrojarred Aug 8, 2023
4c1cf9e
Remove burned tokens from output in burn transactions
astrojarred Aug 8, 2023
491747d
Merge branch 'main' into add-wallet-classes
cffls Jun 16, 2024
7d3ea22
lint: fix mypy issues
KINGH242 Jun 17, 2024
ef11f06
feat: add query stake address info to chain contexts
KINGH242 Jun 18, 2024
8cb1824
fix: use query stake address info and other minor fixes
KINGH242 Jun 18, 2024
f7b39d2
test: add some more tests around wallet
KINGH242 Jun 18, 2024
bf3bb79
test: add test for cli stake address info
KINGH242 Jun 18, 2024
22583c3
Merge pull request #33 from KINGH242/add-wallet-classes
astrojarred Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add typechecking to all helper classes
  • Loading branch information
astrojarred committed Nov 13, 2022
commit 04dfdec27f40b1ca97f1817a6a0f53b0c62af518
38 changes: 28 additions & 10 deletions pycardano/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from os import getenv
from pathlib import Path
from time import sleep
from typing import List, Literal, Optional, Union
from typing import List, Optional, Sequence, Union
from typing_extensions import Literal

from blockfrost import ApiError

Expand Down Expand Up @@ -280,7 +281,7 @@ class TokenPolicy:
"""

name: str
policy_id: Optional[str] = (None,)
policy_id: Optional[str] = None
script: Optional[Union[NativeScript, dict]] = field(repr=False, default=None)
policy_dir: Optional[Union[str, Path]] = field(
repr=False, default=Path("./priv/policies")
Expand Down Expand Up @@ -369,7 +370,13 @@ def is_expired(self, context: ChainContext):

def generate_minting_policy(
self,
signers: Union["Wallet", Address, List["Wallet"], List[Address]],
signers: Union[
"Wallet",
Address,
List["Wallet"],
List[Address],
List[Union["Wallet", Address]],
],
expiration: Optional[Union[datetime.datetime, int]] = None,
context: Optional[ChainContext] = None,
):
Expand All @@ -383,7 +390,10 @@ def generate_minting_policy(
context (Optional[ChainContext]): A context is needed to estimate the expiration slot from a datetime.
"""

script_filepath = Path(self.policy_dir / f"{self.name}.script")
if not self.script or not self.policy_dir:
raise TypeError("The script of this policy is not set.")

script_filepath = Path(self.policy_dir) / f"{self.name}.script"

if script_filepath.exists() or self.script:
raise FileExistsError(f"Policy named {self.name} already exists")
Expand All @@ -409,7 +419,12 @@ def generate_minting_policy(
else:
time_until_expiration = expiration - get_now()

last_block_slot = context.last_block_slot
if context:
last_block_slot = context.last_block_slot
else:
raise AttributeError(
"If input expiration is provided as a datetime, please also provide a context."
)

must_before_slot = InvalidHereAfter(
last_block_slot + int(time_until_expiration.total_seconds())
Expand All @@ -433,8 +448,11 @@ def generate_minting_policy(
@staticmethod
def _get_pub_key_hash(signer: Union["Wallet", Address]):

if hasattr(signer, "verification_key"):
return signer.verification_key.hash()
if isinstance(signer, Wallet):
if signer.verification_key:
return signer.verification_key.hash()
else:
TypeError("Singing wallet does not have associated keys.")
elif isinstance(signer, Address):
return str(signer.payment_part)
else:
Expand Down Expand Up @@ -569,7 +587,7 @@ class Output:

address: Union["Wallet", Address, str]
amount: Union[Lovelace, Ada, int]
tokens: Optional[Union[Token, List[Token]]] = field(default_factory=list)
tokens: Optional[Union[Token, List[Token]]] = None

def __post_init__(self):

Expand Down Expand Up @@ -1299,11 +1317,11 @@ def transact(
outputs: Optional[Union[Output, List[Output]]] = None,
mints: Optional[Union[Token, List[Token]]] = None,
signers: Optional[
Union["Wallet", List["Wallet"], SigningKey, List[SigningKey]]
Union["Wallet", List["Wallet"], SigningKey, List[SigningKey], Sequence["Wallet", SigningKey]]
] = None,
stake_registration: Optional[
Union[
bool, "Wallet", Address, str, List[Address], List["Wallet"], List[str]
bool, "Wallet", Address, str, List[Address], List["Wallet"], List[str], Sequence[Address, "Wallet", str]
]
] = None,
delegations: Optional[Union[str, dict, PoolKeyHash]] = None,
Expand Down