diff --git a/x/cert/legacy/v2/store.go b/x/cert/legacy/v2/store.go index 639a76bfe..303cd22c5 100644 --- a/x/cert/legacy/v2/store.go +++ b/x/cert/legacy/v2/store.go @@ -2,6 +2,7 @@ package v2 import ( "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,12 +26,48 @@ func migrateCertificate(store sdk.KVStore, cdc codec.BinaryCodec) error { } cert.Certifier = shentuAddr + transistCertContent(&cert) + bz := cdc.MustMarshalLengthPrefixed(&cert) oldStore.Set(iterator.Key(), bz) } return nil } +func transistCertContent(certificate *types.Certificate) { + switch certificate.GetContent().(type) { + case *types.OracleOperator: + contentShentu, err := common.PrefixToShentu(certificate.GetContentString()) + if err != nil { + return + } + content := types.OracleOperator{Content: contentShentu} + setContentAny(certificate, &content) + case *types.ShieldPoolCreator: + contentShentu, err := common.PrefixToShentu(certificate.GetContentString()) + if err != nil { + return + } + content := types.ShieldPoolCreator{Content: contentShentu} + setContentAny(certificate, &content) + case *types.Identity: + contentShentu, err := common.PrefixToShentu(certificate.GetContentString()) + if err != nil { + return + } + content := types.Identity{Content: contentShentu} + setContentAny(certificate, &content) + } +} + +func setContentAny(certificate *types.Certificate, content types.Content) { + any, err := codectypes.NewAnyWithValue(content) + if err != nil { + panic(err) + } + certificate.Content = any +} + func migrateCertifier(store sdk.KVStore, cdc codec.BinaryCodec) error { oldStore := prefix.NewStore(store, types.CertifiersStoreKey()) diff --git a/x/cert/legacy/v2/store_test.go b/x/cert/legacy/v2/store_test.go index 37325cca8..327832fc5 100644 --- a/x/cert/legacy/v2/store_test.go +++ b/x/cert/legacy/v2/store_test.go @@ -17,7 +17,7 @@ import ( shentuapp "github.com/shentufoundation/shentu/v2/app" "github.com/shentufoundation/shentu/v2/common" - v280 "github.com/shentufoundation/shentu/v2/x/cert/legacy/v2" + v2 "github.com/shentufoundation/shentu/v2/x/cert/legacy/v2" "github.com/shentufoundation/shentu/v2/x/cert/types" ) @@ -25,7 +25,7 @@ func makeCertificate(certType string) types.Certificate { _, _, addr := testdata.KeyTestPubAddr() certifier, _ := common.PrefixToCertik(addr.String()) - content := types.AssembleContent(certType, "test") + content := types.AssembleContent(certType, certifier) msg, ok := content.(proto.Message) if !ok { panic(fmt.Errorf("%T does not implement proto.Message", content)) @@ -81,7 +81,7 @@ func TestMigrateStore(t *testing.T) { ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now().UTC()}) cdc := shentuapp.MakeEncodingConfig().Marshaler - oldCertificate := makeCertificate("AUDITING") + oldCertificate := makeCertificate("IDENTITY") oldCertifier := makeCertifier(oldCertificate.Certifier, "test_certifier") @@ -92,7 +92,7 @@ func TestMigrateStore(t *testing.T) { oldLibrary := saveLibrary(cdc, store) - err := v280.MigrateStore(ctx, app.GetKey(types.StoreKey), cdc) + err := v2.MigrateStore(ctx, app.GetKey(types.StoreKey), cdc) require.NoError(t, err) //check for Certificate @@ -109,6 +109,7 @@ func TestMigrateStore(t *testing.T) { bz = store.Get(types.CertifierStoreKey(certifierAcc)) cdc.MustUnmarshalLengthPrefixed(bz, &certifier) require.Equal(t, newCertifierAddr, certifier.Address) + require.Equal(t, newCertifierAddr, cert.GetContentString()) newCertifierProposer, _ := common.PrefixToShentu(oldCertifier.Proposer) require.Equal(t, newCertifierProposer, certifier.Proposer)