From 2d5e8c22d58c2fe8a3d653bcf4c2e7833d2ebde3 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 12 Jun 2024 07:24:59 +0200 Subject: [PATCH 1/5] add genesis accounts --- api/cosmos/accounts/v1/genesis.pulsar.go | 244 ++++++++++++++---- api/cosmos/circuit/v1/tx_grpc.pb.go | 2 +- x/accounts/genesis.go | 8 + x/accounts/genesis_test.go | 16 ++ x/accounts/keeper.go | 18 ++ x/accounts/msg_server.go | 17 +- .../proto/cosmos/accounts/v1/genesis.proto | 4 + x/accounts/v1/genesis.pb.go | 104 ++++++-- x/circuit/types/tx.pb.go | 2 +- 9 files changed, 336 insertions(+), 79 deletions(-) diff --git a/api/cosmos/accounts/v1/genesis.pulsar.go b/api/cosmos/accounts/v1/genesis.pulsar.go index 0dcbfa57eea6..391e078901e4 100644 --- a/api/cosmos/accounts/v1/genesis.pulsar.go +++ b/api/cosmos/accounts/v1/genesis.pulsar.go @@ -63,10 +63,62 @@ func (x *_GenesisState_2_list) IsValid() bool { return x.list != nil } +var _ protoreflect.List = (*_GenesisState_3_list)(nil) + +type _GenesisState_3_list struct { + list *[]*MsgInit +} + +func (x *_GenesisState_3_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_GenesisState_3_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_GenesisState_3_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*MsgInit) + (*x.list)[i] = concreteValue +} + +func (x *_GenesisState_3_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*MsgInit) + *x.list = append(*x.list, concreteValue) +} + +func (x *_GenesisState_3_list) AppendMutable() protoreflect.Value { + v := new(MsgInit) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_GenesisState_3_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_GenesisState_3_list) NewElement() protoreflect.Value { + v := new(MsgInit) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_GenesisState_3_list) IsValid() bool { + return x.list != nil +} + var ( - md_GenesisState protoreflect.MessageDescriptor - fd_GenesisState_account_number protoreflect.FieldDescriptor - fd_GenesisState_accounts protoreflect.FieldDescriptor + md_GenesisState protoreflect.MessageDescriptor + fd_GenesisState_account_number protoreflect.FieldDescriptor + fd_GenesisState_accounts protoreflect.FieldDescriptor + fd_GenesisState_init_account_msgs protoreflect.FieldDescriptor ) func init() { @@ -74,6 +126,7 @@ func init() { md_GenesisState = File_cosmos_accounts_v1_genesis_proto.Messages().ByName("GenesisState") fd_GenesisState_account_number = md_GenesisState.Fields().ByName("account_number") fd_GenesisState_accounts = md_GenesisState.Fields().ByName("accounts") + fd_GenesisState_init_account_msgs = md_GenesisState.Fields().ByName("init_account_msgs") } var _ protoreflect.Message = (*fastReflection_GenesisState)(nil) @@ -153,6 +206,12 @@ func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor, return } } + if len(x.InitAccountMsgs) != 0 { + value := protoreflect.ValueOfList(&_GenesisState_3_list{list: &x.InitAccountMsgs}) + if !f(fd_GenesisState_init_account_msgs, value) { + return + } + } } // Has reports whether a field is populated. @@ -172,6 +231,8 @@ func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool return x.AccountNumber != uint64(0) case "cosmos.accounts.v1.GenesisState.accounts": return len(x.Accounts) != 0 + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + return len(x.InitAccountMsgs) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -192,6 +253,8 @@ func (x *fastReflection_GenesisState) Clear(fd protoreflect.FieldDescriptor) { x.AccountNumber = uint64(0) case "cosmos.accounts.v1.GenesisState.accounts": x.Accounts = nil + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + x.InitAccountMsgs = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -217,6 +280,12 @@ func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescripto } listValue := &_GenesisState_2_list{list: &x.Accounts} return protoreflect.ValueOfList(listValue) + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + if len(x.InitAccountMsgs) == 0 { + return protoreflect.ValueOfList(&_GenesisState_3_list{}) + } + listValue := &_GenesisState_3_list{list: &x.InitAccountMsgs} + return protoreflect.ValueOfList(listValue) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -243,6 +312,10 @@ func (x *fastReflection_GenesisState) Set(fd protoreflect.FieldDescriptor, value lv := value.List() clv := lv.(*_GenesisState_2_list) x.Accounts = *clv.list + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + lv := value.List() + clv := lv.(*_GenesisState_3_list) + x.InitAccountMsgs = *clv.list default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -269,6 +342,12 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p } value := &_GenesisState_2_list{list: &x.Accounts} return protoreflect.ValueOfList(value) + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + if x.InitAccountMsgs == nil { + x.InitAccountMsgs = []*MsgInit{} + } + value := &_GenesisState_3_list{list: &x.InitAccountMsgs} + return protoreflect.ValueOfList(value) case "cosmos.accounts.v1.GenesisState.account_number": panic(fmt.Errorf("field account_number of message cosmos.accounts.v1.GenesisState is not mutable")) default: @@ -289,6 +368,9 @@ func (x *fastReflection_GenesisState) NewField(fd protoreflect.FieldDescriptor) case "cosmos.accounts.v1.GenesisState.accounts": list := []*GenesisAccount{} return protoreflect.ValueOfList(&_GenesisState_2_list{list: &list}) + case "cosmos.accounts.v1.GenesisState.init_account_msgs": + list := []*MsgInit{} + return protoreflect.ValueOfList(&_GenesisState_3_list{list: &list}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -367,6 +449,12 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { n += 1 + l + runtime.Sov(uint64(l)) } } + if len(x.InitAccountMsgs) > 0 { + for _, e := range x.InitAccountMsgs { + l = options.Size(e) + n += 1 + l + runtime.Sov(uint64(l)) + } + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -396,6 +484,22 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.InitAccountMsgs) > 0 { + for iNdEx := len(x.InitAccountMsgs) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.InitAccountMsgs[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1a + } + } if len(x.Accounts) > 0 { for iNdEx := len(x.Accounts) - 1; iNdEx >= 0; iNdEx-- { encoded, err := options.Marshal(x.Accounts[iNdEx]) @@ -519,6 +623,40 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field InitAccountMsgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + 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.InitAccountMsgs = append(x.InitAccountMsgs, &MsgInit{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.InitAccountMsgs[len(x.InitAccountMsgs)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -1735,6 +1873,8 @@ type GenesisState struct { AccountNumber uint64 `protobuf:"varint,1,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` // accounts are the genesis accounts. Accounts []*GenesisAccount `protobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts,omitempty"` + // init_accounts_msgs defines the genesis messages that will be executed to init the account. + InitAccountMsgs []*MsgInit `protobuf:"bytes,3,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` } func (x *GenesisState) Reset() { @@ -1771,6 +1911,13 @@ func (x *GenesisState) GetAccounts() []*GenesisAccount { return nil } +func (x *GenesisState) GetInitAccountMsgs() []*MsgInit { + if x != nil { + return x.InitAccountMsgs + } + return nil +} + // GenesisAccount defines an account to be initialized in the genesis state. type GenesisAccount struct { state protoimpl.MessageState @@ -1887,41 +2034,47 @@ var file_cosmos_accounts_v1_genesis_proto_rawDesc = []byte{ 0x0a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x22, 0x75, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, - 0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x3e, 0x0a, - 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x22, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0xa6, 0x01, - 0x0a, 0x0e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, - 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, - 0x6d, 0x62, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x52, - 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x30, 0x0a, 0x06, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, - 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, - 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0xc0, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, - 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, - 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, - 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, 0xaa, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, - 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, - 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1e, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x78, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0xbe, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, + 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x3e, 0x0a, 0x08, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, + 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x47, 0x0a, 0x11, 0x69, + 0x6e, 0x69, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6d, 0x73, 0x67, 0x73, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, + 0x6e, 0x69, 0x74, 0x52, 0x0f, 0x69, 0x6e, 0x69, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x4d, 0x73, 0x67, 0x73, 0x22, 0xa6, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, + 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, + 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, + 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x05, 0x73, + 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x30, 0x0a, + 0x06, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, + 0xc0, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, + 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, + 0xaa, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1e, 0x43, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0x5c, + 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x43, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x3a, 0x3a, + 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1941,15 +2094,17 @@ var file_cosmos_accounts_v1_genesis_proto_goTypes = []interface{}{ (*GenesisState)(nil), // 0: cosmos.accounts.v1.GenesisState (*GenesisAccount)(nil), // 1: cosmos.accounts.v1.GenesisAccount (*KVPair)(nil), // 2: cosmos.accounts.v1.KVPair + (*MsgInit)(nil), // 3: cosmos.accounts.v1.MsgInit } var file_cosmos_accounts_v1_genesis_proto_depIdxs = []int32{ 1, // 0: cosmos.accounts.v1.GenesisState.accounts:type_name -> cosmos.accounts.v1.GenesisAccount - 2, // 1: cosmos.accounts.v1.GenesisAccount.state:type_name -> cosmos.accounts.v1.KVPair - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 3, // 1: cosmos.accounts.v1.GenesisState.init_account_msgs:type_name -> cosmos.accounts.v1.MsgInit + 2, // 2: cosmos.accounts.v1.GenesisAccount.state:type_name -> cosmos.accounts.v1.KVPair + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_cosmos_accounts_v1_genesis_proto_init() } @@ -1957,6 +2112,7 @@ func file_cosmos_accounts_v1_genesis_proto_init() { if File_cosmos_accounts_v1_genesis_proto != nil { return } + file_cosmos_accounts_v1_tx_proto_init() if !protoimpl.UnsafeEnabled { file_cosmos_accounts_v1_genesis_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GenesisState); i { diff --git a/api/cosmos/circuit/v1/tx_grpc.pb.go b/api/cosmos/circuit/v1/tx_grpc.pb.go index a3b22335e577..2b4b95d37fe2 100644 --- a/api/cosmos/circuit/v1/tx_grpc.pb.go +++ b/api/cosmos/circuit/v1/tx_grpc.pb.go @@ -83,7 +83,7 @@ type MsgServer interface { // TripCircuitBreaker pauses processing of Msg's in the state machine. TripCircuitBreaker(context.Context, *MsgTripCircuitBreaker) (*MsgTripCircuitBreakerResponse, error) // ResetCircuitBreaker resumes processing of Msg's in the state machine that - // have been been paused using TripCircuitBreaker. + // have been paused using TripCircuitBreaker. ResetCircuitBreaker(context.Context, *MsgResetCircuitBreaker) (*MsgResetCircuitBreakerResponse, error) mustEmbedUnimplementedMsgServer() } diff --git a/x/accounts/genesis.go b/x/accounts/genesis.go index bd0f9edc0b4d..8c9d35bf7919 100644 --- a/x/accounts/genesis.go +++ b/x/accounts/genesis.go @@ -76,6 +76,14 @@ func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) erro return fmt.Errorf("%w: %s", err, acc.Address) } } + + // after this execute account creation msgs. + for index, msgInit := range genState.InitAccountMsgs { + _, _, err = k.initFromMsg(ctx, msgInit) + if err != nil { + return fmt.Errorf("invalid genesis account msg init at index %d, msg %s: %w", index, msgInit, err) + } + } return nil } diff --git a/x/accounts/genesis_test.go b/x/accounts/genesis_test.go index 357fb8eb6628..b58b21f4b5af 100644 --- a/x/accounts/genesis_test.go +++ b/x/accounts/genesis_test.go @@ -39,6 +39,15 @@ func TestGenesis(t *testing.T) { acc, err := NewTestAccount(deps) return testAccountType, acc, err }) + // add to state a genesis account init msg. + initMsg, err := implementation.PackAny(&types.Empty{}) + require.NoError(t, err) + state.InitAccountMsgs = append(state.InitAccountMsgs, &v1.MsgInit{ + Sender: "sender-2", + AccountType: testAccountType, + Message: initMsg, + Funds: nil, + }) err = k.ImportState(ctx, state) require.NoError(t, err) @@ -51,6 +60,13 @@ func TestGenesis(t *testing.T) { resp, err = k.Query(ctx, addr2, &types.DoubleValue{}) require.NoError(t, err) require.Equal(t, &types.UInt64Value{Value: 20}, resp) + + // check initted on genesis account + addr3, err := k.makeAddress(2) + require.NoError(t, err) + resp, err = k.Query(ctx, addr3, &types.DoubleValue{}) + require.NoError(t, err) + require.Equal(t, &types.UInt64Value{Value: 0}, resp) } func TestImportAccountError(t *testing.T) { diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index a58c32604065..ff5daa1cf8b2 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" + v1 "cosmossdk.io/x/accounts/v1" "google.golang.org/protobuf/runtime/protoiface" "cosmossdk.io/collections" @@ -156,6 +157,23 @@ func (k Keeper) Init( return initResp, accountAddr, nil } +// initFromMsg is a helper which inits an account given a v1.MsgInit. +func (k Keeper) initFromMsg(ctx context.Context, initMsg *v1.MsgInit) (implementation.ProtoMsg, []byte, error) { + creator, err := k.addressCodec.StringToBytes(initMsg.Sender) + if err != nil { + return nil, nil, err + } + + // decode message bytes into the concrete boxed message type + msg, err := implementation.UnpackAnyRaw(initMsg.Message) + if err != nil { + return nil, nil, err + } + + // run account creation logic + return k.Init(ctx, initMsg.AccountType, creator, msg, initMsg.Funds) +} + // init initializes the account, given the type, the creator the newly created account number, its address and the // initialization message. func (k Keeper) init( diff --git a/x/accounts/msg_server.go b/x/accounts/msg_server.go index 182d7025d119..372941cece0e 100644 --- a/x/accounts/msg_server.go +++ b/x/accounts/msg_server.go @@ -2,6 +2,7 @@ package accounts import ( "context" + "fmt" "cosmossdk.io/core/event" "cosmossdk.io/x/accounts/internal/implementation" @@ -19,21 +20,9 @@ type msgServer struct { } func (m msgServer) Init(ctx context.Context, request *v1.MsgInit) (*v1.MsgInitResponse, error) { - creator, err := m.k.addressCodec.StringToBytes(request.Sender) + resp, accAddr, err := m.k.initFromMsg(ctx, request) if err != nil { - return nil, err - } - - // decode message bytes into the concrete boxed message type - msg, err := implementation.UnpackAnyRaw(request.Message) - if err != nil { - return nil, err - } - - // run account creation logic - resp, accAddr, err := m.k.Init(ctx, request.AccountType, creator, msg, request.Funds) - if err != nil { - return nil, err + return nil, fmt.Errorf("unable to initialize account: %w", err) } // encode the address diff --git a/x/accounts/proto/cosmos/accounts/v1/genesis.proto b/x/accounts/proto/cosmos/accounts/v1/genesis.proto index 83e9dc385b44..99ab34b55b2f 100644 --- a/x/accounts/proto/cosmos/accounts/v1/genesis.proto +++ b/x/accounts/proto/cosmos/accounts/v1/genesis.proto @@ -4,12 +4,16 @@ package cosmos.accounts.v1; option go_package = "cosmossdk.io/x/accounts/v1"; +import "cosmos/accounts/v1/tx.proto"; + // GenesisState defines the accounts' module's genesis state. message GenesisState { // account_number is the latest account number. uint64 account_number = 1; // accounts are the genesis accounts. repeated GenesisAccount accounts = 2; + // init_accounts_msgs defines the genesis messages that will be executed to init the account. + repeated cosmos.accounts.v1.MsgInit init_account_msgs = 3; } // GenesisAccount defines an account to be initialized in the genesis state. diff --git a/x/accounts/v1/genesis.pb.go b/x/accounts/v1/genesis.pb.go index b06b43e903df..dc061c42e85e 100644 --- a/x/accounts/v1/genesis.pb.go +++ b/x/accounts/v1/genesis.pb.go @@ -28,6 +28,8 @@ type GenesisState struct { AccountNumber uint64 `protobuf:"varint,1,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` // accounts are the genesis accounts. Accounts []*GenesisAccount `protobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts,omitempty"` + // init_accounts_msgs defines the genesis messages that will be executed to init the account. + InitAccountMsgs []*MsgInit `protobuf:"bytes,3,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -77,6 +79,13 @@ func (m *GenesisState) GetAccounts() []*GenesisAccount { return nil } +func (m *GenesisState) GetInitAccountMsgs() []*MsgInit { + if m != nil { + return m.InitAccountMsgs + } + return nil +} + // GenesisAccount defines an account to be initialized in the genesis state. type GenesisAccount struct { // address is the address of the account. @@ -214,25 +223,28 @@ func init() { func init() { proto.RegisterFile("cosmos/accounts/v1/genesis.proto", fileDescriptor_409859d32eae9438) } var fileDescriptor_409859d32eae9438 = []byte{ - // 285 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x48, 0xce, 0x2f, 0xce, - 0xcd, 0x2f, 0xd6, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x2f, 0x33, 0xd4, 0x4f, - 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x82, 0xa8, - 0xd0, 0x83, 0xa9, 0xd0, 0x2b, 0x33, 0x54, 0x2a, 0xe5, 0xe2, 0x71, 0x87, 0x28, 0x0a, 0x2e, 0x49, - 0x2c, 0x49, 0x15, 0x52, 0xe5, 0xe2, 0x83, 0x4a, 0xc7, 0xe7, 0x95, 0xe6, 0x26, 0xa5, 0x16, 0x49, - 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x04, 0xf1, 0x42, 0x45, 0xfd, 0xc0, 0x82, 0x42, 0x76, 0x5c, 0x1c, - 0x30, 0x53, 0x24, 0x98, 0x14, 0x98, 0x35, 0xb8, 0x8d, 0x94, 0xf4, 0x30, 0x4d, 0xd7, 0x83, 0x1a, - 0xed, 0x08, 0x11, 0x0a, 0x82, 0xeb, 0x51, 0x5a, 0xc6, 0xc8, 0xc5, 0x87, 0x2a, 0x29, 0x24, 0xc1, - 0xc5, 0x9e, 0x98, 0x92, 0x52, 0x94, 0x5a, 0x5c, 0x0c, 0xb6, 0x92, 0x33, 0x08, 0xc6, 0x15, 0x52, - 0xe4, 0xe2, 0x81, 0xb9, 0xa9, 0xa4, 0xb2, 0x20, 0x55, 0x82, 0x09, 0x2c, 0xcd, 0x0d, 0x15, 0x0b, - 0xa9, 0x2c, 0xc0, 0xe6, 0x6c, 0x66, 0x6c, 0xce, 0x36, 0xe0, 0x62, 0x2d, 0x06, 0x79, 0x53, 0x82, - 0x05, 0xec, 0x66, 0x29, 0x6c, 0x6e, 0xf6, 0x0e, 0x0b, 0x48, 0xcc, 0x2c, 0x0a, 0x82, 0x28, 0x54, - 0x32, 0xe0, 0x62, 0x83, 0x08, 0x08, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x82, 0xdd, 0xc6, 0x13, - 0x04, 0x62, 0x0a, 0x89, 0x70, 0xb1, 0x96, 0x25, 0xe6, 0x94, 0x42, 0x1c, 0xc4, 0x13, 0x04, 0xe1, - 0x38, 0x99, 0x9c, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, - 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x14, 0xc4, 0xb6, - 0xe2, 0x94, 0x6c, 0xbd, 0xcc, 0x7c, 0xfd, 0x0a, 0xe4, 0x98, 0x4a, 0x62, 0x03, 0x47, 0x91, 0x31, - 0x20, 0x00, 0x00, 0xff, 0xff, 0x52, 0xae, 0xf2, 0xc5, 0xc6, 0x01, 0x00, 0x00, + // 332 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x51, 0xcd, 0x4e, 0xc2, 0x40, + 0x10, 0x66, 0x29, 0xa0, 0x0e, 0x15, 0x75, 0xe3, 0xa1, 0x81, 0xa4, 0xc1, 0x26, 0x26, 0x9c, 0x5a, + 0x50, 0xcf, 0x26, 0x7a, 0x21, 0xc6, 0x60, 0xcc, 0x6a, 0x3c, 0x78, 0x21, 0x05, 0x36, 0xcd, 0x06, + 0xe9, 0x92, 0xce, 0x42, 0xe0, 0x2d, 0x7c, 0x0a, 0x1f, 0xc3, 0xb3, 0x47, 0x8e, 0x1e, 0x0d, 0xbc, + 0x88, 0x61, 0xb7, 0x35, 0x1a, 0x7b, 0xeb, 0x7c, 0xfd, 0xfe, 0x66, 0x07, 0x9a, 0x43, 0x89, 0x13, + 0x89, 0x41, 0x38, 0x1c, 0xca, 0x59, 0xac, 0x30, 0x98, 0x77, 0x82, 0x88, 0xc7, 0x1c, 0x05, 0xfa, + 0xd3, 0x44, 0x2a, 0x49, 0xa9, 0x61, 0xf8, 0x19, 0xc3, 0x9f, 0x77, 0xea, 0x8d, 0x1c, 0x95, 0x5a, + 0x18, 0x81, 0xf7, 0x4e, 0xc0, 0xee, 0x1a, 0x8b, 0x07, 0x15, 0x2a, 0x4e, 0x4f, 0xa1, 0x96, 0x12, + 0xfb, 0xf1, 0x6c, 0x32, 0xe0, 0x89, 0x43, 0x9a, 0xa4, 0x55, 0x62, 0xfb, 0x29, 0x7a, 0xa7, 0x41, + 0x7a, 0x09, 0xbb, 0x99, 0x9f, 0x53, 0x6c, 0x5a, 0xad, 0xea, 0x99, 0xe7, 0xff, 0xcf, 0xf6, 0x53, + 0xeb, 0x2b, 0x03, 0xb1, 0x1f, 0x0d, 0xed, 0xc2, 0x91, 0x88, 0x85, 0xea, 0x67, 0x59, 0x13, 0x8c, + 0xd0, 0xb1, 0xb4, 0x51, 0x23, 0xcf, 0xa8, 0x87, 0xd1, 0x4d, 0x2c, 0x14, 0x3b, 0xd8, 0xaa, 0x52, + 0xbb, 0x1e, 0x46, 0xe8, 0xbd, 0x11, 0xa8, 0xfd, 0x4d, 0xa1, 0x0e, 0xec, 0x84, 0xa3, 0x51, 0xc2, + 0x11, 0x75, 0xf7, 0x3d, 0x96, 0x8d, 0xf4, 0x04, 0xec, 0x2c, 0x50, 0x2d, 0xa7, 0xdc, 0x29, 0xea, + 0xdf, 0xd5, 0x14, 0x7b, 0x5c, 0x4e, 0xf3, 0xf6, 0xb7, 0xf2, 0xf6, 0x6f, 0x43, 0x19, 0xb7, 0xef, + 0xe5, 0x94, 0x74, 0xe7, 0x7a, 0x5e, 0xe7, 0xdb, 0xa7, 0xfb, 0x50, 0x24, 0xcc, 0x10, 0xbd, 0x36, + 0x54, 0x0c, 0x40, 0x0f, 0xc1, 0x1a, 0xf3, 0xa5, 0xee, 0x66, 0xb3, 0xed, 0x27, 0x3d, 0x86, 0xf2, + 0x3c, 0x7c, 0x99, 0x99, 0x42, 0x36, 0x33, 0xc3, 0xf5, 0xc5, 0xc7, 0xda, 0x25, 0xab, 0xb5, 0x4b, + 0xbe, 0xd6, 0x2e, 0x79, 0xdd, 0xb8, 0x85, 0xd5, 0xc6, 0x2d, 0x7c, 0x6e, 0xdc, 0xc2, 0x73, 0xdd, + 0xa4, 0xe1, 0x68, 0xec, 0x0b, 0x19, 0x2c, 0x7e, 0x9f, 0x76, 0x50, 0xd1, 0x87, 0x3d, 0xff, 0x0e, + 0x00, 0x00, 0xff, 0xff, 0xe5, 0x36, 0x4e, 0xfe, 0x2d, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -255,6 +267,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.InitAccountMsgs) > 0 { + for iNdEx := len(m.InitAccountMsgs) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.InitAccountMsgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } if len(m.Accounts) > 0 { for iNdEx := len(m.Accounts) - 1; iNdEx >= 0; iNdEx-- { { @@ -396,6 +422,12 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.InitAccountMsgs) > 0 { + for _, e := range m.InitAccountMsgs { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -530,6 +562,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InitAccountMsgs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InitAccountMsgs = append(m.InitAccountMsgs, &MsgInit{}) + if err := m.InitAccountMsgs[len(m.InitAccountMsgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/circuit/types/tx.pb.go b/x/circuit/types/tx.pb.go index 667cce9d9d7a..61b184831ac3 100644 --- a/x/circuit/types/tx.pb.go +++ b/x/circuit/types/tx.pb.go @@ -453,7 +453,7 @@ type MsgServer interface { // TripCircuitBreaker pauses processing of Msg's in the state machine. TripCircuitBreaker(context.Context, *MsgTripCircuitBreaker) (*MsgTripCircuitBreakerResponse, error) // ResetCircuitBreaker resumes processing of Msg's in the state machine that - // have been been paused using TripCircuitBreaker. + // have been paused using TripCircuitBreaker. ResetCircuitBreaker(context.Context, *MsgResetCircuitBreaker) (*MsgResetCircuitBreakerResponse, error) } From 18ed52e030a84c6a04b53a9487308ec672f5d29d Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 12 Jun 2024 07:29:25 +0200 Subject: [PATCH 2/5] lint --- x/accounts/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index ff5daa1cf8b2..4ce0e8f0102a 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" - v1 "cosmossdk.io/x/accounts/v1" "google.golang.org/protobuf/runtime/protoiface" "cosmossdk.io/collections" @@ -16,6 +15,7 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/x/accounts/accountstd" "cosmossdk.io/x/accounts/internal/implementation" + v1 "cosmossdk.io/x/accounts/v1" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" From 3185f5ba5c6c7a18b551089dc14376627d4624ac Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 12 Jun 2024 15:11:52 +0200 Subject: [PATCH 3/5] add docs --- x/accounts/README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/x/accounts/README.md b/x/accounts/README.md index 9ffcbed6ede4..f71284262d0a 100644 --- a/x/accounts/README.md +++ b/x/accounts/README.md @@ -1,3 +1,44 @@ # x/accounts -The x/accounts module provides module and facilities for writing smart cosmos-sdk accounts. \ No newline at end of file +The x/accounts module provides module and facilities for writing smart cosmos-sdk accounts. + +# Genesis + +## Creating accounts on genesis + +In order to create accounts at genesis, the `x/accounts` module allows developers to provide +a list of genesis `MsgInit` messages that will be executed in the `x/accounts` genesis flow. + +This follows the same initialization flow and rules that would happen if the chain is running. +The only concrete difference is that this is happening at the genesis block. + +For example, given the following `genesis.json` file: + +```json +{ + "app_state": { + "accounts": { + "init_account_msgs": [ + { + "sender": "account_creator_address", + "account_type": "lockup", + "message": { + "@type": "cosmos.accounts.defaults.lockup.MsgInitLockupAccount", + "owner": "some_owner", + "end_time": "..", + "start_time": ".." + }, + "funds": [ + { + "denom": "stake", + "amount": "1000" + } + ] + } + ] + } + } +} +``` + +The accounts module will run the lockup account initialization message. \ No newline at end of file From 2dc9a759d806458f209a0187295313fbf94ff0f2 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 12 Jun 2024 15:43:46 +0200 Subject: [PATCH 4/5] merge and fix genesis flow --- api/cosmos/accounts/v1/genesis.pulsar.go | 207 +++++++----------- x/accounts/genesis.go | 29 +-- x/accounts/genesis_test.go | 5 +- .../proto/cosmos/accounts/v1/genesis.proto | 6 +- x/accounts/v1/genesis.pb.go | 90 +++----- 5 files changed, 117 insertions(+), 220 deletions(-) diff --git a/api/cosmos/accounts/v1/genesis.pulsar.go b/api/cosmos/accounts/v1/genesis.pulsar.go index 391e078901e4..73fcc1ae59dc 100644 --- a/api/cosmos/accounts/v1/genesis.pulsar.go +++ b/api/cosmos/accounts/v1/genesis.pulsar.go @@ -12,111 +12,110 @@ import ( sync "sync" ) -var _ protoreflect.List = (*_GenesisState_2_list)(nil) +var _ protoreflect.List = (*_GenesisState_1_list)(nil) -type _GenesisState_2_list struct { +type _GenesisState_1_list struct { list *[]*GenesisAccount } -func (x *_GenesisState_2_list) Len() int { +func (x *_GenesisState_1_list) Len() int { if x.list == nil { return 0 } return len(*x.list) } -func (x *_GenesisState_2_list) Get(i int) protoreflect.Value { +func (x *_GenesisState_1_list) Get(i int) protoreflect.Value { return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) } -func (x *_GenesisState_2_list) Set(i int, value protoreflect.Value) { +func (x *_GenesisState_1_list) Set(i int, value protoreflect.Value) { valueUnwrapped := value.Message() concreteValue := valueUnwrapped.Interface().(*GenesisAccount) (*x.list)[i] = concreteValue } -func (x *_GenesisState_2_list) Append(value protoreflect.Value) { +func (x *_GenesisState_1_list) Append(value protoreflect.Value) { valueUnwrapped := value.Message() concreteValue := valueUnwrapped.Interface().(*GenesisAccount) *x.list = append(*x.list, concreteValue) } -func (x *_GenesisState_2_list) AppendMutable() protoreflect.Value { +func (x *_GenesisState_1_list) AppendMutable() protoreflect.Value { v := new(GenesisAccount) *x.list = append(*x.list, v) return protoreflect.ValueOfMessage(v.ProtoReflect()) } -func (x *_GenesisState_2_list) Truncate(n int) { +func (x *_GenesisState_1_list) Truncate(n int) { for i := n; i < len(*x.list); i++ { (*x.list)[i] = nil } *x.list = (*x.list)[:n] } -func (x *_GenesisState_2_list) NewElement() protoreflect.Value { +func (x *_GenesisState_1_list) NewElement() protoreflect.Value { v := new(GenesisAccount) return protoreflect.ValueOfMessage(v.ProtoReflect()) } -func (x *_GenesisState_2_list) IsValid() bool { +func (x *_GenesisState_1_list) IsValid() bool { return x.list != nil } -var _ protoreflect.List = (*_GenesisState_3_list)(nil) +var _ protoreflect.List = (*_GenesisState_2_list)(nil) -type _GenesisState_3_list struct { +type _GenesisState_2_list struct { list *[]*MsgInit } -func (x *_GenesisState_3_list) Len() int { +func (x *_GenesisState_2_list) Len() int { if x.list == nil { return 0 } return len(*x.list) } -func (x *_GenesisState_3_list) Get(i int) protoreflect.Value { +func (x *_GenesisState_2_list) Get(i int) protoreflect.Value { return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) } -func (x *_GenesisState_3_list) Set(i int, value protoreflect.Value) { +func (x *_GenesisState_2_list) Set(i int, value protoreflect.Value) { valueUnwrapped := value.Message() concreteValue := valueUnwrapped.Interface().(*MsgInit) (*x.list)[i] = concreteValue } -func (x *_GenesisState_3_list) Append(value protoreflect.Value) { +func (x *_GenesisState_2_list) Append(value protoreflect.Value) { valueUnwrapped := value.Message() concreteValue := valueUnwrapped.Interface().(*MsgInit) *x.list = append(*x.list, concreteValue) } -func (x *_GenesisState_3_list) AppendMutable() protoreflect.Value { +func (x *_GenesisState_2_list) AppendMutable() protoreflect.Value { v := new(MsgInit) *x.list = append(*x.list, v) return protoreflect.ValueOfMessage(v.ProtoReflect()) } -func (x *_GenesisState_3_list) Truncate(n int) { +func (x *_GenesisState_2_list) Truncate(n int) { for i := n; i < len(*x.list); i++ { (*x.list)[i] = nil } *x.list = (*x.list)[:n] } -func (x *_GenesisState_3_list) NewElement() protoreflect.Value { +func (x *_GenesisState_2_list) NewElement() protoreflect.Value { v := new(MsgInit) return protoreflect.ValueOfMessage(v.ProtoReflect()) } -func (x *_GenesisState_3_list) IsValid() bool { +func (x *_GenesisState_2_list) IsValid() bool { return x.list != nil } var ( md_GenesisState protoreflect.MessageDescriptor - fd_GenesisState_account_number protoreflect.FieldDescriptor fd_GenesisState_accounts protoreflect.FieldDescriptor fd_GenesisState_init_account_msgs protoreflect.FieldDescriptor ) @@ -124,7 +123,6 @@ var ( func init() { file_cosmos_accounts_v1_genesis_proto_init() md_GenesisState = File_cosmos_accounts_v1_genesis_proto.Messages().ByName("GenesisState") - fd_GenesisState_account_number = md_GenesisState.Fields().ByName("account_number") fd_GenesisState_accounts = md_GenesisState.Fields().ByName("accounts") fd_GenesisState_init_account_msgs = md_GenesisState.Fields().ByName("init_account_msgs") } @@ -194,20 +192,14 @@ func (x *fastReflection_GenesisState) Interface() protoreflect.ProtoMessage { // While iterating, mutating operations may only be performed // on the current field descriptor. func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.AccountNumber != uint64(0) { - value := protoreflect.ValueOfUint64(x.AccountNumber) - if !f(fd_GenesisState_account_number, value) { - return - } - } if len(x.Accounts) != 0 { - value := protoreflect.ValueOfList(&_GenesisState_2_list{list: &x.Accounts}) + value := protoreflect.ValueOfList(&_GenesisState_1_list{list: &x.Accounts}) if !f(fd_GenesisState_accounts, value) { return } } if len(x.InitAccountMsgs) != 0 { - value := protoreflect.ValueOfList(&_GenesisState_3_list{list: &x.InitAccountMsgs}) + value := protoreflect.ValueOfList(&_GenesisState_2_list{list: &x.InitAccountMsgs}) if !f(fd_GenesisState_init_account_msgs, value) { return } @@ -227,8 +219,6 @@ func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor, // a repeated field is populated if it is non-empty. func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool { switch fd.FullName() { - case "cosmos.accounts.v1.GenesisState.account_number": - return x.AccountNumber != uint64(0) case "cosmos.accounts.v1.GenesisState.accounts": return len(x.Accounts) != 0 case "cosmos.accounts.v1.GenesisState.init_account_msgs": @@ -249,8 +239,6 @@ func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool // Clear is a mutating operation and unsafe for concurrent use. func (x *fastReflection_GenesisState) Clear(fd protoreflect.FieldDescriptor) { switch fd.FullName() { - case "cosmos.accounts.v1.GenesisState.account_number": - x.AccountNumber = uint64(0) case "cosmos.accounts.v1.GenesisState.accounts": x.Accounts = nil case "cosmos.accounts.v1.GenesisState.init_account_msgs": @@ -271,20 +259,17 @@ func (x *fastReflection_GenesisState) Clear(fd protoreflect.FieldDescriptor) { // of the value; to obtain a mutable reference, use Mutable. func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { switch descriptor.FullName() { - case "cosmos.accounts.v1.GenesisState.account_number": - value := x.AccountNumber - return protoreflect.ValueOfUint64(value) case "cosmos.accounts.v1.GenesisState.accounts": if len(x.Accounts) == 0 { - return protoreflect.ValueOfList(&_GenesisState_2_list{}) + return protoreflect.ValueOfList(&_GenesisState_1_list{}) } - listValue := &_GenesisState_2_list{list: &x.Accounts} + listValue := &_GenesisState_1_list{list: &x.Accounts} return protoreflect.ValueOfList(listValue) case "cosmos.accounts.v1.GenesisState.init_account_msgs": if len(x.InitAccountMsgs) == 0 { - return protoreflect.ValueOfList(&_GenesisState_3_list{}) + return protoreflect.ValueOfList(&_GenesisState_2_list{}) } - listValue := &_GenesisState_3_list{list: &x.InitAccountMsgs} + listValue := &_GenesisState_2_list{list: &x.InitAccountMsgs} return protoreflect.ValueOfList(listValue) default: if descriptor.IsExtension() { @@ -306,15 +291,13 @@ func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescripto // Set is a mutating operation and unsafe for concurrent use. func (x *fastReflection_GenesisState) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { switch fd.FullName() { - case "cosmos.accounts.v1.GenesisState.account_number": - x.AccountNumber = value.Uint() case "cosmos.accounts.v1.GenesisState.accounts": lv := value.List() - clv := lv.(*_GenesisState_2_list) + clv := lv.(*_GenesisState_1_list) x.Accounts = *clv.list case "cosmos.accounts.v1.GenesisState.init_account_msgs": lv := value.List() - clv := lv.(*_GenesisState_3_list) + clv := lv.(*_GenesisState_2_list) x.InitAccountMsgs = *clv.list default: if fd.IsExtension() { @@ -340,16 +323,14 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p if x.Accounts == nil { x.Accounts = []*GenesisAccount{} } - value := &_GenesisState_2_list{list: &x.Accounts} + value := &_GenesisState_1_list{list: &x.Accounts} return protoreflect.ValueOfList(value) case "cosmos.accounts.v1.GenesisState.init_account_msgs": if x.InitAccountMsgs == nil { x.InitAccountMsgs = []*MsgInit{} } - value := &_GenesisState_3_list{list: &x.InitAccountMsgs} + value := &_GenesisState_2_list{list: &x.InitAccountMsgs} return protoreflect.ValueOfList(value) - case "cosmos.accounts.v1.GenesisState.account_number": - panic(fmt.Errorf("field account_number of message cosmos.accounts.v1.GenesisState is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -363,14 +344,12 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p // For lists, maps, and messages, this returns a new, empty, mutable value. func (x *fastReflection_GenesisState) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { switch fd.FullName() { - case "cosmos.accounts.v1.GenesisState.account_number": - return protoreflect.ValueOfUint64(uint64(0)) case "cosmos.accounts.v1.GenesisState.accounts": list := []*GenesisAccount{} - return protoreflect.ValueOfList(&_GenesisState_2_list{list: &list}) + return protoreflect.ValueOfList(&_GenesisState_1_list{list: &list}) case "cosmos.accounts.v1.GenesisState.init_account_msgs": list := []*MsgInit{} - return protoreflect.ValueOfList(&_GenesisState_3_list{list: &list}) + return protoreflect.ValueOfList(&_GenesisState_2_list{list: &list}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.v1.GenesisState")) @@ -440,9 +419,6 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { var n int var l int _ = l - if x.AccountNumber != 0 { - n += 1 + runtime.Sov(uint64(x.AccountNumber)) - } if len(x.Accounts) > 0 { for _, e := range x.Accounts { l = options.Size(e) @@ -497,7 +473,7 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], encoded) i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } } if len(x.Accounts) > 0 { @@ -513,14 +489,9 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { copy(dAtA[i:], encoded) i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0xa } } - if x.AccountNumber != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.AccountNumber)) - i-- - dAtA[i] = 0x8 - } if input.Buf != nil { input.Buf = append(input.Buf, dAtA...) } else { @@ -571,25 +542,6 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { } switch fieldNum { case 1: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) - } - x.AccountNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.AccountNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Accounts", wireType) } @@ -623,7 +575,7 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field InitAccountMsgs", wireType) } @@ -1869,12 +1821,10 @@ type GenesisState struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // account_number is the latest account number. - AccountNumber uint64 `protobuf:"varint,1,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` // accounts are the genesis accounts. - Accounts []*GenesisAccount `protobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts,omitempty"` + Accounts []*GenesisAccount `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` // init_accounts_msgs defines the genesis messages that will be executed to init the account. - InitAccountMsgs []*MsgInit `protobuf:"bytes,3,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` + InitAccountMsgs []*MsgInit `protobuf:"bytes,2,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` } func (x *GenesisState) Reset() { @@ -1897,13 +1847,6 @@ func (*GenesisState) Descriptor() ([]byte, []int) { return file_cosmos_accounts_v1_genesis_proto_rawDescGZIP(), []int{0} } -func (x *GenesisState) GetAccountNumber() uint64 { - if x != nil { - return x.AccountNumber - } - return 0 -} - func (x *GenesisState) GetAccounts() []*GenesisAccount { if x != nil { return x.Accounts @@ -2036,45 +1979,43 @@ var file_cosmos_accounts_v1_genesis_proto_rawDesc = []byte{ 0x74, 0x6f, 0x12, 0x12, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x78, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x22, 0xbe, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, - 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x3e, 0x0a, 0x08, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, - 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x12, 0x47, 0x0a, 0x11, 0x69, - 0x6e, 0x69, 0x74, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6d, 0x73, 0x67, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, - 0x6e, 0x69, 0x74, 0x52, 0x0f, 0x69, 0x6e, 0x69, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x4d, 0x73, 0x67, 0x73, 0x22, 0xa6, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, - 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, - 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, - 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x05, 0x73, - 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, - 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x30, 0x0a, - 0x06, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, - 0xc0, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, - 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, - 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, - 0xaa, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, - 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1e, 0x43, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x43, 0x6f, - 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x74, 0x6f, 0x22, 0x97, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x53, + 0x74, 0x61, 0x74, 0x65, 0x12, 0x3e, 0x0a, 0x08, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, + 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x08, 0x61, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x73, 0x12, 0x47, 0x0a, 0x11, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x61, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6d, 0x73, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x1b, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x73, 0x67, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x0f, 0x69, 0x6e, + 0x69, 0x74, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4d, 0x73, 0x67, 0x73, 0x22, 0xa6, 0x01, + 0x0a, 0x0e, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x25, 0x0a, + 0x0e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x75, + 0x6d, 0x62, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x04, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, 0x52, + 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x30, 0x0a, 0x06, 0x4b, 0x56, 0x50, 0x61, 0x69, 0x72, + 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, + 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0xc0, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, + 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, + 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, + 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x58, 0xaa, 0x02, 0x12, 0x43, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, + 0x12, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, + 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1e, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x14, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/x/accounts/genesis.go b/x/accounts/genesis.go index 5311b2dcbcfd..047345789c09 100644 --- a/x/accounts/genesis.go +++ b/x/accounts/genesis.go @@ -11,15 +11,7 @@ import ( func (k Keeper) ExportState(ctx context.Context) (*v1.GenesisState, error) { genState := &v1.GenesisState{} - // get account number - accountNumber, err := k.AccountNumber.Peek(ctx) - if err != nil { - return nil, err - } - - genState.AccountNumber = accountNumber - - err = k.AccountsByType.Walk(ctx, nil, func(accAddr []byte, accType string) (stop bool, err error) { + err := k.AccountsByType.Walk(ctx, nil, func(accAddr []byte, accType string) (stop bool, err error) { accNum, err := k.AccountByNumber.Get(ctx, accAddr) if err != nil { return true, err @@ -64,7 +56,7 @@ func (k Keeper) exportAccount(ctx context.Context, addr []byte, accType string, } func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) error { - var largestNum *uint64 + lastAccountNumber := uint64(0) var err error // import accounts for _, acc := range genState.Accounts { @@ -73,22 +65,23 @@ func (k Keeper) ImportState(ctx context.Context, genState *v1.GenesisState) erro return fmt.Errorf("%w: %s", err, acc.Address) } - accNum := acc.AccountNumber - - if largestNum == nil || *largestNum < accNum { - largestNum = &accNum + // update lastAccountNumber if the current account being processed + // has a bigger account number. + if lastAccountNumber < acc.AccountNumber { + lastAccountNumber = acc.AccountNumber } } - if largestNum != nil { - // set the account number to the highest account number to avoid duplicate account number - err = k.AccountNumber.Set(ctx, *largestNum) + // we set the latest account number only if there were any genesis accounts, otherwise + // we leave it unset. + if genState.Accounts != nil { + // due to sequence semantics, we store the next account number. + err = k.AccountNumber.Set(ctx, lastAccountNumber+1) if err != nil { return err } } - // after this execute account creation msgs. for index, msgInit := range genState.InitAccountMsgs { _, _, err = k.initFromMsg(ctx, msgInit) diff --git a/x/accounts/genesis_test.go b/x/accounts/genesis_test.go index dfde1d0acc40..b9056827eb74 100644 --- a/x/accounts/genesis_test.go +++ b/x/accounts/genesis_test.go @@ -81,8 +81,9 @@ func TestGenesis(t *testing.T) { currentAccNum, err := k.AccountNumber.Peek(ctx) require.NoError(t, err) - // AccountNumber should be set to the highest account number in the genesis state - require.Equal(t, uint64(99), currentAccNum) + // AccountNumber should be set to the highest account number in the genesis state + 2 + // (one is the sequence offset, the other is the genesis account being added through init msg) + require.Equal(t, state.Accounts[0].AccountNumber+2, currentAccNum) } func TestImportAccountError(t *testing.T) { diff --git a/x/accounts/proto/cosmos/accounts/v1/genesis.proto b/x/accounts/proto/cosmos/accounts/v1/genesis.proto index 99ab34b55b2f..dc7d7a52d480 100644 --- a/x/accounts/proto/cosmos/accounts/v1/genesis.proto +++ b/x/accounts/proto/cosmos/accounts/v1/genesis.proto @@ -8,12 +8,10 @@ import "cosmos/accounts/v1/tx.proto"; // GenesisState defines the accounts' module's genesis state. message GenesisState { - // account_number is the latest account number. - uint64 account_number = 1; // accounts are the genesis accounts. - repeated GenesisAccount accounts = 2; + repeated GenesisAccount accounts = 1; // init_accounts_msgs defines the genesis messages that will be executed to init the account. - repeated cosmos.accounts.v1.MsgInit init_account_msgs = 3; + repeated cosmos.accounts.v1.MsgInit init_account_msgs = 2; } // GenesisAccount defines an account to be initialized in the genesis state. diff --git a/x/accounts/v1/genesis.pb.go b/x/accounts/v1/genesis.pb.go index dc061c42e85e..fba3f5832e9f 100644 --- a/x/accounts/v1/genesis.pb.go +++ b/x/accounts/v1/genesis.pb.go @@ -24,12 +24,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the accounts' module's genesis state. type GenesisState struct { - // account_number is the latest account number. - AccountNumber uint64 `protobuf:"varint,1,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"` // accounts are the genesis accounts. - Accounts []*GenesisAccount `protobuf:"bytes,2,rep,name=accounts,proto3" json:"accounts,omitempty"` + Accounts []*GenesisAccount `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"` // init_accounts_msgs defines the genesis messages that will be executed to init the account. - InitAccountMsgs []*MsgInit `protobuf:"bytes,3,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` + InitAccountMsgs []*MsgInit `protobuf:"bytes,2,rep,name=init_account_msgs,json=initAccountMsgs,proto3" json:"init_account_msgs,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -65,13 +63,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetAccountNumber() uint64 { - if m != nil { - return m.AccountNumber - } - return 0 -} - func (m *GenesisState) GetAccounts() []*GenesisAccount { if m != nil { return m.Accounts @@ -223,28 +214,28 @@ func init() { func init() { proto.RegisterFile("cosmos/accounts/v1/genesis.proto", fileDescriptor_409859d32eae9438) } var fileDescriptor_409859d32eae9438 = []byte{ - // 332 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x51, 0xcd, 0x4e, 0xc2, 0x40, - 0x10, 0x66, 0x29, 0xa0, 0x0e, 0x15, 0x75, 0xe3, 0xa1, 0x81, 0xa4, 0xc1, 0x26, 0x26, 0x9c, 0x5a, - 0x50, 0xcf, 0x26, 0x7a, 0x21, 0xc6, 0x60, 0xcc, 0x6a, 0x3c, 0x78, 0x21, 0x05, 0x36, 0xcd, 0x06, - 0xe9, 0x92, 0xce, 0x42, 0xe0, 0x2d, 0x7c, 0x0a, 0x1f, 0xc3, 0xb3, 0x47, 0x8e, 0x1e, 0x0d, 0xbc, - 0x88, 0x61, 0xb7, 0x35, 0x1a, 0x7b, 0xeb, 0x7c, 0xfd, 0xfe, 0x66, 0x07, 0x9a, 0x43, 0x89, 0x13, - 0x89, 0x41, 0x38, 0x1c, 0xca, 0x59, 0xac, 0x30, 0x98, 0x77, 0x82, 0x88, 0xc7, 0x1c, 0x05, 0xfa, - 0xd3, 0x44, 0x2a, 0x49, 0xa9, 0x61, 0xf8, 0x19, 0xc3, 0x9f, 0x77, 0xea, 0x8d, 0x1c, 0x95, 0x5a, - 0x18, 0x81, 0xf7, 0x4e, 0xc0, 0xee, 0x1a, 0x8b, 0x07, 0x15, 0x2a, 0x4e, 0x4f, 0xa1, 0x96, 0x12, - 0xfb, 0xf1, 0x6c, 0x32, 0xe0, 0x89, 0x43, 0x9a, 0xa4, 0x55, 0x62, 0xfb, 0x29, 0x7a, 0xa7, 0x41, - 0x7a, 0x09, 0xbb, 0x99, 0x9f, 0x53, 0x6c, 0x5a, 0xad, 0xea, 0x99, 0xe7, 0xff, 0xcf, 0xf6, 0x53, - 0xeb, 0x2b, 0x03, 0xb1, 0x1f, 0x0d, 0xed, 0xc2, 0x91, 0x88, 0x85, 0xea, 0x67, 0x59, 0x13, 0x8c, - 0xd0, 0xb1, 0xb4, 0x51, 0x23, 0xcf, 0xa8, 0x87, 0xd1, 0x4d, 0x2c, 0x14, 0x3b, 0xd8, 0xaa, 0x52, - 0xbb, 0x1e, 0x46, 0xe8, 0xbd, 0x11, 0xa8, 0xfd, 0x4d, 0xa1, 0x0e, 0xec, 0x84, 0xa3, 0x51, 0xc2, - 0x11, 0x75, 0xf7, 0x3d, 0x96, 0x8d, 0xf4, 0x04, 0xec, 0x2c, 0x50, 0x2d, 0xa7, 0xdc, 0x29, 0xea, - 0xdf, 0xd5, 0x14, 0x7b, 0x5c, 0x4e, 0xf3, 0xf6, 0xb7, 0xf2, 0xf6, 0x6f, 0x43, 0x19, 0xb7, 0xef, - 0xe5, 0x94, 0x74, 0xe7, 0x7a, 0x5e, 0xe7, 0xdb, 0xa7, 0xfb, 0x50, 0x24, 0xcc, 0x10, 0xbd, 0x36, - 0x54, 0x0c, 0x40, 0x0f, 0xc1, 0x1a, 0xf3, 0xa5, 0xee, 0x66, 0xb3, 0xed, 0x27, 0x3d, 0x86, 0xf2, - 0x3c, 0x7c, 0x99, 0x99, 0x42, 0x36, 0x33, 0xc3, 0xf5, 0xc5, 0xc7, 0xda, 0x25, 0xab, 0xb5, 0x4b, - 0xbe, 0xd6, 0x2e, 0x79, 0xdd, 0xb8, 0x85, 0xd5, 0xc6, 0x2d, 0x7c, 0x6e, 0xdc, 0xc2, 0x73, 0xdd, - 0xa4, 0xe1, 0x68, 0xec, 0x0b, 0x19, 0x2c, 0x7e, 0x9f, 0x76, 0x50, 0xd1, 0x87, 0x3d, 0xff, 0x0e, - 0x00, 0x00, 0xff, 0xff, 0xe5, 0x36, 0x4e, 0xfe, 0x2d, 0x02, 0x00, 0x00, + // 331 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xcd, 0x4a, 0xc3, 0x40, + 0x14, 0x85, 0x3b, 0xfd, 0x53, 0x6f, 0x63, 0xd5, 0xc1, 0x45, 0x68, 0x21, 0xd4, 0x80, 0xd0, 0x55, + 0xd2, 0xaa, 0x6b, 0x41, 0x37, 0x45, 0xa4, 0x22, 0xa3, 0xb8, 0x70, 0x53, 0xd2, 0x76, 0x08, 0x43, + 0x6d, 0xa6, 0xe4, 0x4e, 0x4b, 0xfb, 0x16, 0xee, 0x7c, 0x03, 0x9f, 0xc5, 0x65, 0x97, 0x2e, 0xa5, + 0x7d, 0x11, 0xc9, 0x4c, 0x22, 0x8a, 0xd9, 0xe5, 0x7e, 0x39, 0xe7, 0xdc, 0xc3, 0x5c, 0x68, 0x8d, + 0x24, 0x4e, 0x25, 0xfa, 0xc1, 0x68, 0x24, 0xe7, 0x91, 0x42, 0x7f, 0xd1, 0xf5, 0x43, 0x1e, 0x71, + 0x14, 0xe8, 0xcd, 0x62, 0xa9, 0x24, 0xa5, 0x46, 0xe1, 0x65, 0x0a, 0x6f, 0xd1, 0x6d, 0x34, 0x73, + 0x5c, 0x6a, 0x69, 0x0c, 0xee, 0x1b, 0x01, 0xab, 0x67, 0x22, 0x1e, 0x54, 0xa0, 0x38, 0xbd, 0x84, + 0xdd, 0x4c, 0x68, 0x93, 0x56, 0xa9, 0x5d, 0x3b, 0x73, 0xbd, 0xff, 0xa1, 0x5e, 0xea, 0xb9, 0x32, + 0x88, 0xfd, 0x78, 0x68, 0x0f, 0x8e, 0x44, 0x24, 0xd4, 0x20, 0x05, 0x83, 0x29, 0x86, 0x68, 0x17, + 0x75, 0x50, 0x33, 0x2f, 0xa8, 0x8f, 0xe1, 0x4d, 0x24, 0x14, 0x3b, 0x48, 0x5c, 0x69, 0x5c, 0x1f, + 0x43, 0x74, 0xdf, 0x09, 0xd4, 0xff, 0x6e, 0xa1, 0x36, 0xec, 0x04, 0xe3, 0x71, 0xcc, 0x31, 0xa9, + 0x46, 0xda, 0x7b, 0x2c, 0x1b, 0xe9, 0x09, 0x58, 0xd9, 0x42, 0xb5, 0x9a, 0x71, 0xbb, 0xa8, 0x7f, + 0xd7, 0x52, 0xf6, 0xb8, 0x9a, 0x71, 0x7a, 0x0a, 0xf5, 0x4c, 0x12, 0xcd, 0xa7, 0x43, 0x1e, 0xdb, + 0xa5, 0x16, 0x69, 0x97, 0xd9, 0x7e, 0x4a, 0xef, 0x34, 0xa4, 0x1d, 0xa8, 0x60, 0xf2, 0x10, 0x76, + 0x59, 0x77, 0x6e, 0xe4, 0x75, 0xbe, 0x7d, 0xba, 0x0f, 0x44, 0xcc, 0x8c, 0xd0, 0xed, 0x40, 0xd5, + 0x00, 0x7a, 0x08, 0xa5, 0x09, 0x5f, 0xe9, 0x6e, 0x16, 0x4b, 0x3e, 0xe9, 0x31, 0x54, 0x16, 0xc1, + 0xcb, 0xdc, 0x14, 0xb2, 0x98, 0x19, 0xae, 0x2f, 0x3e, 0x36, 0x0e, 0x59, 0x6f, 0x1c, 0xf2, 0xb5, + 0x71, 0xc8, 0xeb, 0xd6, 0x29, 0xac, 0xb7, 0x4e, 0xe1, 0x73, 0xeb, 0x14, 0x9e, 0x1b, 0x66, 0x1b, + 0x8e, 0x27, 0x9e, 0x90, 0xfe, 0xf2, 0xf7, 0xcd, 0x86, 0x55, 0x7d, 0xb1, 0xf3, 0xef, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x06, 0xd4, 0x9c, 0x6a, 0x06, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -278,7 +269,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } } if len(m.Accounts) > 0 { @@ -292,14 +283,9 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x12 + dAtA[i] = 0xa } } - if m.AccountNumber != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.AccountNumber)) - i-- - dAtA[i] = 0x8 - } return len(dAtA) - i, nil } @@ -413,9 +399,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - if m.AccountNumber != 0 { - n += 1 + sovGenesis(uint64(m.AccountNumber)) - } if len(m.Accounts) > 0 { for _, e := range m.Accounts { l = e.Size() @@ -510,25 +493,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field AccountNumber", wireType) - } - m.AccountNumber = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.AccountNumber |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Accounts", wireType) } @@ -562,7 +526,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InitAccountMsgs", wireType) } From 587d3d6708ece378da10bb5bad9ff58d32476700 Mon Sep 17 00:00:00 2001 From: unknown unknown Date: Wed, 12 Jun 2024 16:00:01 +0200 Subject: [PATCH 5/5] add cli cmd and enhance docs --- x/accounts/README.md | 4 ++++ x/accounts/cli/cli.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/x/accounts/README.md b/x/accounts/README.md index f71284262d0a..3bc9e1d48635 100644 --- a/x/accounts/README.md +++ b/x/accounts/README.md @@ -9,6 +9,10 @@ The x/accounts module provides module and facilities for writing smart cosmos-sd In order to create accounts at genesis, the `x/accounts` module allows developers to provide a list of genesis `MsgInit` messages that will be executed in the `x/accounts` genesis flow. +The init messages are generated offline. You can also use the following CLI command to generate the +json messages: `simd accounts tx init [account type] [msg] --from me --genesis`. This will generate +a jsonified init message wrapped in an x/accounts `MsgInit`. + This follows the same initialization flow and rules that would happen if the chain is running. The only concrete difference is that this is happening at the genesis block. diff --git a/x/accounts/cli/cli.go b/x/accounts/cli/cli.go index a8ebbd914d21..12d7170ae821 100644 --- a/x/accounts/cli/cli.go +++ b/x/accounts/cli/cli.go @@ -75,9 +75,20 @@ func GetTxInitCmd() *cobra.Command { Message: msgBytes, } + isGenesis, err := cmd.Flags().GetBool("genesis") + if err != nil { + return err + } + + // in case the genesis flag is provided then the init message is printed. + if isGenesis { + return clientCtx.WithOutputFormat(flags.OutputFormatJSON).PrintProto(&msg) + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg) }, } + cmd.Flags().Bool("genesis", false, "if true will print the json init message for genesis") flags.AddTxFlagsToCmd(cmd) return cmd }