@@ -18,16 +18,14 @@ import (
1818 "github.com/cosmos/cosmos-sdk/client/flags"
1919 "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"
2020 "github.com/cosmos/cosmos-sdk/client/tx"
21- codectypes "github.com/cosmos/cosmos-sdk/codec/types"
2221 "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
2322 "github.com/cosmos/cosmos-sdk/crypto/types"
23+ multisigtypes "github.com/cosmos/cosmos-sdk/crypto/types/multisig"
2424 sdk "github.com/cosmos/cosmos-sdk/types"
2525 cosmoserrors "github.com/cosmos/cosmos-sdk/types/errors"
2626 sdktx "github.com/cosmos/cosmos-sdk/types/tx"
2727 "github.com/cosmos/cosmos-sdk/types/tx/signing"
28- authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
2928 authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
30- "github.com/cosmos/gogoproto/proto"
3129 "github.com/pkg/errors"
3230
3331 "github.com/CoreumFoundation/coreum-tools/pkg/retry"
@@ -169,8 +167,10 @@ func BuildTxForSimulation(
169167 txf = txf .WithGasAdjustment (clientCtx .GasAdjustment ())
170168 }
171169
170+ var signatureData signing.SignatureData = & signing.SingleSignatureData {
171+ SignMode : txf .SignMode (),
172+ }
172173 var pubKey types.PubKey
173- var pubKeyAny * codectypes.Any
174174 if ! clientCtx .GetUnsignedSimulation () {
175175 keyInfo , err := txf .Keybase ().KeyByAddress (clientCtx .FromAddress ())
176176 if err != nil {
@@ -180,71 +180,37 @@ func BuildTxForSimulation(
180180 if err != nil {
181181 return nil , errors .WithStack (err )
182182 }
183- pubKeyAny = keyInfo .PubKey
184- }
185-
186- msgsAny := make ([]* codectypes.Any , 0 , len (msgs ))
187- for _ , msg := range msgs {
188- msgAny , err := codectypes .NewAnyWithValue (msg )
189- if err != nil {
190- return nil , errors .WithStack (err )
191- }
192- msgsAny = append (msgsAny , msgAny )
193- }
194-
195- txBodyBytes , err := proto .Marshal (& sdktx.TxBody {
196- Messages : msgsAny ,
197- Memo : txf .Memo (),
198- })
199- if err != nil {
200- return nil , errors .WithStack (err )
201- }
202183
203- var signatureData signing. SignatureData
204- if multisigPubKey , ok := pubKey .( * multisig. LegacyAminoPubKey ); ok {
205- multiSignatureData := make ([]signing. SignatureData , 0 , multisigPubKey .Threshold )
206- for range multisigPubKey . Threshold {
207- multiSignatureData = append ( multiSignatureData , & signing. SingleSignatureData {
208- SignMode : txf . SignMode (),
209- })
210- }
211- signatureData = & signing. MultiSignatureData {
212- Signatures : multiSignatureData ,
184+ if multisigPubKey , ok := pubKey .( * multisig. LegacyAminoPubKey ); ok {
185+ multiSignatureData := make ([]signing. SignatureData , 0 , multisigPubKey . Threshold )
186+ for range multisigPubKey .Threshold {
187+ multiSignatureData = append ( multiSignatureData , & signing. SingleSignatureData {
188+ SignMode : txf . SignMode (),
189+ })
190+ }
191+ signatureData = & signing. MultiSignatureData {
192+ Signatures : multiSignatureData ,
193+ }
213194 }
214195 } else {
215- signatureData = & signing.SingleSignatureData {
216- SignMode : txf .SignMode (),
217- }
196+ // For unsigned simulation, signatureData doesn't matter. It should just not be nil
197+ signatureData = multisigtypes .NewMultisig (4 )
218198 }
219199
220- modeInfo , signature := authtx .SignatureDataToModeInfoAndSig (signatureData )
221-
222- simAuthInfoBytes , err := proto .Marshal (& sdktx.AuthInfo {
223- SignerInfos : []* sdktx.SignerInfo {
224- {
225- PublicKey : pubKeyAny ,
226- ModeInfo : modeInfo ,
227- Sequence : txf .Sequence (),
228- },
229- },
230- Fee : & sdktx.Fee {},
231- })
200+ signature := signing.SignatureV2 {
201+ PubKey : pubKey ,
202+ Data : signatureData ,
203+ Sequence : txf .Sequence (),
204+ }
205+ txBuilder , err := txf .BuildUnsignedTx (msgs ... )
232206 if err != nil {
233207 return nil , errors .WithStack (err )
234208 }
235-
236- txBytes , err := proto .Marshal (& sdktx.TxRaw {
237- BodyBytes : txBodyBytes ,
238- AuthInfoBytes : simAuthInfoBytes ,
239- Signatures : [][]byte {
240- signature ,
241- },
242- })
243- if err != nil {
209+ if err = txBuilder .SetSignatures (signature ); err != nil {
244210 return nil , errors .WithStack (err )
245211 }
246212
247- return txBytes , nil
213+ return clientCtx . TxConfig (). TxEncoder ()( txBuilder . GetTx ())
248214}
249215
250216// BroadcastRawTx broadcast the txBytes using the clientCtx and set BroadcastMode.
0 commit comments