From b3103b45128459802f18e561ba1958397a255033 Mon Sep 17 00:00:00 2001 From: poorphd Date: Mon, 15 Jul 2024 17:45:14 +0900 Subject: [PATCH] fix: genesis import/export for csr --- api/canto/csr/v1/genesis.pulsar.go | 36 ++++++++++++++---------------- proto/canto/csr/v1/genesis.proto | 2 +- x/csr/genesis.go | 9 ++++---- x/csr/keeper/genesis_test.go | 4 ++-- x/csr/types/genesis.go | 4 ++-- x/csr/types/genesis.pb.go | 24 +++++++++----------- 6 files changed, 37 insertions(+), 42 deletions(-) diff --git a/api/canto/csr/v1/genesis.pulsar.go b/api/canto/csr/v1/genesis.pulsar.go index ecdbb1aa..0dcef6da 100644 --- a/api/canto/csr/v1/genesis.pulsar.go +++ b/api/canto/csr/v1/genesis.pulsar.go @@ -156,8 +156,8 @@ func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor, return } } - if len(x.TurnstileAddress) != 0 { - value := protoreflect.ValueOfBytes(x.TurnstileAddress) + if x.TurnstileAddress != "" { + value := protoreflect.ValueOfString(x.TurnstileAddress) if !f(fd_GenesisState_turnstile_address, value) { return } @@ -182,7 +182,7 @@ func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool case "canto.csr.v1.GenesisState.csrs": return len(x.Csrs) != 0 case "canto.csr.v1.GenesisState.turnstile_address": - return len(x.TurnstileAddress) != 0 + return x.TurnstileAddress != "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: canto.csr.v1.GenesisState")) @@ -204,7 +204,7 @@ func (x *fastReflection_GenesisState) Clear(fd protoreflect.FieldDescriptor) { case "canto.csr.v1.GenesisState.csrs": x.Csrs = nil case "canto.csr.v1.GenesisState.turnstile_address": - x.TurnstileAddress = nil + x.TurnstileAddress = "" default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: canto.csr.v1.GenesisState")) @@ -232,7 +232,7 @@ func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescripto return protoreflect.ValueOfList(listValue) case "canto.csr.v1.GenesisState.turnstile_address": value := x.TurnstileAddress - return protoreflect.ValueOfBytes(value) + return protoreflect.ValueOfString(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: canto.csr.v1.GenesisState")) @@ -260,7 +260,7 @@ func (x *fastReflection_GenesisState) Set(fd protoreflect.FieldDescriptor, value clv := lv.(*_GenesisState_2_list) x.Csrs = *clv.list case "canto.csr.v1.GenesisState.turnstile_address": - x.TurnstileAddress = value.Bytes() + x.TurnstileAddress = value.Interface().(string) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: canto.csr.v1.GenesisState")) @@ -314,7 +314,7 @@ func (x *fastReflection_GenesisState) NewField(fd protoreflect.FieldDescriptor) list := []*CSR{} return protoreflect.ValueOfList(&_GenesisState_2_list{list: &list}) case "canto.csr.v1.GenesisState.turnstile_address": - return protoreflect.ValueOfBytes(nil) + return protoreflect.ValueOfString("") default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: canto.csr.v1.GenesisState")) @@ -587,7 +587,7 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field TurnstileAddress", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow @@ -597,25 +597,23 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength } if postIndex > l { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF } - x.TurnstileAddress = append(x.TurnstileAddress[:0], dAtA[iNdEx:postIndex]...) - if x.TurnstileAddress == nil { - x.TurnstileAddress = []byte{} - } + x.TurnstileAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex @@ -674,7 +672,7 @@ type GenesisState struct { // params defines all of the parameters of the module Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` Csrs []*CSR `protobuf:"bytes,2,rep,name=csrs,proto3" json:"csrs,omitempty"` - TurnstileAddress []byte `protobuf:"bytes,3,opt,name=turnstile_address,json=turnstileAddress,proto3" json:"turnstile_address,omitempty"` + TurnstileAddress string `protobuf:"bytes,3,opt,name=turnstile_address,json=turnstileAddress,proto3" json:"turnstile_address,omitempty"` } func (x *GenesisState) Reset() { @@ -711,11 +709,11 @@ func (x *GenesisState) GetCsrs() []*CSR { return nil } -func (x *GenesisState) GetTurnstileAddress() []byte { +func (x *GenesisState) GetTurnstileAddress() string { if x != nil { return x.TurnstileAddress } - return nil + return "" } var File_canto_csr_v1_genesis_proto protoreflect.FileDescriptor @@ -736,7 +734,7 @@ var file_canto_csr_v1_genesis_proto_rawDesc = []byte{ 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x63, 0x61, 0x6e, 0x74, 0x6f, 0x2e, 0x63, 0x73, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x53, 0x52, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x04, 0x63, 0x73, 0x72, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x74, 0x69, - 0x6c, 0x65, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, + 0x6c, 0x65, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x74, 0x75, 0x72, 0x6e, 0x73, 0x74, 0x69, 0x6c, 0x65, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0x97, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x61, 0x6e, 0x74, 0x6f, 0x2e, 0x63, 0x73, 0x72, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, diff --git a/proto/canto/csr/v1/genesis.proto b/proto/canto/csr/v1/genesis.proto index a00d7833..827d9745 100644 --- a/proto/canto/csr/v1/genesis.proto +++ b/proto/canto/csr/v1/genesis.proto @@ -12,5 +12,5 @@ message GenesisState { // params defines all of the parameters of the module Params params = 1 [ (gogoproto.nullable) = false ]; repeated CSR csrs = 2 [ (gogoproto.nullable) = false ]; - bytes turnstile_address = 3; + string turnstile_address = 3; } diff --git a/x/csr/genesis.go b/x/csr/genesis.go index 9fe53c9a..b704827f 100644 --- a/x/csr/genesis.go +++ b/x/csr/genesis.go @@ -17,8 +17,9 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, accountKeeper authkeeper.Acco for _, csr := range genState.Csrs { k.SetCSR(ctx, csr) } - if genState.TurnstileAddress != nil { - k.SetTurnstile(ctx, common.BytesToAddress(genState.TurnstileAddress)) + if genState.TurnstileAddress != "" { + turnstileAddress := common.HexToAddress(genState.TurnstileAddress) + k.SetTurnstile(ctx, turnstileAddress) } // make sure that the csr module account is set on genesis if acc := accountKeeper.GetModuleAccount(ctx, types.ModuleName); acc == nil { @@ -41,9 +42,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { turnstileAddr, ok := k.GetTurnstile(ctx) if ok { - genesis.TurnstileAddress = turnstileAddr.Bytes() - } else { - genesis.TurnstileAddress = nil + genesis.TurnstileAddress = turnstileAddr.String() } return genesis diff --git a/x/csr/keeper/genesis_test.go b/x/csr/keeper/genesis_test.go index e01b1463..86e0ee76 100644 --- a/x/csr/keeper/genesis_test.go +++ b/x/csr/keeper/genesis_test.go @@ -23,7 +23,7 @@ func (suite *KeeperTestSuite) TestImportExportGenesisEmpty() { suite.Require().Empty(csrs) genState := csr.ExportGenesis(suite.ctx, suite.app.CSRKeeper) - suite.Require().Nil(genState.TurnstileAddress) + suite.Require().Equal("", genState.TurnstileAddress) suite.Require().Empty(genState.Csrs) // Copy genState to genState2 and init with it @@ -39,7 +39,7 @@ func (suite *KeeperTestSuite) TestImportExportGenesisEmpty() { genState3 := csr.ExportGenesis(suite.ctx, suite.app.CSRKeeper) suite.Equal(*genState, genState2) suite.Equal(genState2, *genState3) - suite.Require().Nil(genState3.TurnstileAddress) + suite.Require().Equal("", genState3.TurnstileAddress) suite.Require().Empty(genState3.Csrs) } diff --git a/x/csr/types/genesis.go b/x/csr/types/genesis.go index 783f5211..04abf811 100644 --- a/x/csr/types/genesis.go +++ b/x/csr/types/genesis.go @@ -5,10 +5,10 @@ const DefaultIndex uint64 = 1 // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { - return NewGenesisState(DefaultParams(), []CSR{}, nil) + return NewGenesisState(DefaultParams(), []CSR{}, "") } -func NewGenesisState(params Params, csrs []CSR, turnstileAddress []byte) *GenesisState { +func NewGenesisState(params Params, csrs []CSR, turnstileAddress string) *GenesisState { return &GenesisState{ Params: params, Csrs: csrs, diff --git a/x/csr/types/genesis.pb.go b/x/csr/types/genesis.pb.go index 830cc6ad..307d60c8 100644 --- a/x/csr/types/genesis.pb.go +++ b/x/csr/types/genesis.pb.go @@ -28,7 +28,7 @@ type GenesisState struct { // params defines all of the parameters of the module Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` Csrs []CSR `protobuf:"bytes,2,rep,name=csrs,proto3" json:"csrs"` - TurnstileAddress []byte `protobuf:"bytes,3,opt,name=turnstile_address,json=turnstileAddress,proto3" json:"turnstile_address,omitempty"` + TurnstileAddress string `protobuf:"bytes,3,opt,name=turnstile_address,json=turnstileAddress,proto3" json:"turnstile_address,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -78,11 +78,11 @@ func (m *GenesisState) GetCsrs() []CSR { return nil } -func (m *GenesisState) GetTurnstileAddress() []byte { +func (m *GenesisState) GetTurnstileAddress() string { if m != nil { return m.TurnstileAddress } - return nil + return "" } func init() { @@ -104,12 +104,12 @@ var fileDescriptor_4c1065f59845b427 = []byte{ 0x25, 0xb9, 0xb8, 0xa8, 0x58, 0x82, 0x49, 0x81, 0x59, 0x83, 0xdb, 0x48, 0x10, 0x55, 0x87, 0x73, 0x70, 0x10, 0x54, 0x39, 0x58, 0x91, 0x90, 0x36, 0x97, 0x60, 0x49, 0x69, 0x51, 0x5e, 0x71, 0x49, 0x66, 0x4e, 0x6a, 0x7c, 0x62, 0x4a, 0x4a, 0x51, 0x6a, 0x71, 0xb1, 0x04, 0xb3, 0x02, 0xa3, 0x06, - 0x4f, 0x90, 0x00, 0x5c, 0xc2, 0x11, 0x22, 0xee, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, + 0x67, 0x90, 0x00, 0x5c, 0xc2, 0x11, 0x22, 0xee, 0xe4, 0x7e, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0xba, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xce, 0x20, 0xfb, 0x74, 0xfd, 0x52, 0x4b, 0xca, 0xf3, 0x8b, 0xb2, 0x21, 0x3c, 0xfd, 0x32, 0x73, 0xfd, 0x0a, 0xb0, 0x77, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0x93, 0xd8, 0xc0, 0xde, 0x35, 0x06, 0x04, - 0x00, 0x00, 0xff, 0xff, 0xf7, 0xd8, 0x67, 0x34, 0x63, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x5f, 0x02, 0xf6, 0x4c, 0x63, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -304,7 +304,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field TurnstileAddress", wireType) } - var byteLen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -314,25 +314,23 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - byteLen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if byteLen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthGenesis } - postIndex := iNdEx + byteLen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthGenesis } if postIndex > l { return io.ErrUnexpectedEOF } - m.TurnstileAddress = append(m.TurnstileAddress[:0], dAtA[iNdEx:postIndex]...) - if m.TurnstileAddress == nil { - m.TurnstileAddress = []byte{} - } + m.TurnstileAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex default: iNdEx = preIndex