Skip to content

Commit

Permalink
add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed May 31, 2022
1 parent 7d26ea2 commit e0293ee
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,40 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) {
return nil, err
}

// use the first element from the list of keys in order to generate a valid
// pubkey that supports multiple algorithms
pk, err := f.getSimPK()
if err != nil {
return nil, err
}

// Create an empty signature literal as the ante handler will populate with a
// sentinel pubkey.
sig := signing.SignatureV2{
PubKey: pk,
Data: &signing.SingleSignatureData{
SignMode: f.signMode,
},
Sequence: f.Sequence(),
}
if err := txb.SetSignatures(sig); err != nil {
return nil, err
}

return f.txConfig.TxEncoder()(txb.GetTx())
}

// getSimPK gets the public key to use for building a simulation tx
// note we should only check for keys in the keybase if we are in simulate and execute mode
// (f.e. when using --gas=auto - ref #11283)
// when using --dry-run, we are is simulation mode only and should not check the keybase
func (f Factory) getSimPK() (cryptotypes.PubKey, error) {
var (
ok bool
pk cryptotypes.PubKey = &secp256k1.PubKey{} // use default public key type
)

if f.keybase != nil {
// use the first element from the list of keys in order to generate a valid
// pubkey that supports multiple algorithms
if f.simulateAndExecute && f.keybase != nil {
records, _ := f.keybase.List()
if len(records) == 0 {
return nil, errors.New("cannot build signature for simulation, key records slice is empty")
Expand All @@ -338,20 +363,7 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) {
}
}

// Create an empty signature literal as the ante handler will populate with a
// sentinel pubkey.
sig := signing.SignatureV2{
PubKey: pk,
Data: &signing.SingleSignatureData{
SignMode: f.signMode,
},
Sequence: f.Sequence(),
}
if err := txb.SetSignatures(sig); err != nil {
return nil, err
}

return f.txConfig.TxEncoder()(txb.GetTx())
return pk, nil
}

// Prepare ensures the account defined by ctx.GetFromAddress() exists and
Expand Down

0 comments on commit e0293ee

Please sign in to comment.