33 Convex API
44
55"""
6+ from __future__ import annotations
7+
8+ from typing import TYPE_CHECKING
9+
10+ if TYPE_CHECKING :
11+ from typing import Any , Dict
612
713import logging
814import re
915import secrets
1016import time
11- from typing import (
12- Any ,
13- Dict ,
14- Union ,
15- cast
16- )
17+ from typing import cast
1718from urllib .parse import urljoin
1819
1920import requests
@@ -101,7 +102,7 @@ def create_account(self, key_pair: KeyPair, sequence_retry_count: int = 20) -> A
101102
102103 return account
103104
104- def load_account (self , name : str , key_pair : KeyPair ) -> Union [ Account , None ] :
105+ def load_account (self , name : str , key_pair : KeyPair ) -> Account | None :
105106 """
106107
107108 Load an account using the correct name. If successful return the :class:`.Account` object with the address set.
@@ -130,7 +131,7 @@ def load_account(self, name: str, key_pair: KeyPair) -> Union[Account, None]:
130131 new_account = Account (key_pair , address , name = name )
131132 return new_account
132133
133- def setup_account (self , name : str , key_pair : KeyPair , register_account : Union [ Account , None ] = None ) -> Union [ Account , None ] :
134+ def setup_account (self , name : str , key_pair : KeyPair , register_account : Account | None = None ) -> Account | None :
134135 """
135136
136137 Convenience method to create or load an account based on the account name.
@@ -174,8 +175,8 @@ def setup_account(self, name: str, key_pair: KeyPair, register_account: Union[Ac
174175 def register_account_name (
175176 self ,
176177 name : str ,
177- address_account : Union [ Account , int , str ] ,
178- account : Union [ Account , None ] = None
178+ address_account : Account | int | str ,
179+ account : Account | None = None
179180 ) -> Account :
180181 """
181182
@@ -287,7 +288,7 @@ def send(self, transaction: str, account: Account, sequence_retry_count: int = 2
287288 def query (
288289 self ,
289290 transaction : str ,
290- address_account : Union [ int , str , Account ]
291+ address_account : int | str | Account
291292 ):
292293 """
293294
@@ -398,7 +399,7 @@ def topup_account(
398399 retry_count -= 1
399400 return transfer_amount
400401
401- def get_address (self , function_name : str , address_account : Union [ Account , int , str ] ):
402+ def get_address (self , function_name : str , address_account : Account | int | str ):
402403 """
403404
404405 Query the network for a contract ( function ) address. The contract must have been deployed
@@ -425,7 +426,7 @@ def get_address(self, function_name: str, address_account: Union[Account, int, s
425426 result = self .query (line , address_account )
426427 return Account .to_address (result .value )
427428
428- def get_balance (self , address_account : Union [ Account , int , str ] , account_from : Union [ Account , int , str , None ] = None ):
429+ def get_balance (self , address_account : Account | int | str , account_from : Account | int | str | None = None ):
429430 """
430431
431432 Get a balance of an account.
@@ -473,7 +474,7 @@ def get_balance(self, address_account: Union[Account, int, str], account_from: U
473474 value = cast (int , result .value )
474475 return value
475476
476- def transfer (self , to_address_account : Union [ Account , int , str ] , amount : Union [ int , float ] , account : Account ):
477+ def transfer (self , to_address_account : Account | int | str , amount : int | float , account : Account ):
477478 """
478479
479480 Transfer funds from on account to another.
@@ -513,7 +514,7 @@ def transfer(self, to_address_account: Union[Account, int, str], amount: Union[i
513514 return result .value
514515 return 0
515516
516- def transfer_account (self , from_account : Union [ Account , int , str ] , to_account : Union [ Account , int , str ] ):
517+ def transfer_account (self , from_account : Account | int | str , to_account : Account | int | str ):
517518 """
518519
519520 **WARNING**
@@ -564,7 +565,7 @@ def transfer_account(self, from_account: Union[Account, int, str], to_account: U
564565 if result is not None and from_account .key_pair .is_equal (result .value ):
565566 return Account (from_account .key_pair , to_account .address , to_account .name )
566567
567- def get_account_info (self , address_account : Union [ Account , int , str ] ) -> AccountDetailsResponse :
568+ def get_account_info (self , address_account : Account | int | str ) -> AccountDetailsResponse :
568569 """
569570
570571 Get account information. This will only work with an account that has a balance or has had some transactions
@@ -605,7 +606,7 @@ def get_account_info(self, address_account: Union[Account, int, str]) -> Account
605606
606607 return result
607608
608- def resolve_account_name (self , name : str ) -> Union [ int , None ] :
609+ def resolve_account_name (self , name : str ) -> int | None :
609610 """
610611 Resolves an account name to an address.
611612 :param string name Name of the account to resolve.
@@ -618,7 +619,7 @@ def resolve_account_name(self, name: str) -> Union[int, None]:
618619 """
619620 return self ._registry .resolve_address (f'account.{ name } ' )
620621
621- def resolve_name (self , name : str ) -> Union [ int , None ] :
622+ def resolve_name (self , name : str ) -> int | None :
622623 """
623624 Resolves any Convex Name Services to an address.
624625 :param string name Name of the the CNS Service.
@@ -641,11 +642,11 @@ def load_contract(self, name: str):
641642 def _post (
642643 self ,
643644 url : str ,
644- data : Union [ CreateAccountRequest , FaucetRequest , QueryRequest , PrepareTransactionRequest , SubmitTransactionRequest ] ,
645+ data : CreateAccountRequest | FaucetRequest | QueryRequest | PrepareTransactionRequest | SubmitTransactionRequest ,
645646 sequence_retry_count : int = 20
646- ) -> Union [ Dict [str , Any ], None ] :
647+ ) -> Dict [str , Any ] | None :
647648 max_sleep_time_seconds = 1
648- result : Union [ Dict [str , Any ], None ] = None
649+ result : Dict [str , Any ] | None = None
649650 while sequence_retry_count >= 0 :
650651 response = requests .post (url , data = data .model_dump_json ())
651652 if response .status_code == 200 :
@@ -668,8 +669,8 @@ def _post(
668669 def _transaction_prepare (
669670 self ,
670671 transaction : str ,
671- address : Union [ Account , int , str ] ,
672- sequence_number : Union [ int , None ] = None
672+ address : Account | int | str ,
673+ sequence_number : int | None = None
673674 ) -> PrepareTransactionResponse :
674675 """
675676 A transaction requires its hash to be digitally signed by the executing account prior to submission.
@@ -703,15 +704,15 @@ def _transaction_prepare(
703704
704705 def _transaction_submit (
705706 self ,
706- address : Union [ Account , int , str ] ,
707+ address : Account | int | str ,
707708 public_key : str ,
708709 hash_data : str ,
709710 signed_data : str
710711 ) -> SubmitTransactionResponse :
711712 """
712713 Submit a transaction to the Convex network.
713714
714- :param Union[ Account, int, str] address: :class:`.Account` object or address of the executing account.
715+ :param Account | int, str address: :class:`.Account` object or address of the executing account.
715716 :param str public_key: Public key of the executing account.
716717 :param str hash_data: Hash of the transaction to be submitted.
717718 :param str signed_data: Ed25519 signature of the transaction hash.
@@ -733,7 +734,7 @@ def _transaction_submit(
733734
734735 def _transaction_query (
735736 self ,
736- address : Union [ Account , int , str ] ,
737+ address : Account | int | str ,
737738 transaction : str
738739 ):
739740 """
0 commit comments