Add a command to create a lockup module account

This commit is contained in:
Prathamesh Musale 2025-05-15 19:09:14 +05:30
parent 01147b34eb
commit ae68e301ba
7 changed files with 245 additions and 86 deletions

View File

@ -17,15 +17,15 @@ import (
)
var (
md_LockupAccount protoreflect.MessageDescriptor
fd_LockupAccount_base_account protoreflect.FieldDescriptor
fd_LockupAccount_distribution protoreflect.FieldDescriptor
md_LockupAccount protoreflect.MessageDescriptor
fd_LockupAccount_module_account protoreflect.FieldDescriptor
fd_LockupAccount_distribution protoreflect.FieldDescriptor
)
func init() {
file_cerc_types_v1_lockup_proto_init()
md_LockupAccount = File_cerc_types_v1_lockup_proto.Messages().ByName("LockupAccount")
fd_LockupAccount_base_account = md_LockupAccount.Fields().ByName("base_account")
fd_LockupAccount_module_account = md_LockupAccount.Fields().ByName("module_account")
fd_LockupAccount_distribution = md_LockupAccount.Fields().ByName("distribution")
}
@ -94,9 +94,9 @@ func (x *fastReflection_LockupAccount) Interface() protoreflect.ProtoMessage {
// While iterating, mutating operations may only be performed
// on the current field descriptor.
func (x *fastReflection_LockupAccount) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
if x.BaseAccount != nil {
value := protoreflect.ValueOfMessage(x.BaseAccount.ProtoReflect())
if !f(fd_LockupAccount_base_account, value) {
if x.ModuleAccount != nil {
value := protoreflect.ValueOfMessage(x.ModuleAccount.ProtoReflect())
if !f(fd_LockupAccount_module_account, value) {
return
}
}
@ -121,8 +121,8 @@ func (x *fastReflection_LockupAccount) Range(f func(protoreflect.FieldDescriptor
// a repeated field is populated if it is non-empty.
func (x *fastReflection_LockupAccount) Has(fd protoreflect.FieldDescriptor) bool {
switch fd.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
return x.BaseAccount != nil
case "cerc.types.v1.LockupAccount.module_account":
return x.ModuleAccount != nil
case "cerc.types.v1.LockupAccount.distribution":
return x.Distribution != ""
default:
@ -141,8 +141,8 @@ func (x *fastReflection_LockupAccount) Has(fd protoreflect.FieldDescriptor) bool
// Clear is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_LockupAccount) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
x.BaseAccount = nil
case "cerc.types.v1.LockupAccount.module_account":
x.ModuleAccount = nil
case "cerc.types.v1.LockupAccount.distribution":
x.Distribution = ""
default:
@ -161,8 +161,8 @@ func (x *fastReflection_LockupAccount) Clear(fd protoreflect.FieldDescriptor) {
// of the value; to obtain a mutable reference, use Mutable.
func (x *fastReflection_LockupAccount) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
switch descriptor.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
value := x.BaseAccount
case "cerc.types.v1.LockupAccount.module_account":
value := x.ModuleAccount
return protoreflect.ValueOfMessage(value.ProtoReflect())
case "cerc.types.v1.LockupAccount.distribution":
value := x.Distribution
@ -187,8 +187,8 @@ func (x *fastReflection_LockupAccount) Get(descriptor protoreflect.FieldDescript
// Set is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_LockupAccount) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
switch fd.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
x.BaseAccount = value.Message().Interface().(*types.ModuleAccount)
case "cerc.types.v1.LockupAccount.module_account":
x.ModuleAccount = value.Message().Interface().(*types.ModuleAccount)
case "cerc.types.v1.LockupAccount.distribution":
x.Distribution = value.Interface().(string)
default:
@ -211,11 +211,11 @@ func (x *fastReflection_LockupAccount) Set(fd protoreflect.FieldDescriptor, valu
// Mutable is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_LockupAccount) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
if x.BaseAccount == nil {
x.BaseAccount = new(types.ModuleAccount)
case "cerc.types.v1.LockupAccount.module_account":
if x.ModuleAccount == nil {
x.ModuleAccount = new(types.ModuleAccount)
}
return protoreflect.ValueOfMessage(x.BaseAccount.ProtoReflect())
return protoreflect.ValueOfMessage(x.ModuleAccount.ProtoReflect())
case "cerc.types.v1.LockupAccount.distribution":
panic(fmt.Errorf("field distribution of message cerc.types.v1.LockupAccount is not mutable"))
default:
@ -231,7 +231,7 @@ func (x *fastReflection_LockupAccount) Mutable(fd protoreflect.FieldDescriptor)
// For lists, maps, and messages, this returns a new, empty, mutable value.
func (x *fastReflection_LockupAccount) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cerc.types.v1.LockupAccount.base_account":
case "cerc.types.v1.LockupAccount.module_account":
m := new(types.ModuleAccount)
return protoreflect.ValueOfMessage(m.ProtoReflect())
case "cerc.types.v1.LockupAccount.distribution":
@ -305,8 +305,8 @@ func (x *fastReflection_LockupAccount) ProtoMethods() *protoiface.Methods {
var n int
var l int
_ = l
if x.BaseAccount != nil {
l = options.Size(x.BaseAccount)
if x.ModuleAccount != nil {
l = options.Size(x.ModuleAccount)
n += 1 + l + runtime.Sov(uint64(l))
}
l = len(x.Distribution)
@ -349,8 +349,8 @@ func (x *fastReflection_LockupAccount) ProtoMethods() *protoiface.Methods {
i--
dAtA[i] = 0x12
}
if x.BaseAccount != nil {
encoded, err := options.Marshal(x.BaseAccount)
if x.ModuleAccount != nil {
encoded, err := options.Marshal(x.ModuleAccount)
if err != nil {
return protoiface.MarshalOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
@ -414,7 +414,7 @@ func (x *fastReflection_LockupAccount) ProtoMethods() *protoiface.Methods {
switch fieldNum {
case 1:
if wireType != 2 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field BaseAccount", wireType)
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ModuleAccount", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@ -441,10 +441,10 @@ func (x *fastReflection_LockupAccount) ProtoMethods() *protoiface.Methods {
if postIndex > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
if x.BaseAccount == nil {
x.BaseAccount = &types.ModuleAccount{}
if x.ModuleAccount == nil {
x.ModuleAccount = &types.ModuleAccount{}
}
if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.BaseAccount); err != nil {
if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ModuleAccount); err != nil {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
}
iNdEx = postIndex
@ -534,8 +534,8 @@ type LockupAccount struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
BaseAccount *types.ModuleAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3" json:"base_account,omitempty"`
Distribution string `protobuf:"bytes,2,opt,name=distribution,proto3" json:"distribution,omitempty"`
ModuleAccount *types.ModuleAccount `protobuf:"bytes,1,opt,name=module_account,json=moduleAccount,proto3" json:"module_account,omitempty"`
Distribution string `protobuf:"bytes,2,opt,name=distribution,proto3" json:"distribution,omitempty"`
}
func (x *LockupAccount) Reset() {
@ -558,9 +558,9 @@ func (*LockupAccount) Descriptor() ([]byte, []int) {
return file_cerc_types_v1_lockup_proto_rawDescGZIP(), []int{0}
}
func (x *LockupAccount) GetBaseAccount() *types.ModuleAccount {
func (x *LockupAccount) GetModuleAccount() *types.ModuleAccount {
if x != nil {
return x.BaseAccount
return x.ModuleAccount
}
return nil
}
@ -584,31 +584,32 @@ var file_cerc_types_v1_lockup_proto_rawDesc = []byte{
0x73, 0x2f, 0x61, 0x75, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x61,
0x75, 0x74, 0x68, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0xd4, 0x01, 0x0a, 0x0d, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e,
0x74, 0x12, 0x4b, 0x0a, 0x0c, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e,
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73,
0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x4d, 0x6f,
0x64, 0x75, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x04, 0xd0, 0xde, 0x1f,
0x01, 0x52, 0x0b, 0x62, 0x61, 0x73, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x22,
0x0a, 0x0c, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69,
0x6f, 0x6e, 0x3a, 0x52, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0, 0x1f, 0x00, 0xca, 0xb4, 0x2d, 0x19,
0x63, 0x65, 0x72, 0x63, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x4c, 0x6f, 0x63, 0x6b, 0x75,
0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x8a, 0xe7, 0xb0, 0x2a, 0x15, 0x6c, 0x61,
0x63, 0x6f, 0x6e, 0x69, 0x63, 0x2f, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f,
0x75, 0x6e, 0x74, 0x92, 0xe7, 0xb0, 0x2a, 0x0e, 0x6c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x5f, 0x61,
0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0xad, 0x01, 0x0a, 0x11, 0x63, 0x6f, 0x6d, 0x2e, 0x63,
0x65, 0x72, 0x63, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4c, 0x6f,
0x63, 0x6b, 0x75, 0x70, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x35, 0x67, 0x69, 0x74,
0x2e, 0x76, 0x64, 0x62, 0x2e, 0x74, 0x6f, 0x2f, 0x63, 0x65, 0x72, 0x63, 0x2d, 0x69, 0x6f, 0x2f,
0x6c, 0x61, 0x63, 0x6f, 0x6e, 0x69, 0x63, 0x64, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x65, 0x72,
0x63, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x74, 0x79, 0x70, 0x65, 0x73,
0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x58, 0xaa, 0x02, 0x0d, 0x43, 0x65, 0x72, 0x63, 0x2e,
0x54, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0d, 0x43, 0x65, 0x72, 0x63, 0x5c,
0x54, 0x79, 0x70, 0x65, 0x73, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x19, 0x43, 0x65, 0x72, 0x63, 0x5c,
0x54, 0x79, 0x70, 0x65, 0x73, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0f, 0x43, 0x65, 0x72, 0x63, 0x3a, 0x3a, 0x54, 0x79, 0x70,
0x65, 0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0xdb, 0x01, 0x0a, 0x0d, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e,
0x74, 0x12, 0x4f, 0x0a, 0x0e, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f,
0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x73, 0x6d,
0x6f, 0x73, 0x2e, 0x61, 0x75, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e,
0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x04, 0xd0,
0xde, 0x1f, 0x01, 0x52, 0x0d, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x41, 0x63, 0x63, 0x6f, 0x75,
0x6e, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69,
0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69,
0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x55, 0x88, 0xa0, 0x1f, 0x00, 0xe8, 0xa0, 0x1f, 0x00,
0xca, 0xb4, 0x2d, 0x1c, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x76,
0x31, 0x2e, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49,
0x8a, 0xe7, 0xb0, 0x2a, 0x15, 0x6c, 0x61, 0x63, 0x6f, 0x6e, 0x69, 0x63, 0x2f, 0x4c, 0x6f, 0x63,
0x6b, 0x75, 0x70, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x92, 0xe7, 0xb0, 0x2a, 0x0e, 0x6c,
0x6f, 0x63, 0x6b, 0x75, 0x70, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0xad, 0x01,
0x0a, 0x11, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73,
0x2e, 0x76, 0x31, 0x42, 0x0b, 0x4c, 0x6f, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x72, 0x6f, 0x74, 0x6f,
0x50, 0x01, 0x5a, 0x35, 0x67, 0x69, 0x74, 0x2e, 0x76, 0x64, 0x62, 0x2e, 0x74, 0x6f, 0x2f, 0x63,
0x65, 0x72, 0x63, 0x2d, 0x69, 0x6f, 0x2f, 0x6c, 0x61, 0x63, 0x6f, 0x6e, 0x69, 0x63, 0x64, 0x2f,
0x61, 0x70, 0x69, 0x2f, 0x63, 0x65, 0x72, 0x63, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x76,
0x31, 0x3b, 0x74, 0x79, 0x70, 0x65, 0x73, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x54, 0x58, 0xaa,
0x02, 0x0d, 0x43, 0x65, 0x72, 0x63, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x56, 0x31, 0xca,
0x02, 0x0d, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x5c, 0x56, 0x31, 0xe2,
0x02, 0x19, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x54, 0x79, 0x70, 0x65, 0x73, 0x5c, 0x56, 0x31, 0x5c,
0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0f, 0x43, 0x65,
0x72, 0x63, 0x3a, 0x3a, 0x54, 0x79, 0x70, 0x65, 0x73, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -629,7 +630,7 @@ var file_cerc_types_v1_lockup_proto_goTypes = []interface{}{
(*types.ModuleAccount)(nil), // 1: cosmos.auth.v1beta1.ModuleAccount
}
var file_cerc_types_v1_lockup_proto_depIdxs = []int32{
1, // 0: cerc.types.v1.LockupAccount.base_account:type_name -> cosmos.auth.v1beta1.ModuleAccount
1, // 0: cerc.types.v1.LockupAccount.module_account:type_name -> cosmos.auth.v1beta1.ModuleAccount
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name

View File

@ -18,7 +18,7 @@ import (
bondkeeper "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
onboardingkeeper "git.vdb.to/cerc-io/laconicd/x/onboarding/keeper"
registrykeeper "git.vdb.to/cerc-io/laconicd/x/registry/keeper"
types "git.vdb.to/cerc-io/laconicd/x/types"
types "git.vdb.to/cerc-io/laconicd/x/types/v1"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
@ -249,16 +249,29 @@ func (app *LaconicApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.AP
}
func RegisterCustomInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
// Custom ZenithAccount type needs to be registered to be able to use it as a genesis account
// Custom LockupAccount type needs to be registered to be able to use it as a genesis account
interfaceRegistry.RegisterImplementations((*authtypes.GenesisAccount)(nil), &types.LockupAccount{})
// ZenithAccount extends auth Account
// LockupAccount extends auth Account
interfaceRegistry.RegisterInterface(
"cosmos.auth.v1beta1.AccountI",
(*sdk.AccountI)(nil),
&types.LockupAccount{},
)
// LockupAccount extends auth ModuleAccount
interfaceRegistry.RegisterInterface(
"cosmos.auth.v1beta1.ModuleAccountI",
(*sdk.ModuleAccountI)(nil),
&types.LockupAccount{},
)
interfaceRegistry.RegisterInterface(
"cosmos.auth.v1beta1.GenesisAccount",
(*authtypes.GenesisAccount)(nil),
&types.LockupAccount{},
)
interfaceRegistry.RegisterInterface(
"cerc.types.v1.LockupAccountI",
(*types.LockupAccountI)(nil),

View File

@ -0,0 +1,141 @@
package cmd
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/cobra"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
types "git.vdb.to/cerc-io/laconicd/x/types/v1"
)
const (
flagAppendMode = "append"
)
// AddGenesisLockupAccountCmd returns add-genesis-module-account cobra Command.
func AddGenesisLockupAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "add-genesis-lockup-account <module_name> <coin>[,<coin>...]",
Short: "Add genesis accounts for given participants to genesis.json",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
config.SetRoot(clientCtx.HomeDir)
moduleName := args[0]
appendflag, _ := cmd.Flags().GetBool(flagAppendMode)
return AddGenesisAccount(clientCtx.Codec, moduleName, appendflag, config.GenesisFile(), args[1])
},
}
cmd.Flags().Bool(flagAppendMode, false, "append the coins to an account already in the genesis.json file")
return cmd
}
func AddGenesisAccount(
cdc codec.Codec,
moduleName string,
appendAcct bool,
genesisFileURL, amountStr string,
) error {
coins, err := sdk.ParseCoinsNormalized(amountStr)
if err != nil {
return fmt.Errorf("failed to parse coins: %w", err)
}
// create concrete account type based on input parameters
moduleAccount := authtypes.NewEmptyModuleAccount(moduleName)
accAddr := moduleAccount.GetAddress()
balances := banktypes.Balance{Address: accAddr.String(), Coins: coins.Sort()}
var genAccount authtypes.GenesisAccount
genAccount = &types.LockupAccount{
ModuleAccount: moduleAccount,
Distribution: "",
}
if err := genAccount.Validate(); err != nil {
return fmt.Errorf("failed to validate new genesis account: %w", err)
}
appState, appGenesis, err := genutiltypes.GenesisStateFromGenFile(genesisFileURL)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}
authGenState := authtypes.GetGenesisStateFromAppState(cdc, appState)
accs, err := authtypes.UnpackAccounts(authGenState.Accounts)
if err != nil {
return fmt.Errorf("failed to get accounts from any: %w", err)
}
bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState)
if accs.Contains(accAddr) {
if !appendAcct {
return fmt.Errorf(" Account %s already exists\nUse `append` flag to append account at existing address", accAddr)
}
genesisB := banktypes.GetGenesisStateFromAppState(cdc, appState)
for idx, acc := range genesisB.Balances {
if acc.Address != accAddr.String() {
continue
}
updatedCoins := acc.Coins.Add(coins...)
bankGenState.Balances[idx] = banktypes.Balance{Address: accAddr.String(), Coins: updatedCoins.Sort()}
break
}
} else {
// Add the new account to the set of genesis accounts and sanitize the accounts afterwards.
accs = append(accs, genAccount)
accs = authtypes.SanitizeGenesisAccounts(accs)
genAccs, err := authtypes.PackAccounts(accs)
if err != nil {
return fmt.Errorf("failed to convert accounts into any's: %w", err)
}
authGenState.Accounts = genAccs
authGenStateBz, err := cdc.MarshalJSON(&authGenState)
if err != nil {
return fmt.Errorf("failed to marshal auth genesis state: %w", err)
}
appState[authtypes.ModuleName] = authGenStateBz
bankGenState.Balances = append(bankGenState.Balances, balances)
}
bankGenState.Balances = banktypes.SanitizeGenesisBalances(bankGenState.Balances)
bankGenState.Supply = bankGenState.Supply.Add(balances.Coins...)
bankGenStateBz, err := cdc.MarshalJSON(bankGenState)
if err != nil {
return fmt.Errorf("failed to marshal bank genesis state: %w", err)
}
appState[banktypes.ModuleName] = bankGenStateBz
appStateJSON, err := json.Marshal(appState)
if err != nil {
return fmt.Errorf("failed to marshal application genesis state: %w", err)
}
appGenesis.AppState = appStateJSON
return genutil.ExportGenesisFile(appGenesis, genesisFileURL)
}

View File

@ -58,10 +58,14 @@ func initRootCmd(rootCmd *cobra.Command, txConfig client.TxConfig, basicManager
startCmd.RunE = newStartCmd.RunE
})
// Capture the genesis command from genutilcli and add new commands
genesisCmd := genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome)
genesisCmd.AddCommand(AddGenesisLockupAccountCmd())
// add keybase, auxiliary RPC, query, genesis, and tx child commands
rootCmd.AddCommand(
server.StatusCommand(),
genutilcli.Commands(txConfig, basicManager, app.DefaultNodeHome),
genesisCmd,
queryCommand(),
txCommand(),
keys.Commands(),

View File

@ -6,7 +6,7 @@ import "cosmos_proto/cosmos.proto";
import "cosmos/auth/v1beta1/auth.proto";
import "gogoproto/gogo.proto";
option go_package = "git.vdb.to/cerc-io/laconicd/x/types";
option go_package = "git.vdb.to/cerc-io/laconicd/x/types/v1";
// LockupAccount extends the Cosmos SDK ModuleAccount with a distribution field.
message LockupAccount {
@ -15,9 +15,9 @@ message LockupAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = false;
option (cosmos_proto.implements_interface) = "cerc.types.LockupAccountI";
option (cosmos_proto.implements_interface) = "cerc.types.v1.LockupAccountI";
cosmos.auth.v1beta1.ModuleAccount base_account = 1
cosmos.auth.v1beta1.ModuleAccount module_account = 1
[ (gogoproto.embed) = true ];
string distribution = 2;
}

View File

@ -1,4 +1,4 @@
package types
package v1
import (
"errors"
@ -14,18 +14,18 @@ var (
// LockupAccountI defines an account interface for accounts with lockup distribution
type LockupAccountI interface {
sdk.AccountI
sdk.ModuleAccountI
GetDistribution() string
}
// Validate checks for errors on the account fields
func (la LockupAccount) Validate() error {
if la.BaseAccount == nil {
return errors.New("uninitialized LockupAccount: BaseAccount is nil")
if la.ModuleAccount == nil {
return errors.New("uninitialized LockupAccount: ModuleAccount is nil")
}
return la.BaseAccount.Validate()
return la.ModuleAccount.Validate()
}
// GetAzimuthId returns the Azimuth Id associated with the account

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cerc/types/v1/lockup.proto
package types
package v1
import (
fmt "fmt"
@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// LockupAccount extends the Cosmos SDK ModuleAccount with a distribution field.
type LockupAccount struct {
*types.ModuleAccount `protobuf:"bytes,1,opt,name=base_account,json=baseAccount,proto3,embedded=base_account" json:"base_account,omitempty"`
*types.ModuleAccount `protobuf:"bytes,1,opt,name=module_account,json=moduleAccount,proto3,embedded=module_account" json:"module_account,omitempty"`
Distribution string `protobuf:"bytes,2,opt,name=distribution,proto3" json:"distribution,omitempty"`
}
@ -79,20 +79,20 @@ var fileDescriptor_8fa58dc19f6348bf = []byte{
0xa5, 0x04, 0x13, 0x73, 0x33, 0xf3, 0xf2, 0xf5, 0xc1, 0x24, 0x44, 0x85, 0x94, 0x64, 0x72, 0x7e,
0x71, 0x6e, 0x7e, 0x71, 0x3c, 0x98, 0xa7, 0x0f, 0xe1, 0x40, 0xa5, 0xe4, 0x20, 0x3c, 0xfd, 0xc4,
0xd2, 0x92, 0x0c, 0xfd, 0x32, 0xc3, 0xa4, 0xd4, 0x92, 0x44, 0x43, 0x30, 0x07, 0x2a, 0x2f, 0x92,
0x9e, 0x9f, 0x9e, 0x0f, 0xd1, 0x07, 0x62, 0x41, 0x44, 0x95, 0xae, 0x30, 0x72, 0xf1, 0xfa, 0x80,
0xdd, 0xe0, 0x98, 0x9c, 0x9c, 0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xa5, 0x24, 0xe9, 0x81, 0x82, 0x31, 0xb5, 0x28, 0x59, 0x37, 0x33, 0x5f, 0x1f, 0x6a, 0x6c,
0x8a, 0x7e, 0x05, 0x3c, 0x7e, 0x92, 0xd8, 0xc0, 0xc1, 0x64, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff,
0x1f, 0x66, 0x3d, 0xd4, 0xb7, 0x01, 0x00, 0x00,
}
func (m *LockupAccount) Marshal() (dAtA []byte, err error) {