
    (i                         d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZmZ d dlmZ d dlmZmZmZmZ erd d	lmZmZ d
edededefdZ G d de      Zy)    )TYPE_CHECKINGAnycast)assoc)to_hex_if_integer)all_in_dictany_in_dictnone_in_dict)DYNAMIC_FEE_TXN_PARAMS)InvalidTransactionTransactionTypeMismatch)Web3Middleware)	BlockDataRPCEndpointTxParamsWei)	AsyncWeb3Web3transactionlatest_blockstrategy_based_gas_pricereturnc                    |*d| vr&t        t        |       rt        | dt        |            } d| v rt	        t        |       r
t               t        t        |       r>t        t        | d         d      t        t        | d         d      k  rt        d      | S d| vrAd| v r=|d   }t        t        | d         d      }|d|z  z   }t        | dt        |            } | S d| v rd| vrt        d      | S )	NgasPricemaxFeePerGas   maxPriorityFeePerGasz,maxFeePerGas must be >= maxPriorityFeePerGasbaseFeePerGas   z;maxPriorityFeePerGas must be defined in a 1559 transaction.)r
   r   r   r   r	   r   r   intstrr   hex)r   r   r   base_feepriority_feemax_fee_per_gass         S/var/www/br/venv/lib/python3.12/site-packages/web3/middleware/gas_price_strategy.pyvalidate_transaction_paramsr'   +   s)   
 	!,k)/=%67O%P

 [ [1G%U%''	+[	9s;~./4s234b8
 
 %%STT  
{	*/E/T03{+ABCRH&X5K_9MN  
;	&+A+T I
 	
     c                   8    e Zd ZdZdededefdZdededefdZy)GasPriceStrategyMiddlewarea  
    - Uses a gas price strategy if one is set. This is only supported for
      legacy transactions. It is recommended to send dynamic fee transactions
      (EIP-1559) whenever possible.

    - Validates transaction params against legacy and dynamic fee txn values.
    methodparamsr   c                     |dk(  rk|d   }| j                   j                  j                  |      }t        d| j                         }|j                  j	                  d      }t        |||      }|f}||fS )Neth_sendTransactionr   r   latest)_w3ethgenerate_gas_pricer   	get_blockr'   )selfr+   r,   r   generated_gas_pricew3r   s          r&   request_processorz,GasPriceStrategyMiddleware.request_processor[   sv    ** )K"&((,,"A"A+"Nfdhh'B66++H5L5\+>K "^Fv~r(   c                    K   |dk(  ri|d   }t        d| j                        }|j                  j                  |      }|j                  j	                  d       d {   }t        |||      }|f}||fS 7 w)Nr.   r   zAsyncWeb3[Any]r/   )r   r0   r1   r2   r3   r'   )r4   r+   r,   r   r6   r5   r   s          r&   async_request_processorz2GasPriceStrategyMiddleware.async_request_processorj   s     ** )K&1B"$&&";";K"H!#!1!1(!;;L5\+>K "^Fv~ <s   AA7A5A7N)__name__
__module____qualname____doc__r   r   r7   r9    r(   r&   r*   r*   R   s<     S S 
K 
 
QT 
r(   r*   N)typingr   r   r   eth_utils.toolzr   web3._utils.method_formattersr   web3._utils.utility_methodsr   r	   r
   web3.constantsr   web3.exceptionsr   r   web3.middleware.baser   
web3.typesr   r   r   r   web3r   r   r'   r*   r>   r(   r&   <module>rH      sx     
  $$)2$NQ$$N" "r(   