fix(x/auth/tx): avoid panic from intoAnyV2 when v1.PublicKey is optional (#23148)

This commit is contained in:
mmsqe 2025-01-04 00:54:32 +08:00 committed by GitHub
parent f29d7f75f1
commit 07d5168d29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 3 deletions

View File

@ -51,6 +51,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
### Bug Fixes
* (query) [23002](https://github.com/cosmos/cosmos-sdk/pull/23002) Fix collection filtered pagination.
* (x/auth/tx) [#23148](https://github.com/cosmos/cosmos-sdk/pull/23148) Avoid panic from intoAnyV2 when v1.PublicKey is optional.
### API Breaking Changes

View File

@ -293,9 +293,11 @@ func intoV2SignerInfo(v1s []*tx.SignerInfo) []*txv1beta1.SignerInfo {
modeInfoV2 := new(txv1beta1.ModeInfo)
intoV2ModeInfo(v1.ModeInfo, modeInfoV2)
v2 := &txv1beta1.SignerInfo{
PublicKey: intoAnyV2([]*codectypes.Any{v1.PublicKey})[0],
ModeInfo: modeInfoV2,
Sequence: v1.Sequence,
ModeInfo: modeInfoV2,
Sequence: v1.Sequence,
}
if v1.PublicKey != nil {
v2.PublicKey = intoAnyV2([]*codectypes.Any{v1.PublicKey})[0]
}
v2s[i] = v2
}

15
x/auth/tx/builder_test.go Normal file
View File

@ -0,0 +1,15 @@
package tx
import (
"testing"
any "github.com/cosmos/gogoproto/types/any"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/types/tx"
)
func TestIntoV2SignerInfo(t *testing.T) {
require.NotNil(t, intoV2SignerInfo([]*tx.SignerInfo{{}}))
require.NotNil(t, intoV2SignerInfo([]*tx.SignerInfo{{PublicKey: &any.Any{}}}))
}