From b3287a64a8617042fd254b57614080f10a4a575a Mon Sep 17 00:00:00 2001 From: Matthew Witkowski Date: Fri, 3 May 2024 14:18:51 -0400 Subject: [PATCH] Add proposal type back. --- proto/provenance/name/v1/name.proto | 20 ++ x/name/types/name.pb.go | 405 +++++++++++++++++++++++++--- x/name/types/proposal.go | 79 ++++++ x/name/types/proposal_test.go | 37 +++ 4 files changed, 509 insertions(+), 32 deletions(-) create mode 100644 x/name/types/proposal.go create mode 100644 x/name/types/proposal_test.go diff --git a/proto/provenance/name/v1/name.proto b/proto/provenance/name/v1/name.proto index 6fadde21c4..523cb4f618 100644 --- a/proto/provenance/name/v1/name.proto +++ b/proto/provenance/name/v1/name.proto @@ -36,6 +36,26 @@ message NameRecord { bool restricted = 3; } +// CreateRootNameProposal details a proposal to create a new root name +// that is controlled by a given owner and optionally restricted to the owner +// for the sole creation of sub names. +message CreateRootNameProposal { + option (gogoproto.equal) = false; + option (gogoproto.goproto_getters) = false; + option (gogoproto.goproto_stringer) = false; + + // proposal title + string title = 1; + // proposal description + string description = 2; + // the bound name + string name = 3; + // the address the name will resolve to + string owner = 4; + // a flag that indicates if an owner signature is required to add sub-names + bool restricted = 5; +} + // Event emitted when name is bound. message EventNameBound { string address = 1; diff --git a/x/name/types/name.pb.go b/x/name/types/name.pb.go index 8aae36bd1e..9aac9e5670 100644 --- a/x/name/types/name.pb.go +++ b/x/name/types/name.pb.go @@ -161,6 +161,54 @@ func (m *NameRecord) GetRestricted() bool { return false } +// CreateRootNameProposal details a proposal to create a new root name +// that is controlled by a given owner and optionally restricted to the owner +// for the sole creation of sub names. +type CreateRootNameProposal struct { + // proposal title + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // proposal description + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // the bound name + Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` + // the address the name will resolve to + Owner string `protobuf:"bytes,4,opt,name=owner,proto3" json:"owner,omitempty"` + // a flag that indicates if an owner signature is required to add sub-names + Restricted bool `protobuf:"varint,5,opt,name=restricted,proto3" json:"restricted,omitempty"` +} + +func (m *CreateRootNameProposal) Reset() { *m = CreateRootNameProposal{} } +func (*CreateRootNameProposal) ProtoMessage() {} +func (*CreateRootNameProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_a314256905bb00ec, []int{2} +} +func (m *CreateRootNameProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreateRootNameProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreateRootNameProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CreateRootNameProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateRootNameProposal.Merge(m, src) +} +func (m *CreateRootNameProposal) XXX_Size() int { + return m.Size() +} +func (m *CreateRootNameProposal) XXX_DiscardUnknown() { + xxx_messageInfo_CreateRootNameProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateRootNameProposal proto.InternalMessageInfo + // Event emitted when name is bound. type EventNameBound struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` @@ -172,7 +220,7 @@ func (m *EventNameBound) Reset() { *m = EventNameBound{} } func (m *EventNameBound) String() string { return proto.CompactTextString(m) } func (*EventNameBound) ProtoMessage() {} func (*EventNameBound) Descriptor() ([]byte, []int) { - return fileDescriptor_a314256905bb00ec, []int{2} + return fileDescriptor_a314256905bb00ec, []int{3} } func (m *EventNameBound) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -233,7 +281,7 @@ func (m *EventNameUnbound) Reset() { *m = EventNameUnbound{} } func (m *EventNameUnbound) String() string { return proto.CompactTextString(m) } func (*EventNameUnbound) ProtoMessage() {} func (*EventNameUnbound) Descriptor() ([]byte, []int) { - return fileDescriptor_a314256905bb00ec, []int{3} + return fileDescriptor_a314256905bb00ec, []int{4} } func (m *EventNameUnbound) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -294,7 +342,7 @@ func (m *EventNameUpdate) Reset() { *m = EventNameUpdate{} } func (m *EventNameUpdate) String() string { return proto.CompactTextString(m) } func (*EventNameUpdate) ProtoMessage() {} func (*EventNameUpdate) Descriptor() ([]byte, []int) { - return fileDescriptor_a314256905bb00ec, []int{4} + return fileDescriptor_a314256905bb00ec, []int{5} } func (m *EventNameUpdate) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -347,6 +395,7 @@ func (m *EventNameUpdate) GetRestricted() bool { func init() { proto.RegisterType((*Params)(nil), "provenance.name.v1.Params") proto.RegisterType((*NameRecord)(nil), "provenance.name.v1.NameRecord") + proto.RegisterType((*CreateRootNameProposal)(nil), "provenance.name.v1.CreateRootNameProposal") proto.RegisterType((*EventNameBound)(nil), "provenance.name.v1.EventNameBound") proto.RegisterType((*EventNameUnbound)(nil), "provenance.name.v1.EventNameUnbound") proto.RegisterType((*EventNameUpdate)(nil), "provenance.name.v1.EventNameUpdate") @@ -355,35 +404,40 @@ func init() { func init() { proto.RegisterFile("provenance/name/v1/name.proto", fileDescriptor_a314256905bb00ec) } var fileDescriptor_a314256905bb00ec = []byte{ - // 438 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0x31, 0x6f, 0xd4, 0x30, - 0x14, 0x8e, 0x4b, 0x55, 0x5a, 0x4b, 0xa5, 0x27, 0xab, 0x40, 0xa8, 0x44, 0xa8, 0x32, 0xa0, 0x0a, - 0xd1, 0x0b, 0x85, 0x05, 0xb1, 0x71, 0x12, 0x5b, 0x85, 0xaa, 0x54, 0x5d, 0x18, 0x08, 0xbe, 0xe4, - 0xc9, 0x8d, 0x14, 0xdb, 0x91, 0xed, 0x0b, 0x61, 0x65, 0x60, 0x66, 0x64, 0xe4, 0x27, 0x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01, 0x00, 0x00, 0xff, 0xff, 0x36, 0xa4, - 0x9e, 0xee, 0x5f, 0x03, 0x00, 0x00, + // 518 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0xbf, 0x6f, 0x13, 0x3f, + 0x18, 0xc6, 0xcf, 0x6d, 0xd3, 0x6f, 0xe3, 0x2f, 0xa5, 0x91, 0x15, 0xca, 0x51, 0x89, 0x4b, 0x94, + 0x01, 0x55, 0x88, 0xe6, 0x28, 0x2c, 0x88, 0x8d, 0x20, 0xb6, 0x0a, 0x45, 0x57, 0x75, 0x61, 0xe0, + 0x70, 0xee, 0x5e, 0x5d, 0x2d, 0x9d, 0xed, 0x93, 0xed, 0xa4, 0x61, 0x65, 0x40, 0x8c, 0x8c, 0x8c, + 0x19, 0x19, 0x19, 0xf8, 0x1b, 0x10, 0x63, 0xc5, 0xc4, 0x88, 0x92, 0x01, 0xfe, 0x0c, 0x74, 0x76, + 0x7e, 0x1c, 0x61, 0x60, 0x81, 0xe9, 0xfc, 0x3e, 0xcf, 0xe3, 0x7b, 0x3f, 0x7e, 0xa5, 0x17, 0xdf, + 0x2c, 0x94, 0x1c, 0x81, 0xa0, 0x22, 0x81, 0x50, 0x50, 0x0e, 0xe1, 0xe8, 0xd8, 0x7e, 0xbb, 0x85, + 0x92, 0x46, 0x12, 0xb2, 0xb2, 0xbb, 0x56, 0x1e, 0x1d, 0x1f, 0x5c, 0x4f, 0xa4, 0xe6, 0x52, 0x87, + 0x5c, 0x67, 0x65, 0x9a, 0xeb, 0xcc, 0x85, 0x0f, 0x6e, 0x38, 0x23, 0xb6, 0x55, 0xe8, 0x8a, 0xb9, + 0xd5, 0xcc, 0x64, 0x26, 0x9d, 0x5e, 0x9e, 0x9c, 0xda, 0xf9, 0x84, 0xf0, 0x76, 0x9f, 0x2a, 0xca, + 0x35, 0xb9, 0x83, 0x09, 0xa7, 0xe3, 0x58,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0a, 0xd2, 0xc6, + 0xff, 0xa7, 0xa0, 0x13, 0xc5, 0x0a, 0xc3, 0xa4, 0x70, 0x68, 0x51, 0x55, 0x5a, 0x3e, 0x66, 0xb3, + 0xf2, 0x98, 0x26, 0xae, 0xc9, 0x0b, 0x01, 0xca, 0x8e, 0xa5, 0x1e, 0xb9, 0x62, 0x0d, 0xb7, 0xf6, + 0x1b, 0xee, 0x95, 0x37, 0x93, 0x96, 0x57, 0x22, 0xff, 0x98, 0xb4, 0xbc, 0xce, 0x73, 0x7c, 0xf5, + 0xc9, 0x08, 0x84, 0x85, 0xec, 0xc9, 0xa1, 0x48, 0x89, 0xbf, 0x1a, 0x91, 0x63, 0x5c, 0x0e, 0x62, + 0xc1, 0xb0, 0x51, 0x61, 0xf8, 0xc3, 0x70, 0x3a, 0x2f, 0x70, 0x63, 0xf9, 0xff, 0x33, 0x31, 0xf8, + 0x07, 0x1d, 0x62, 0xbc, 0xb7, 0xea, 0x50, 0xa4, 0xd4, 0xc0, 0xdf, 0x6d, 0xd0, 0x4b, 0x3e, 0x4f, + 0x03, 0x74, 0x39, 0x0d, 0xd0, 0xb7, 0x69, 0x80, 0xde, 0xce, 0x02, 0xef, 0x72, 0x16, 0x78, 0x5f, + 0x67, 0x81, 0x87, 0xaf, 0x31, 0xbb, 0x43, 0x6b, 0xab, 0xd9, 0x47, 0xcf, 0xee, 0x66, 0xcc, 0x9c, + 0x0f, 0x07, 0xdd, 0x44, 0xf2, 0x70, 0x15, 0x38, 0x62, 0xb2, 0x52, 0x85, 0x63, 0xb7, 0xea, 0xe6, + 0x65, 0x01, 0x7a, 0xb0, 0x6d, 0x77, 0xf1, 0xfe, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xbe, + 0x0f, 0x18, 0x0a, 0x04, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -481,6 +535,67 @@ func (m *NameRecord) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CreateRootNameProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CreateRootNameProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CreateRootNameProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Restricted { + i-- + if m.Restricted { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } + if len(m.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintName(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0x22 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintName(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintName(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintName(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *EventNameBound) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -674,6 +789,34 @@ func (m *NameRecord) Size() (n int) { return n } +func (m *CreateRootNameProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovName(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovName(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovName(uint64(l)) + } + l = len(m.Owner) + if l > 0 { + n += 1 + l + sovName(uint64(l)) + } + if m.Restricted { + n += 2 + } + return n +} + func (m *EventNameBound) Size() (n int) { if m == nil { return 0 @@ -1001,6 +1144,204 @@ func (m *NameRecord) Unmarshal(dAtA []byte) error { } return nil } +func (m *CreateRootNameProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CreateRootNameProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreateRootNameProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthName + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthName + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthName + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthName + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthName + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthName + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthName + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthName + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Owner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Restricted", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowName + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Restricted = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipName(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthName + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *EventNameBound) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/name/types/proposal.go b/x/name/types/proposal.go new file mode 100644 index 0000000000..ea2a962c97 --- /dev/null +++ b/x/name/types/proposal.go @@ -0,0 +1,79 @@ +package types + +import ( + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + govtypesv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + // ProposalTypeCreateRootName defines the type for a CreateRootNameProposal + ProposalTypeCreateRootName = "CreateRootName" + ProposalTypeModifyName = "ModifyName" +) + +// Assert CreateRootNameProposal implements govtypesv1beta1.Content at compile-time +var _ govtypesv1beta1.Content = &CreateRootNameProposal{} + +func init() { + govtypesv1beta1.RegisterProposalType(ProposalTypeCreateRootName) +} + +// NewCreateRootNameProposal create a new governance proposal request to create a root name +func NewCreateRootNameProposal(title, description, name string, owner sdk.AccAddress, restricted bool) *CreateRootNameProposal { + return &CreateRootNameProposal{ + Title: title, + Description: description, + Name: name, + Owner: owner.String(), + Restricted: restricted, + } +} + +// GetTitle returns the title of a community pool spend proposal. +func (crnp CreateRootNameProposal) GetTitle() string { return crnp.Title } + +// GetDescription returns the description of a community pool spend proposal. +func (crnp CreateRootNameProposal) GetDescription() string { return crnp.Description } + +// ProposalRoute returns the routing key of a community pool spend proposal. +func (crnp CreateRootNameProposal) ProposalRoute() string { return RouterKey } + +// ProposalType returns the type of a community pool spend proposal. +func (crnp CreateRootNameProposal) ProposalType() string { return ProposalTypeCreateRootName } + +// ValidateBasic runs basic stateless validity checks +func (crnp CreateRootNameProposal) ValidateBasic() error { + err := govtypesv1beta1.ValidateAbstract(crnp) + if err != nil { + return err + } + if strings.TrimSpace(crnp.Owner) != "" { + if _, err := sdk.AccAddressFromBech32(crnp.Owner); err != nil { + return ErrInvalidAddress + } + } + if strings.TrimSpace(crnp.Name) == "" { + return ErrInvalidLengthName + } + if strings.Contains(crnp.Name, ".") { + return ErrNameContainsSegments + } + + return nil +} + +// String implements the Stringer interface. +func (crnp CreateRootNameProposal) String() string { + var b strings.Builder + b.WriteString(fmt.Sprintf(`Create Root Name Proposal: + Title: %s + Description: %s + Owner: %s + Name: %s + Restricted: %v +`, crnp.Title, crnp.Description, crnp.Owner, crnp.Name, crnp.Restricted)) + return b.String() +} diff --git a/x/name/types/proposal_test.go b/x/name/types/proposal_test.go new file mode 100644 index 0000000000..8ea6c5547e --- /dev/null +++ b/x/name/types/proposal_test.go @@ -0,0 +1,37 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +func TestNewCreateRootNameProposal(t *testing.T) { + crnp := NewCreateRootNameProposal("test title", "test description", "root", sdk.AccAddress{}, false) + + require.Equal(t, "test title", crnp.GetTitle()) + require.Equal(t, "test description", crnp.GetDescription()) + require.Equal(t, RouterKey, crnp.ProposalRoute()) + require.Equal(t, ProposalTypeCreateRootName, crnp.ProposalType()) + require.Equal(t, false, crnp.Restricted) + require.Equal(t, sdk.AccAddress{}.String(), crnp.Owner) + require.Nil(t, crnp.ValidateBasic()) + require.Equal(t, `Create Root Name Proposal: + Title: test title + Description: test description + Owner: + Name: root + Restricted: false +`, crnp.String()) +} + +type IntegrationTestSuite struct { + suite.Suite +} + +func TestIntegrationTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +}