Skip to content

Commit 49a4c32

Browse files
committed
Remove gas sim from example
1 parent 4f0c1f5 commit 49a4c32

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

examples/chain_client/0_LocalOrderHash.py

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,17 @@ async def main() -> None:
9797
print("computed spot order hashes", order_hashes.spot)
9898
print("computed derivative order hashes", order_hashes.derivative)
9999

100-
# build sim tx 1
100+
# build tx 1
101101
tx = (
102102
Transaction()
103103
.with_messages(spot_msg, deriv_msg)
104104
.with_sequence(client.get_sequence())
105105
.with_account_num(client.get_number())
106106
.with_chain_id(network.chain_id)
107107
)
108-
sim_sign_doc = tx.get_sign_doc(pub_key)
109-
sim_sig = priv_key.sign(sim_sign_doc.SerializeToString())
110-
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)
111-
112-
# simulate tx
113-
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
114-
if not success:
115-
print(sim_res)
116-
return
117-
118-
# build tx
119108
gas_price = 500000000
120-
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
109+
base_gas = 85000
110+
gas_limit = base_gas + 20000 # add 20k for gas, fee computation
121111
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
122112
fee = [composer.Coin(
123113
amount=gas_price * gas_limit,
@@ -141,27 +131,17 @@ async def main() -> None:
141131
print("computed spot order hashes", order_hashes.spot)
142132
print("computed derivative order hashes", order_hashes.derivative)
143133

144-
# build sim tx 2
134+
# build tx 2
145135
tx = (
146136
Transaction()
147137
.with_messages(spot_msg, deriv_msg)
148138
.with_sequence(client.get_sequence())
149139
.with_account_num(client.get_number())
150140
.with_chain_id(network.chain_id)
151141
)
152-
sim_sign_doc = tx.get_sign_doc(pub_key)
153-
sim_sig = priv_key.sign(sim_sign_doc.SerializeToString())
154-
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)
155-
156-
# simulate tx
157-
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
158-
if not success:
159-
print(sim_res)
160-
return
161-
162-
# build tx
163142
gas_price = 500000000
164-
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
143+
base_gas = 85000
144+
gas_limit = base_gas + 20000 # add 20k for gas, fee computation
165145
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
166146
fee = [composer.Coin(
167147
amount=gas_price * gas_limit,
@@ -239,27 +219,17 @@ async def main() -> None:
239219
print("computed spot order hashes", order_hashes.spot)
240220
print("computed derivative order hashes", order_hashes.derivative)
241221

242-
# build sim tx 3
222+
# build tx 3
243223
tx = (
244224
Transaction()
245225
.with_messages(spot_msg, deriv_msg)
246226
.with_sequence(client.get_sequence())
247227
.with_account_num(client.get_number())
248228
.with_chain_id(network.chain_id)
249229
)
250-
sim_sign_doc = tx.get_sign_doc(pub_key)
251-
sim_sig = priv_key.sign(sim_sign_doc.SerializeToString())
252-
sim_tx_raw_bytes = tx.get_tx_data(sim_sig, pub_key)
253-
254-
# simulate tx
255-
(sim_res, success) = await client.simulate_tx(sim_tx_raw_bytes)
256-
if not success:
257-
print(sim_res)
258-
return
259-
260-
# build tx
261230
gas_price = 500000000
262-
gas_limit = sim_res.gas_info.gas_used + 20000 # add 20k for gas, fee computation
231+
base_gas = 85000
232+
gas_limit = base_gas + 20000 # add 20k for gas, fee computation
263233
gas_fee = '{:.18f}'.format((gas_price * gas_limit) / pow(10, 18)).rstrip('0')
264234
fee = [composer.Coin(
265235
amount=gas_price * gas_limit,

0 commit comments

Comments
 (0)