Skip to content

Commit 25b01df

Browse files
committed
feat: made the gas calculator using gas heuristics the default one for the MsgBroadcasterWithPk when broadcasting without simulation
1 parent 9f2062c commit 25b01df

File tree

1 file changed

+80
-8
lines changed

1 file changed

+80
-8
lines changed

pyinjective/core/broadcaster.py

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,36 @@ def new_without_simulation(
124124
):
125125
"""Creates a new broadcaster instance that uses message-based gas estimation without simulation.
126126
127+
Args:
128+
network (Network): The network configuration to use (mainnet, testnet, etc.)
129+
private_key (str): The private key in hex format for signing transactions
130+
gas_price (Optional[int]): Custom gas price in chain format (e.g. 500000000000000000 for 0.5 INJ).
131+
Defaults to None
132+
client (Optional[AsyncClient]): Custom AsyncClient instance. Defaults to None
133+
composer (Optional[Composer]): Custom Composer instance. Defaults to None
134+
135+
Returns:
136+
MsgBroadcasterWithPk: A configured broadcaster instance using message-based fee calculation
137+
"""
138+
return cls.new_using_gas_heuristics(
139+
network=network,
140+
private_key=private_key,
141+
gas_price=gas_price,
142+
client=client,
143+
composer=composer,
144+
)
145+
146+
@classmethod
147+
def new_using_gas_heuristics(
148+
cls,
149+
network: Network,
150+
private_key: str,
151+
gas_price: Optional[int] = None,
152+
client: Optional[AsyncClient] = None,
153+
composer: Optional[Composer] = None,
154+
):
155+
"""Creates a new broadcaster instance that uses gas heuristics for gas calculation
156+
127157
Args:
128158
network (Network): The network configuration to use (mainnet, testnet, etc.)
129159
private_key (str): The private key in hex format for signing transactions
@@ -138,7 +168,11 @@ def new_without_simulation(
138168
client = client or AsyncClient(network=network)
139169
composer = composer or Composer(network=client.network.string())
140170
account_config = StandardAccountBroadcasterConfig(private_key=private_key)
141-
fee_calculator = MessageBasedTransactionFeeCalculator(client=client, composer=composer, gas_price=gas_price)
171+
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_heuristics(
172+
client=client,
173+
composer=composer,
174+
gas_price=gas_price,
175+
)
142176
instance = cls(
143177
network=network,
144178
account_config=account_config,
@@ -149,7 +183,7 @@ def new_without_simulation(
149183
return instance
150184

151185
@classmethod
152-
def new_using_gas_heuristics(
186+
def new_using_estimate_gas(
153187
cls,
154188
network: Network,
155189
private_key: str,
@@ -173,7 +207,7 @@ def new_using_gas_heuristics(
173207
client = client or AsyncClient(network=network)
174208
composer = composer or Composer(network=client.network.string())
175209
account_config = StandardAccountBroadcasterConfig(private_key=private_key)
176-
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_heuristics(
210+
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_estimation(
177211
client=client,
178212
composer=composer,
179213
gas_price=gas_price,
@@ -232,8 +266,38 @@ def new_for_grantee_account_without_simulation(
232266
client: Optional[AsyncClient] = None,
233267
composer: Optional[Composer] = None,
234268
):
235-
"""Creates a new broadcaster instance for a grantee account that uses message-based gas estimation without
236-
simulation.
269+
"""Creates a new broadcaster instance for a grantee account that uses gas estimator using gas heuristics.
270+
271+
Args:
272+
network (Network): The network configuration to use (mainnet, testnet, etc.)
273+
grantee_private_key (str): The grantee's private key in hex format for signing transactions
274+
gas_price (Optional[int]): Custom gas price in chain format (e.g. 500000000000000000 for 0.5 INJ).
275+
Defaults to None
276+
client (Optional[AsyncClient]): Custom AsyncClient instance. Defaults to None
277+
composer (Optional[Composer]): Custom Composer instance. Defaults to None
278+
279+
Returns:
280+
MsgBroadcasterWithPk: A configured broadcaster instance using message-based fee calculation for a grantee
281+
account
282+
"""
283+
return cls.new_for_grantee_account_using_gas_heuristics(
284+
network=network,
285+
grantee_private_key=grantee_private_key,
286+
gas_price=gas_price,
287+
client=client,
288+
composer=composer,
289+
)
290+
291+
@classmethod
292+
def new_for_grantee_account_using_gas_heuristics(
293+
cls,
294+
network: Network,
295+
grantee_private_key: str,
296+
gas_price: Optional[int] = None,
297+
client: Optional[AsyncClient] = None,
298+
composer: Optional[Composer] = None,
299+
):
300+
"""Creates a new broadcaster instance for a grantee account that uses gas heuristics.
237301
238302
Args:
239303
network (Network): The network configuration to use (mainnet, testnet, etc.)
@@ -250,7 +314,11 @@ def new_for_grantee_account_without_simulation(
250314
client = client or AsyncClient(network=network)
251315
composer = composer or Composer(network=client.network.string())
252316
account_config = GranteeAccountBroadcasterConfig(grantee_private_key=grantee_private_key, composer=composer)
253-
fee_calculator = MessageBasedTransactionFeeCalculator(client=client, composer=composer, gas_price=gas_price)
317+
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_heuristics(
318+
client=client,
319+
composer=composer,
320+
gas_price=gas_price,
321+
)
254322
instance = cls(
255323
network=network,
256324
account_config=account_config,
@@ -261,7 +329,7 @@ def new_for_grantee_account_without_simulation(
261329
return instance
262330

263331
@classmethod
264-
def new_for_grantee_account_using_gas_heuristics(
332+
def new_for_grantee_account_using_estimated_gas(
265333
cls,
266334
network: Network,
267335
grantee_private_key: str,
@@ -287,7 +355,7 @@ def new_for_grantee_account_using_gas_heuristics(
287355
client = client or AsyncClient(network=network)
288356
composer = composer or Composer(network=client.network.string())
289357
account_config = GranteeAccountBroadcasterConfig(grantee_private_key=grantee_private_key, composer=composer)
290-
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_heuristics(
358+
fee_calculator = MessageBasedTransactionFeeCalculator.new_using_gas_estimation(
291359
client=client,
292360
composer=composer,
293361
gas_price=gas_price,
@@ -465,6 +533,10 @@ def new_using_gas_heuristics(cls, client: AsyncClient, composer: Composer, gas_p
465533
client=client, composer=composer, gas_price=gas_price, estimator_class=GasHeuristicsGasLimitEstimator
466534
)
467535

536+
@classmethod
537+
def new_using_gas_estimation(cls, client: AsyncClient, composer: Composer, gas_price: Optional[int] = None):
538+
return cls(client=client, composer=composer, gas_price=gas_price, estimator_class=GasLimitEstimator)
539+
468540
async def configure_gas_fee_for_transaction(
469541
self,
470542
transaction: Transaction,

0 commit comments

Comments
 (0)