Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 6b6dbf0

Browse files
authored
Merge PR #171: Use configured ChainClient key in tx simulation
* use the keyring from `ChainClient` vs. the txfactory * attempt to use the working `ChainClients` configured key in tx simulation
1 parent 9f0d3c7 commit 6b6dbf0

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

client/tx.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package client
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"strings"
87

98
"github.com/avast/retry-go/v4"
109
"github.com/cosmos/cosmos-sdk/client"
1110
"github.com/cosmos/cosmos-sdk/client/tx"
11+
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1212
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
1313
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1414
"github.com/cosmos/cosmos-sdk/store/rootmulti"
@@ -178,10 +178,15 @@ func (cc *ChainClient) PrepareFactory(txf tx.Factory) (tx.Factory, error) {
178178
}
179179

180180
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+
181186
var txBytes []byte
182187
if err := retry.Do(func() error {
183188
var err error
184-
txBytes, err = BuildSimTx(txf, msgs...)
189+
txBytes, err = BuildSimTx(keyInfo, txf, msgs...)
185190
if err != nil {
186191
return err
187192
}
@@ -279,23 +284,15 @@ type protoTxProvider interface {
279284

280285
// BuildSimTx creates an unsigned tx with an empty single signature and returns
281286
// 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) {
283288
txb, err := tx.BuildUnsignedTx(txf, msgs...)
284289
if err != nil {
285290
return nil, err
286291
}
287292

288293
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-
}
295294

296-
// take the first info record just for simulation purposes
297-
pk = infos[0].GetPubKey()
298-
}
295+
pk = info.GetPubKey()
299296

300297
// Create an empty signature literal as the ante handler will populate with a
301298
// sentinel pubkey.

0 commit comments

Comments
 (0)