Skip to content

Commit

Permalink
Replace app.Simulate with c.client.Simulate
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Abliazimov committed Sep 16, 2024
1 parent 4475b4b commit 097d1e2
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions go-client/tx_raw_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ func (c *RawTxClient) BuildTx(
msgs[i] = m.Msg(c.Identity.Address.String())
}

gasLimit, err = c.EstimateGas(txBuilder, app, autoEstimateGas, gasAdjustmentFactor, gasLimit)
if err = txBuilder.SetMsgs(msgs...); err != nil {
return nil, fmt.Errorf("set msgs: %w", err)
}

gasLimit, err = c.EstimateGas(ctx, txBuilder, app, autoEstimateGas, gasAdjustmentFactor, gasLimit)
if err != nil {
return nil, fmt.Errorf("estimage gas: %w", err)
}
Expand All @@ -128,10 +132,6 @@ func (c *RawTxClient) BuildTx(
txBuilder.SetGasLimit(gasLimit)
txBuilder.SetFeeAmount(fees)

if err = txBuilder.SetMsgs(msgs...); err != nil {
return nil, fmt.Errorf("set msgs: %w", err)
}

// First round: we gather all the signer infos. We use the "set empty
// signature" hack to do that.
sigV2 := signing.SignatureV2{
Expand Down Expand Up @@ -229,6 +229,7 @@ func (c *RawTxClient) WaitForTx(ctx context.Context, hash string) error {
// EstimateGas estimates gas by simulating the transaction when autoEstimateGas is set to true.
// Otherwise, GasLimit is used.
func (c *RawTxClient) EstimateGas(
ctx context.Context,
txBuilder client.TxBuilder,
app *app.App,
autoEstimateGas bool,
Expand All @@ -244,12 +245,14 @@ func (c *RawTxClient) EstimateGas(
return 0, fmt.Errorf("estimate gas, encode tx: %w", err)
}

gasInfo, _, err := app.Simulate(txBytes)
gasInfo, err := c.client.Simulate(ctx, &txtypes.SimulateRequest{
TxBytes: txBytes,
})
if err != nil {
return 0, fmt.Errorf("estimate gas, simulate tx: %w", err)
}

estimatedGas := uint64(float64(gasInfo.GasUsed) * gasAdjustmentFactor)
estimatedGas := uint64(float64(gasInfo.GasInfo.GasUsed) * gasAdjustmentFactor)

return min(estimatedGas, gasLimit), nil
}

0 comments on commit 097d1e2

Please sign in to comment.