
    (i                     0   d dl mZmZ d dlmZmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZmZmZmZ deeef   deeef   fdZd	edefd
ZdedefdZdeeef   deeef   fdZdedefdZdedefdZdeeef   deeef   fdZdedefdZdedefdZy)    )AnyDict)assocdissoc)is_rlp_structured_access_list$is_rlp_structured_authorization_listis_rpc_structured_access_list$is_rpc_structured_authorization_list)CustomPydanticModel)
AccessListAuthorizationListRLPStructuredAccessListRLPStructuredAuthorizationListTransactionDictTypetxn_dictreturnc                     | j                         D ]P  \  }}t        |t        t        f      rt        d |D              | |<   2t        |t              sCt        |      | |<   R | S )z.
    Normalizes a transaction dictionary.
    c              3   V   K   | ]!  }t        |t              rt        |      n| # y wN)
isinstancedictnormalize_transaction_dict).0items     U/var/www/br/venv/lib/python3.12/site-packages/eth_account/_utils/transaction_utils.py	<genexpr>z-normalize_transaction_dict.<locals>.<genexpr>$   s-      " 5?tT4J*40PTT"s   '))itemsr   listtupler   r   )r   keyvalues      r   r   r      sh    
 nn& >
UedE]+! "!" HSM
 t$6u=HSM> O    transaction_dictc                     d vrzt         fddD              rt         dd        S t         fddD              rCt         fddD              rt         dd	        S d
 v rt         dd        S t         dd        S )Ntypec              3   &   K   | ]  }|v  
 y wr    )r   
type_1_argr#   s     r   r   z1set_transaction_type_if_needed.<locals>.<genexpr>3   s      
/9J**
   )gasPrice
accessList0x1c              3   &   K   | ]  }|v  
 y wr   r'   )r   
type_2_argr#   s     r   r   z1set_transaction_type_if_needed.<locals>.<genexpr>8   s      
 **
r)   )maxFeePerGasmaxPriorityFeePerGasc              3   &   K   | ]  }|v  
 y wr   r'   )r   
type_3_argr#   s     r   r   z1set_transaction_type_if_needed.<locals>.<genexpr><   s       ..r)   )maxFeePerBlobGasblobVersionedHashes0x3authorizationList0x40x2)allr   any)r#   s   `r   set_transaction_type_if_neededr;   /   s     %% 
=W
 
  %%5vuE" !  
F
 
  "M 
 $))965#I   %(88#()965#I   $))965#I r"   valc                 ,   t        | t              r| j                  d      S t        | t              r-| j	                         D ci c]  \  }}|t        |       c}}S t        | t        t        f      r| j                  d | D              S | S c c}}w )a  
    Serialize class objects in a transaction using expected defined instructions.
    Pydantic models are serialized with:

    - ``mode="json"``           Uses the json encoder to serialize the model.
    - ``by_alias=True``:        Uses the alias generator to turn all non-excluded fields
                                into lowerCamelCase dicts.
    - ``exclude=val._exclude:   Fields excluded for serialization are defined within a
                                ``_exclude`` property on the pydantic model.
    T)by_aliasc              3   2   K   | ]  }t        |        y wr   )%json_serialize_classes_in_transaction)r   vs     r   r   z8json_serialize_classes_in_transaction.<locals>.<genexpr>[   s     S!B1ES   )	r   r   
model_dumpr   r   r@   r   r   	__class__)r<   krA   s      r   r@   r@   K   s~     #*+~~t~,,	C	HK		T18;;TT	C$	'}}SsSSS
	 Us   B
dictionaryc                     | j                  d      }|r$t        | d      } t        |      }t        | d|      } | j                  d      }|r$t        | d      } t	        |      }t        | d|      } | S )zU
    Convert a JSON-RPC-structured transaction to an rlp-structured transaction.
    r+   r6   )getr   !_access_list_rpc_to_rlp_structurer   (_authorization_list_rpc_to_rlp_structure)rF   access_listrlp_structured_access_listauthorization_list!rlp_structured_authorization_lists        r    transaction_rpc_to_rlp_structurerO   a   s     ...KJ5
%F{%S":|5OP
#(;<J(;<
,T-
) +-N

 r"   rK   c                 R    t        |       st        d      t        d | D              S )Nz@provided object not formatted as JSON-RPC-structured access listc              3   P   K   | ]  }|d    t        d |d   D              f   yw)addressc              3       K   | ]  }|  y wr   r'   )r   _s     r   r   z>_access_list_rpc_to_rlp_structure.<locals>.<genexpr>.<genexpr>   s     .!.s   storageKeysN)r   r   ds     r   r   z4_access_list_rpc_to_rlp_structure.<locals>.<genexpr>   s6      
  iL.Q}-..	
   $&)r	   
ValueErrorr   rK   s    r   rI   rI   w   s:     )5N
 	

  
   r"   rM   c                 R    t        |       st        d      t        d | D              S )NzGprovided object not formatted as JSON-RPC-structured authorization listc              3   P   K   | ]  }|d    |d   |d   |d   |d   |d   f   yw)chainIdrR   nonceyParityrsNr'   rV   s     r   r   z;_authorization_list_rpc_to_rlp_structure.<locals>.<genexpr>   sF      
  iLiLgJiLcFcF	

rX   )r
   rY   r   rM   s    r   rJ   rJ      s;     00BCU
 	
  
 $
 
 
r"   c                     | j                  d      }| j                  d      }|r$t        | d      } t        |      }t        | d|      } |r$t        | d      } t	        |      }t        | d|      } | S )zU
    Convert an rlp-structured transaction to a JSON-RPC-structured transaction.
    r+   r6   )rH   r   !_access_list_rlp_to_rpc_structurer   (_authorization_list_rlp_to_rpc_structure)rF   rK   rM   rpc_structured_access_list!rpc_structured_authorization_lists        r    transaction_rlp_to_rpc_structurerh      s     ...K#(;<J5
%F{%S":|5OP
J(;<
,T-
) +-N

 r"   c                 R    t        |       st        d      t        d | D              S )Nz;provided object not formatted as rlp-structured access listc              3   2   K   | ]  }|d    |d   d  yw)r      )rR   rU   Nr'   r   ts     r   r   z4_access_list_rlp_to_rpc_structure.<locals>.<genexpr>   s     MAQqT!A$7MrB   )r   rY   r   rZ   s    r   rd   rd      s+     )5VWW MMMMr"   c                 R    t        |       st        d      t        d | D              S )NzBprovided object not formatted as rlp-structured authorization listc              3   R   K   | ]  }|d    |d   |d   |d   |d   |d   d ! yw)r   rk               )r]   rR   r^   r_   r`   ra   Nr'   rl   s     r   r   z;_authorization_list_rlp_to_rpc_structure.<locals>.<genexpr>   sF      
  ttqTt11	

s   %')r   rY   r   rb   s    r   re   re      s;     00BCP
 	
  
 $
 
 
r"   N)typingr   r   toolzr   r   eth_account._utils.validationr   r   r	   r
   eth_account.datastructuresr   eth_account.typesr   r   r   r   r   strr   r;   r@   rO   rI   rJ   rh   rd   re   r'   r"   r   <module>rz      s  

  c3h DcN $)8s s ,c3h DcN ,$)#,c3h DcN *N(NN6r"   