@@ -2,13 +2,13 @@ package client
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"fmt"
7
6
"strings"
8
7
9
8
"github.com/avast/retry-go/v4"
10
9
"github.com/cosmos/cosmos-sdk/client"
11
10
"github.com/cosmos/cosmos-sdk/client/tx"
11
+ "github.com/cosmos/cosmos-sdk/crypto/keyring"
12
12
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
13
13
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
14
14
"github.com/cosmos/cosmos-sdk/store/rootmulti"
@@ -178,10 +178,15 @@ func (cc *ChainClient) PrepareFactory(txf tx.Factory) (tx.Factory, error) {
178
178
}
179
179
180
180
func (cc * ChainClient ) CalculateGas (ctx context.Context , txf tx.Factory , msgs ... sdk.Msg ) (txtypes.SimulateResponse , uint64 , error ) {
181
+ keyInfo , err := cc .Keybase .Key (cc .Config .Key )
182
+ if err != nil {
183
+ return txtypes.SimulateResponse {}, 0 , err
184
+ }
185
+
181
186
var txBytes []byte
182
187
if err := retry .Do (func () error {
183
188
var err error
184
- txBytes , err = BuildSimTx (txf , msgs ... )
189
+ txBytes , err = BuildSimTx (keyInfo , txf , msgs ... )
185
190
if err != nil {
186
191
return err
187
192
}
@@ -279,23 +284,15 @@ type protoTxProvider interface {
279
284
280
285
// BuildSimTx creates an unsigned tx with an empty single signature and returns
281
286
// the encoded transaction or an error if the unsigned transaction cannot be built.
282
- func BuildSimTx (txf tx.Factory , msgs ... sdk.Msg ) ([]byte , error ) {
287
+ func BuildSimTx (info keyring. Info , txf tx.Factory , msgs ... sdk.Msg ) ([]byte , error ) {
283
288
txb , err := tx .BuildUnsignedTx (txf , msgs ... )
284
289
if err != nil {
285
290
return nil , err
286
291
}
287
292
288
293
var pk cryptotypes.PubKey = & secp256k1.PubKey {} // use default public key type
289
- keybase := txf .Keybase ()
290
- if keybase != nil {
291
- infos , _ := keybase .List ()
292
- if len (infos ) == 0 {
293
- return nil , errors .New ("cannot build signature for simulation, key infos slice is empty" )
294
- }
295
294
296
- // take the first info record just for simulation purposes
297
- pk = infos [0 ].GetPubKey ()
298
- }
295
+ pk = info .GetPubKey ()
299
296
300
297
// Create an empty signature literal as the ante handler will populate with a
301
298
// sentinel pubkey.
0 commit comments