forked from cerc-io/laconicd-deprecated
rename nameservie to registry (#54)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package types
|
||||
|
||||
type Attributes interface {
|
||||
GetType() string
|
||||
}
|
||||
Generated
+1309
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||
)
|
||||
|
||||
// RegisterLegacyAminoCodec registers the necessary x/bond interfaces and concrete types
|
||||
// on the provided LegacyAmino codec. These types are used for Amino JSON serialization.
|
||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||
cdc.RegisterConcrete(&MsgSetName{}, "registry/SetName", nil)
|
||||
cdc.RegisterConcrete(&MsgReserveAuthority{}, "registry/ReserveAuthority", nil)
|
||||
cdc.RegisterConcrete(&MsgDeleteNameAuthority{}, "registry/DeleteAuthority", nil)
|
||||
cdc.RegisterConcrete(&MsgSetAuthorityBond{}, "registry/SetAuthorityBond", nil)
|
||||
|
||||
cdc.RegisterConcrete(&MsgSetRecord{}, "registry/SetRecord", nil)
|
||||
cdc.RegisterConcrete(&MsgRenewRecord{}, "registry/RenewRecord", nil)
|
||||
cdc.RegisterConcrete(&MsgAssociateBond{}, "registry/AssociateBond", nil)
|
||||
cdc.RegisterConcrete(&MsgDissociateBond{}, "registry/DissociateBond", nil)
|
||||
cdc.RegisterConcrete(&MsgDissociateRecords{}, "registry/DissociateRecords", nil)
|
||||
cdc.RegisterConcrete(&MsgReAssociateRecords{}, "registry/ReassociateRecords", nil)
|
||||
}
|
||||
|
||||
func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
registry.RegisterImplementations((*sdk.Msg)(nil),
|
||||
&MsgSetName{},
|
||||
&MsgReserveAuthority{},
|
||||
&MsgDeleteNameAuthority{},
|
||||
&MsgSetAuthorityBond{},
|
||||
|
||||
&MsgSetRecord{},
|
||||
&MsgRenewRecord{},
|
||||
&MsgAssociateBond{},
|
||||
&MsgDissociateBond{},
|
||||
&MsgDissociateRecords{},
|
||||
&MsgReAssociateRecords{},
|
||||
)
|
||||
|
||||
registry.RegisterInterface(
|
||||
"vulcanize.registry.v1beta1.ServiceProvideRegistration",
|
||||
(*Attributes)(nil),
|
||||
&ServiceProviderRegistration{},
|
||||
)
|
||||
|
||||
registry.RegisterInterface(
|
||||
"vulcanize.registry.v1beta1.WebsiteRegistrationRecord",
|
||||
(*Attributes)(nil),
|
||||
&WebsiteRegistrationRecord{},
|
||||
)
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
}
|
||||
|
||||
var (
|
||||
amino = codec.NewLegacyAmino()
|
||||
ModuleCdc = codec.NewAminoCodec(amino)
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterLegacyAminoCodec(amino)
|
||||
cryptocodec.RegisterCrypto(amino)
|
||||
amino.Seal()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
EventTypeSetRecord = "set"
|
||||
EventTypeDeleteName = "delete-name"
|
||||
EventTypeReserveNameAuthority = "reserve-authority"
|
||||
EventTypeAuthorityBond = "authority-bond"
|
||||
EventTypeRenewRecord = "renew-record"
|
||||
EventTypeAssociateBond = "associate-bond"
|
||||
EventTypeDissociateBond = "dissociate-bond"
|
||||
EventTypeDissociateRecords = "dissociate-record"
|
||||
EventTypeReAssociateRecords = "re-associate-records"
|
||||
|
||||
AttributeKeySigner = "signer"
|
||||
AttributeKeyOwner = "owner"
|
||||
AttributeKeyBondID = "bond-id"
|
||||
AttributeKeyPayload = "payload"
|
||||
AttributeKeyOldBondID = "old-bond-id"
|
||||
AttributeKeyNewBondID = "new-bond-id"
|
||||
AttributeKeyCID = "cid"
|
||||
AttributeKeyName = "name"
|
||||
AttributeKeyCRN = "crn"
|
||||
AttributeKeyRecordID = "record-id"
|
||||
AttributeValueCategory = ModuleName
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
package types
|
||||
|
||||
func NewGenesisState(params Params, records []Record, authorities []AuthorityEntry, names []NameEntry) GenesisState {
|
||||
return GenesisState{
|
||||
Params: params,
|
||||
Records: records,
|
||||
Authorities: authorities,
|
||||
Names: names,
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultGenesisState sets default evm genesis state with empty accounts and default params and
|
||||
// chain config values.
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: DefaultParams(),
|
||||
Records: []Record{},
|
||||
Authorities: []AuthorityEntry{},
|
||||
Names: []NameEntry{},
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateGenesis(data GenesisState) error {
|
||||
err := data.Params.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Generated
+522
@@ -0,0 +1,522 @@
|
||||
// Code generated by protoc-gen-gogo. DO NOT EDIT.
|
||||
// source: vulcanize/registry/v1beta1/genesis.proto
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// GenesisState defines the registry module's genesis state.
|
||||
type GenesisState struct {
|
||||
// params defines all the params of registry module.
|
||||
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
|
||||
// records
|
||||
Records []Record `protobuf:"bytes,2,rep,name=records,proto3" json:"records" json:"records" yaml:"records"`
|
||||
// authorities
|
||||
Authorities []AuthorityEntry `protobuf:"bytes,3,rep,name=authorities,proto3" json:"authorities" json:"authorities" yaml:"authorities"`
|
||||
// names
|
||||
Names []NameEntry `protobuf:"bytes,4,rep,name=names,proto3" json:"names" json:"names" yaml:"names"`
|
||||
}
|
||||
|
||||
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
||||
func (m *GenesisState) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisState) ProtoMessage() {}
|
||||
func (*GenesisState) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_8e599869d3a2e5ff, []int{0}
|
||||
}
|
||||
func (m *GenesisState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisState.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisState) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisState) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisState.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisState) GetParams() Params {
|
||||
if m != nil {
|
||||
return m.Params
|
||||
}
|
||||
return Params{}
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetRecords() []Record {
|
||||
if m != nil {
|
||||
return m.Records
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetAuthorities() []AuthorityEntry {
|
||||
if m != nil {
|
||||
return m.Authorities
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetNames() []NameEntry {
|
||||
if m != nil {
|
||||
return m.Names
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*GenesisState)(nil), "vulcanize.registry.v1beta1.GenesisState")
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("vulcanize/registry/v1beta1/genesis.proto", fileDescriptor_8e599869d3a2e5ff)
|
||||
}
|
||||
|
||||
var fileDescriptor_8e599869d3a2e5ff = []byte{
|
||||
// 340 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xb1, 0x4e, 0xc2, 0x40,
|
||||
0x18, 0x80, 0x5b, 0x41, 0x4c, 0x8a, 0x53, 0xe3, 0x50, 0x49, 0x2c, 0xd8, 0x84, 0x04, 0x8d, 0xf4,
|
||||
0x82, 0x6e, 0x4e, 0xda, 0x44, 0xdd, 0x8c, 0xa9, 0x9b, 0x83, 0xc9, 0x71, 0xfc, 0x29, 0x67, 0x68,
|
||||
0x8f, 0xdc, 0x1d, 0xc4, 0xea, 0x4b, 0x18, 0x9f, 0x8a, 0x91, 0xd1, 0x89, 0x18, 0x78, 0x03, 0x9f,
|
||||
0xc0, 0x70, 0x77, 0x05, 0x16, 0x71, 0xbb, 0xff, 0xf2, 0xfd, 0xdf, 0x37, 0xfc, 0x4e, 0x6b, 0x3c,
|
||||
0x1a, 0x10, 0x9c, 0xd1, 0x37, 0x40, 0x1c, 0x12, 0x2a, 0x24, 0xcf, 0xd1, 0xb8, 0xd3, 0x05, 0x89,
|
||||
0x3b, 0x28, 0x81, 0x0c, 0x04, 0x15, 0xe1, 0x90, 0x33, 0xc9, 0xdc, 0xda, 0x8a, 0x0c, 0x0b, 0x32,
|
||||
0x34, 0x64, 0xed, 0x20, 0x61, 0x09, 0x53, 0x18, 0x5a, 0xbe, 0xf4, 0x46, 0xed, 0x64, 0x8b, 0x7b,
|
||||
0xa5, 0x50, 0x68, 0xf0, 0x59, 0x72, 0xf6, 0xef, 0x74, 0xee, 0x51, 0x62, 0x09, 0xee, 0x95, 0x53,
|
||||
0x19, 0x62, 0x8e, 0x53, 0xe1, 0xd9, 0x0d, 0xbb, 0x55, 0x3d, 0x0f, 0xc2, 0xbf, 0xf3, 0xe1, 0x83,
|
||||
0x22, 0xa3, 0xf2, 0x64, 0x56, 0xb7, 0x62, 0xb3, 0xe7, 0x12, 0x67, 0x8f, 0x03, 0x61, 0xbc, 0x27,
|
||||
0xbc, 0x9d, 0x46, 0xe9, 0x3f, 0x45, 0xac, 0xd0, 0xa8, 0xb9, 0x54, 0xfc, 0xcc, 0xea, 0x47, 0x2f,
|
||||
0x82, 0x65, 0x97, 0x81, 0x11, 0x04, 0x8d, 0x1c, 0xa7, 0x83, 0xf5, 0x18, 0x17, 0x66, 0xf7, 0xdd,
|
||||
0xa9, 0xe2, 0x91, 0xec, 0x33, 0x4e, 0x25, 0x05, 0xe1, 0x95, 0x54, 0xe8, 0x74, 0x5b, 0xe8, 0xda,
|
||||
0xe0, 0xf9, 0x4d, 0x26, 0x79, 0x1e, 0xb5, 0x4d, 0xb0, 0xa9, 0x83, 0x1b, 0xb2, 0x22, 0xba, 0xf9,
|
||||
0x15, 0x6f, 0xd6, 0xdc, 0x67, 0x67, 0x37, 0xc3, 0x29, 0x08, 0xaf, 0xac, 0xb2, 0xcd, 0x6d, 0xd9,
|
||||
0x7b, 0x9c, 0x82, 0x2e, 0x1e, 0x9b, 0xe2, 0xa1, 0x2e, 0x2a, 0x43, 0xd1, 0xd2, 0x43, 0xac, 0xb5,
|
||||
0xd1, 0xed, 0x64, 0xee, 0xdb, 0xd3, 0xb9, 0x6f, 0x7f, 0xcf, 0x7d, 0xfb, 0x63, 0xe1, 0x5b, 0xd3,
|
||||
0x85, 0x6f, 0x7d, 0x2d, 0x7c, 0xeb, 0xe9, 0x2c, 0xa1, 0xb2, 0x3f, 0xea, 0x86, 0x84, 0xa5, 0x88,
|
||||
0x00, 0x27, 0x6d, 0xca, 0xd0, 0x00, 0x13, 0x96, 0x51, 0xd2, 0x43, 0xaf, 0xeb, 0x6b, 0xcb, 0x7c,
|
||||
0x08, 0xa2, 0x5b, 0x51, 0x37, 0xbe, 0xf8, 0x0d, 0x00, 0x00, 0xff, 0xff, 0xba, 0xb2, 0x8e, 0x8c,
|
||||
0x6c, 0x02, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Names) > 0 {
|
||||
for iNdEx := len(m.Names) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Names[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
}
|
||||
if len(m.Authorities) > 0 {
|
||||
for iNdEx := len(m.Authorities) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Authorities[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.Records) > 0 {
|
||||
for iNdEx := len(m.Records) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Records[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
{
|
||||
size, err := m.Params.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovGenesis(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *GenesisState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = m.Params.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
if len(m.Records) > 0 {
|
||||
for _, e := range m.Records {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.Authorities) > 0 {
|
||||
for _, e := range m.Authorities {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.Names) > 0 {
|
||||
for _, e := range m.Names {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovGenesis(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozGenesis(x uint64) (n int) {
|
||||
return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *GenesisState) 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 ErrIntOverflowGenesis
|
||||
}
|
||||
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: GenesisState: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Params", 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
|
||||
}
|
||||
if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Records", 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.Records = append(m.Records, Record{})
|
||||
if err := m.Records[len(m.Records)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Authorities", 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.Authorities = append(m.Authorities, AuthorityEntry{})
|
||||
if err := m.Authorities[len(m.Authorities)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Names", 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.Names = append(m.Names, NameEntry{})
|
||||
if err := m.Names[len(m.Names)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipGenesis(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupGenesis
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
package types
|
||||
|
||||
const (
|
||||
// ModuleName is the name of the staking module
|
||||
ModuleName = "registry"
|
||||
|
||||
// RecordRentModuleAccountName is the name of the module account that keeps track of record rents paid.
|
||||
RecordRentModuleAccountName = "record_rent"
|
||||
|
||||
// AuthorityRentModuleAccountName is the name of the module account that keeps track of authority rents paid.
|
||||
AuthorityRentModuleAccountName = "authority_rent"
|
||||
|
||||
// StoreKey is the string store representation
|
||||
StoreKey = ModuleName
|
||||
|
||||
// QuerierRoute is the querier route for the staking module
|
||||
QuerierRoute = ModuleName
|
||||
|
||||
// RouterKey is the msg router key for the staking module
|
||||
RouterKey = ModuleName
|
||||
)
|
||||
@@ -0,0 +1,187 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.Msg = &MsgSetName{}
|
||||
_ sdk.Msg = &MsgReserveAuthority{}
|
||||
_ sdk.Msg = &MsgSetAuthorityBond{}
|
||||
_ sdk.Msg = &MsgDeleteNameAuthority{}
|
||||
)
|
||||
|
||||
// NewMsgSetName is the constructor function for MsgSetName.
|
||||
func NewMsgSetName(crn string, cid string, signer sdk.AccAddress) MsgSetName {
|
||||
return MsgSetName{
|
||||
Crn: crn,
|
||||
Cid: cid,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgSetName) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgSetName) Type() string { return "set-name" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgSetName) ValidateBasic() error {
|
||||
if msg.Crn == "" {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CRN is required.")
|
||||
}
|
||||
|
||||
if msg.Cid == "" {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgSetName
|
||||
func (msg MsgSetName) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgSetName) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgReserveAuthority is the constructor function for MsgReserveName.
|
||||
func NewMsgReserveAuthority(name string, signer sdk.AccAddress, owner sdk.AccAddress) MsgReserveAuthority {
|
||||
return MsgReserveAuthority{
|
||||
Name: name,
|
||||
Owner: owner.String(),
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgReserveAuthority) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgReserveAuthority) Type() string { return "reserve-authority" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgReserveAuthority) ValidateBasic() error {
|
||||
if len(msg.Name) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgSetName
|
||||
func (msg MsgReserveAuthority) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgReserveAuthority) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgSetAuthorityBond is the constructor function for MsgSetAuthorityBond.
|
||||
func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) MsgSetAuthorityBond {
|
||||
return MsgSetAuthorityBond{
|
||||
Name: name,
|
||||
Signer: signer.String(),
|
||||
BondId: bondID,
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgSetAuthorityBond) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgSetAuthorityBond) Type() string { return "authority-bond" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgSetAuthorityBond) ValidateBasic() error {
|
||||
if len(msg.Name) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
if len(msg.BondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgSetName
|
||||
func (msg MsgSetAuthorityBond) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgSetAuthorityBond) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgDeleteNameAuthority is the constructor function for MsgDeleteNameAuthority.
|
||||
func NewMsgDeleteNameAuthority(crn string, signer sdk.AccAddress) MsgDeleteNameAuthority {
|
||||
return MsgDeleteNameAuthority{
|
||||
Crn: crn,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgDeleteNameAuthority) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgDeleteNameAuthority) Type() string { return "delete-name" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgDeleteNameAuthority) ValidateBasic() error {
|
||||
if len(msg.Crn) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "crn is required.")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
_, err := url.Parse(msg.Crn)
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid crn.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgSetName
|
||||
func (msg MsgDeleteNameAuthority) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgDeleteNameAuthority) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
)
|
||||
|
||||
// Default parameter values.
|
||||
var (
|
||||
// DefaultRecordRent is the default record rent for 1 time period (see expiry time).
|
||||
DefaultRecordRent = sdk.NewInt(1000000)
|
||||
|
||||
// DefaultRecordExpiryTime is the default record expiry time (1 year).
|
||||
DefaultRecordExpiryTime = time.Hour * 24 * 365
|
||||
|
||||
DefaultAuthorityRent = sdk.NewInt(1000000)
|
||||
DefaultAuthorityExpiryTime = time.Hour * 24 * 365
|
||||
DefaultAuthorityGracePeriod = time.Hour * 24 * 2
|
||||
|
||||
DefaultAuthorityAuctionEnabled = false
|
||||
DefaultCommitsDuration = time.Hour * 24
|
||||
DefaultRevealsDuration = time.Hour * 24
|
||||
DefaultCommitFee = sdk.NewInt(1000000)
|
||||
DefaultRevealFee = sdk.NewInt(1000000)
|
||||
DefaultMinimumBid = sdk.NewInt(5000000)
|
||||
)
|
||||
|
||||
// Keys for parameter access
|
||||
var (
|
||||
KeyRecordRent = []byte("RecordRent")
|
||||
KeyRecordRentDuration = []byte("RecordRentDuration")
|
||||
|
||||
KeyAuthorityRent = []byte("AuthorityRent")
|
||||
KeyAuthorityRentDuration = []byte("AuthorityRentDuration")
|
||||
KeyAuthorityGracePeriod = []byte("AuthorityGracePeriod")
|
||||
|
||||
KeyAuthorityAuctionEnabled = []byte("AuthorityAuctionEnabled")
|
||||
KeyCommitsDuration = []byte("AuthorityAuctionCommitsDuration")
|
||||
KeyRevealsDuration = []byte("AuthorityAuctionRevealsDuration")
|
||||
KeyCommitFee = []byte("AuthorityAuctionCommitFee")
|
||||
KeyRevealFee = []byte("AuthorityAuctionRevealFee")
|
||||
KeyMinimumBid = []byte("AuthorityAuctionMinimumBid")
|
||||
)
|
||||
|
||||
var _ paramtypes.ParamSet = &Params{}
|
||||
|
||||
// ParamKeyTable ParamTable for staking module
|
||||
func ParamKeyTable() paramtypes.KeyTable {
|
||||
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
|
||||
}
|
||||
|
||||
// ParamSetPairs returns the parameter set pairs.
|
||||
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
||||
return paramtypes.ParamSetPairs{
|
||||
paramtypes.NewParamSetPair(KeyRecordRent, &p.RecordRent, validateRecordRent),
|
||||
paramtypes.NewParamSetPair(KeyRecordRentDuration, &p.RecordRentDuration, validateRecordRentDuration),
|
||||
|
||||
paramtypes.NewParamSetPair(KeyAuthorityRent, &p.AuthorityRent, validateAuthorityRent),
|
||||
paramtypes.NewParamSetPair(KeyAuthorityRentDuration, &p.AuthorityRentDuration, validateAuthorityRentDuration),
|
||||
paramtypes.NewParamSetPair(KeyAuthorityGracePeriod, &p.AuthorityGracePeriod, validateAuthorityGracePeriod),
|
||||
|
||||
paramtypes.NewParamSetPair(KeyAuthorityAuctionEnabled, &p.AuthorityAuctionEnabled, validateAuthorityAuctionEnabled),
|
||||
paramtypes.NewParamSetPair(KeyCommitsDuration, &p.AuthorityAuctionCommitsDuration, validateCommitsDuration),
|
||||
paramtypes.NewParamSetPair(KeyRevealsDuration, &p.AuthorityAuctionRevealsDuration, validateRevealsDuration),
|
||||
paramtypes.NewParamSetPair(KeyCommitFee, &p.AuthorityAuctionCommitFee, validateCommitFee),
|
||||
paramtypes.NewParamSetPair(KeyRevealFee, &p.AuthorityAuctionRevealFee, validateRevealFee),
|
||||
paramtypes.NewParamSetPair(KeyMinimumBid, &p.AuthorityAuctionMinimumBid, validateMinimumBid),
|
||||
}
|
||||
}
|
||||
|
||||
// NewParams creates a new Params instance
|
||||
func NewParams(recordRent sdk.Coin, recordRentDuration time.Duration,
|
||||
authorityRent sdk.Coin, authorityRentDuration time.Duration, authorityGracePeriod time.Duration,
|
||||
authorityAuctionEnabled bool, commitsDuration time.Duration, revealsDuration time.Duration,
|
||||
commitFee sdk.Coin, revealFee sdk.Coin, minimumBid sdk.Coin,
|
||||
) Params {
|
||||
return Params{
|
||||
RecordRent: recordRent,
|
||||
RecordRentDuration: recordRentDuration,
|
||||
|
||||
AuthorityRent: authorityRent,
|
||||
AuthorityRentDuration: authorityRentDuration,
|
||||
AuthorityGracePeriod: authorityGracePeriod,
|
||||
|
||||
AuthorityAuctionEnabled: authorityAuctionEnabled,
|
||||
AuthorityAuctionCommitsDuration: commitsDuration,
|
||||
AuthorityAuctionRevealsDuration: revealsDuration,
|
||||
AuthorityAuctionCommitFee: commitFee,
|
||||
AuthorityAuctionRevealFee: revealFee,
|
||||
AuthorityAuctionMinimumBid: minimumBid,
|
||||
}
|
||||
}
|
||||
|
||||
// Equal returns a boolean determining if two Params types are identical.
|
||||
func (p Params) Equal(p2 Params) bool {
|
||||
bz1 := ModuleCdc.MustMarshalLengthPrefixed(&p)
|
||||
bz2 := ModuleCdc.MustMarshalLengthPrefixed(&p2)
|
||||
return bytes.Equal(bz1, bz2)
|
||||
}
|
||||
|
||||
// DefaultParams returns a default set of parameters.
|
||||
func DefaultParams() Params {
|
||||
return NewParams(
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, DefaultRecordRent), DefaultRecordExpiryTime,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, DefaultAuthorityRent),
|
||||
DefaultAuthorityExpiryTime, DefaultAuthorityGracePeriod, DefaultAuthorityAuctionEnabled, DefaultCommitsDuration,
|
||||
DefaultRevealsDuration,
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, DefaultCommitFee),
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, DefaultRevealFee),
|
||||
sdk.NewCoin(sdk.DefaultBondDenom, DefaultMinimumBid),
|
||||
)
|
||||
}
|
||||
|
||||
func validateAmount(name string, i interface{}) error {
|
||||
v, ok := i.(sdk.Coin)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
}
|
||||
|
||||
if v.Amount.IsNegative() {
|
||||
return fmt.Errorf("%s can't be negative", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDuration(name string, i interface{}) error {
|
||||
v, ok := i.(time.Duration)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s invalid parameter type: %T", name, i)
|
||||
}
|
||||
|
||||
if v <= 0 {
|
||||
return fmt.Errorf("%s must be a positive integer", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRecordRent(i interface{}) error {
|
||||
return validateAmount("RecordRent", i)
|
||||
}
|
||||
|
||||
func validateRecordRentDuration(i interface{}) error {
|
||||
return validateDuration("RecordRentDuration", i)
|
||||
}
|
||||
|
||||
func validateAuthorityRent(i interface{}) error {
|
||||
return validateAmount("AuthorityRent", i)
|
||||
}
|
||||
|
||||
func validateAuthorityRentDuration(i interface{}) error {
|
||||
return validateDuration("AuthorityRentDuration", i)
|
||||
}
|
||||
|
||||
func validateAuthorityGracePeriod(i interface{}) error {
|
||||
return validateDuration("AuthorityGracePeriod", i)
|
||||
}
|
||||
|
||||
func validateAuthorityAuctionEnabled(i interface{}) error {
|
||||
_, ok := i.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s invalid parameter type: %T", "AuthorityAuctionEnabled", i)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateCommitsDuration(i interface{}) error {
|
||||
return validateDuration("AuthorityCommitsDuration", i)
|
||||
}
|
||||
|
||||
func validateRevealsDuration(i interface{}) error {
|
||||
return validateDuration("AuthorityRevealsDuration", i)
|
||||
}
|
||||
|
||||
func validateCommitFee(i interface{}) error {
|
||||
return validateAmount("AuthorityCommitFee", i)
|
||||
}
|
||||
|
||||
func validateRevealFee(i interface{}) error {
|
||||
return validateAmount("AuthorityRevealFee", i)
|
||||
}
|
||||
|
||||
func validateMinimumBid(i interface{}) error {
|
||||
return validateAmount("AuthorityMinimumBid", i)
|
||||
}
|
||||
|
||||
// Validate a set of params.
|
||||
func (p Params) Validate() error {
|
||||
if err := validateRecordRent(p.RecordRent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateRecordRentDuration(p.RecordRentDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateAuthorityRent(p.AuthorityRent); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateAuthorityRentDuration(p.AuthorityRentDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateAuthorityGracePeriod(p.AuthorityGracePeriod); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateAuthorityAuctionEnabled(p.AuthorityAuctionEnabled); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateCommitsDuration(p.AuthorityAuctionCommitsDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateRevealsDuration(p.AuthorityAuctionRevealsDuration); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateCommitFee(p.AuthorityAuctionCommitFee); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateRevealFee(p.AuthorityAuctionRevealFee); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateMinimumBid(p.AuthorityAuctionMinimumBid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Generated
+6272
File diff suppressed because it is too large
Load Diff
Generated
+1002
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,257 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.Msg = &MsgSetRecord{}
|
||||
_ sdk.Msg = &MsgRenewRecord{}
|
||||
_ sdk.Msg = &MsgAssociateBond{}
|
||||
_ sdk.Msg = &MsgDissociateBond{}
|
||||
_ sdk.Msg = &MsgDissociateRecords{}
|
||||
_ sdk.Msg = &MsgReAssociateRecords{}
|
||||
)
|
||||
|
||||
// NewMsgSetRecord is the constructor function for MsgSetRecord.
|
||||
func NewMsgSetRecord(payload Payload, bondID string, signer sdk.AccAddress) MsgSetRecord {
|
||||
return MsgSetRecord{
|
||||
Payload: payload,
|
||||
BondId: bondID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgSetRecord) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgSetRecord) Type() string { return "set-record" }
|
||||
|
||||
func (msg MsgSetRecord) ValidateBasic() error {
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||
}
|
||||
owners := msg.Payload.Record.Owners
|
||||
for _, owner := range owners {
|
||||
if owner == "" {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record owner not set.")
|
||||
}
|
||||
}
|
||||
|
||||
if len(msg.BondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond ID is required.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg MsgSetRecord) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for the msg MsgCreateBond
|
||||
func (msg MsgSetRecord) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// NewMsgRenewRecord is the constructor function for MsgRenewRecord.
|
||||
func NewMsgRenewRecord(recordID string, signer sdk.AccAddress) MsgRenewRecord {
|
||||
return MsgRenewRecord{
|
||||
RecordId: recordID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgRenewRecord) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgRenewRecord) Type() string { return "renew-record" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgRenewRecord) ValidateBasic() error {
|
||||
if len(msg.RecordId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||
}
|
||||
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for Msg
|
||||
func (msg MsgRenewRecord) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgRenewRecord) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgAssociateBond is the constructor function for MsgAssociateBond.
|
||||
func NewMsgAssociateBond(recordID, bondID string, signer sdk.AccAddress) MsgAssociateBond {
|
||||
return MsgAssociateBond{
|
||||
BondId: bondID,
|
||||
RecordId: recordID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgAssociateBond) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgAssociateBond) Type() string { return "associate-bond" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgAssociateBond) ValidateBasic() error {
|
||||
if len(msg.RecordId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||
}
|
||||
if len(msg.BondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
||||
}
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for Msg
|
||||
func (msg MsgAssociateBond) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgAssociateBond) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgDissociateBond is the constructor function for MsgDissociateBond.
|
||||
func NewMsgDissociateBond(recordID string, signer sdk.AccAddress) MsgDissociateBond {
|
||||
return MsgDissociateBond{
|
||||
RecordId: recordID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgDissociateBond) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgDissociateBond) Type() string { return "dissociate-bond" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgDissociateBond) ValidateBasic() error {
|
||||
if len(msg.RecordId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||
}
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for Msg
|
||||
func (msg MsgDissociateBond) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgDissociateBond) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgDissociateRecords is the constructor function for MsgDissociateRecords.
|
||||
func NewMsgDissociateRecords(bondID string, signer sdk.AccAddress) MsgDissociateRecords {
|
||||
return MsgDissociateRecords{
|
||||
BondId: bondID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgDissociateRecords) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgDissociateRecords) Type() string { return "dissociate-records" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgDissociateRecords) ValidateBasic() error {
|
||||
if len(msg.BondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
||||
}
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for Msg
|
||||
func (msg MsgDissociateRecords) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgDissociateRecords) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
|
||||
// NewMsgReAssociateRecords is the constructor function for MsgReAssociateRecords.
|
||||
func NewMsgReAssociateRecords(oldBondID, newBondID string, signer sdk.AccAddress) MsgReAssociateRecords {
|
||||
return MsgReAssociateRecords{
|
||||
OldBondId: oldBondID,
|
||||
NewBondId: newBondID,
|
||||
Signer: signer.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// Route Implements Msg.
|
||||
func (msg MsgReAssociateRecords) Route() string { return RouterKey }
|
||||
|
||||
// Type Implements Msg.
|
||||
func (msg MsgReAssociateRecords) Type() string { return "reassociate-records" }
|
||||
|
||||
// ValidateBasic Implements Msg.
|
||||
func (msg MsgReAssociateRecords) ValidateBasic() error {
|
||||
if len(msg.OldBondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required.")
|
||||
}
|
||||
if len(msg.NewBondId) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required.")
|
||||
}
|
||||
if len(msg.Signer) == 0 {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSignBytes gets the sign bytes for Msg
|
||||
func (msg MsgReAssociateRecords) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&msg)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// GetSigners Implements Msg.
|
||||
func (msg MsgReAssociateRecords) GetSigners() []sdk.AccAddress {
|
||||
accAddr, _ := sdk.AccAddressFromBech32(msg.Signer)
|
||||
return []sdk.AccAddress{accAddr}
|
||||
}
|
||||
Generated
+3751
File diff suppressed because it is too large
Load Diff
Generated
+4643
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,221 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cerc-io/laconicd/x/registry/helpers"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
canonicalJson "github.com/gibson042/canonicaljson-go"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
AuthorityActive = "active"
|
||||
AuthorityExpired = "expired"
|
||||
AuthorityUnderAuction = "auction"
|
||||
)
|
||||
|
||||
// PayloadType represents a signed record payload that can be serialized from/to YAML.
|
||||
type PayloadType struct {
|
||||
Record map[string]interface{} `json:"record"`
|
||||
Signatures []Signature `json:"signatures"`
|
||||
}
|
||||
|
||||
// ToPayload converts PayloadType to Payload object.
|
||||
// Why? Because go-amino can't handle maps: https://github.com/tendermint/go-amino/issues/4.
|
||||
func (payloadObj *PayloadType) ToPayload() (Payload, error) {
|
||||
attributes, err := payLoadAttributes(payloadObj.Record)
|
||||
if err != nil {
|
||||
return Payload{}, err
|
||||
}
|
||||
payload := Payload{
|
||||
Record: &Record{
|
||||
Deleted: false,
|
||||
Owners: nil,
|
||||
Attributes: attributes,
|
||||
},
|
||||
Signatures: payloadObj.Signatures,
|
||||
}
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
func payLoadAttributes(recordPayLoad map[string]interface{}) (*codectypes.Any, error) {
|
||||
recordType, ok := recordPayLoad["type"]
|
||||
if !ok {
|
||||
return &codectypes.Any{}, fmt.Errorf("cannot get type from payload")
|
||||
}
|
||||
bz := helpers.MarshalMapToJSONBytes(recordPayLoad)
|
||||
|
||||
switch recordType.(string) {
|
||||
case "ServiceProviderRegistration":
|
||||
{
|
||||
var attributes ServiceProviderRegistration
|
||||
err := json.Unmarshal(bz, &attributes)
|
||||
if err != nil {
|
||||
return &codectypes.Any{}, err
|
||||
}
|
||||
return codectypes.NewAnyWithValue(&attributes)
|
||||
}
|
||||
case "WebsiteRegistrationRecord":
|
||||
{
|
||||
var attributes WebsiteRegistrationRecord
|
||||
err := json.Unmarshal(bz, &attributes)
|
||||
if err != nil {
|
||||
return &codectypes.Any{}, err
|
||||
}
|
||||
return codectypes.NewAnyWithValue(&attributes)
|
||||
}
|
||||
default:
|
||||
return &codectypes.Any{}, fmt.Errorf("unsupported record type %s", recordType.(string))
|
||||
}
|
||||
}
|
||||
|
||||
// ToReadablePayload converts Payload to PayloadType
|
||||
// It will unmarshal with record attributes
|
||||
func (payload Payload) ToReadablePayload() PayloadType {
|
||||
var payloadType PayloadType
|
||||
bz, err := GetJSONBytesFromAny(*payload.Record.Attributes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
payloadType.Record = helpers.UnMarshalMapFromJSONBytes(bz)
|
||||
payloadType.Signatures = payload.Signatures
|
||||
|
||||
return payloadType
|
||||
}
|
||||
|
||||
// Record to Record Type for human-readable attributes
|
||||
|
||||
func (r *Record) ToRecordType() RecordType {
|
||||
var resourceObj RecordType
|
||||
|
||||
resourceObj.ID = r.Id
|
||||
resourceObj.BondID = r.BondId
|
||||
resourceObj.CreateTime = r.CreateTime
|
||||
resourceObj.ExpiryTime = r.ExpiryTime
|
||||
resourceObj.Deleted = r.Deleted
|
||||
resourceObj.Owners = r.Owners
|
||||
resourceObj.Names = r.Names
|
||||
|
||||
bz, err := GetJSONBytesFromAny(*r.Attributes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
resourceObj.Attributes = helpers.UnMarshalMapFromJSONBytes(bz)
|
||||
|
||||
return resourceObj
|
||||
}
|
||||
|
||||
func GetJSONBytesFromAny(any codectypes.Any) ([]byte, error) {
|
||||
var bz []byte
|
||||
s := strings.Split(any.TypeUrl, ".")
|
||||
switch s[len(s)-1] {
|
||||
case "ServiceProviderRegistration":
|
||||
{
|
||||
var attributes ServiceProviderRegistration
|
||||
err := proto.Unmarshal(any.Value, &attributes)
|
||||
if err != nil {
|
||||
panic("Proto unmarshal error")
|
||||
}
|
||||
|
||||
bz, err = json.Marshal(attributes)
|
||||
if err != nil {
|
||||
panic("JSON marshal error")
|
||||
}
|
||||
}
|
||||
case "WebsiteRegistrationRecord":
|
||||
{
|
||||
var attributes WebsiteRegistrationRecord
|
||||
err := proto.Unmarshal(any.Value, &attributes)
|
||||
if err != nil {
|
||||
panic("Proto unmarshal error")
|
||||
}
|
||||
|
||||
bz, err = json.Marshal(attributes)
|
||||
if err != nil {
|
||||
panic("JSON marshal error")
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported type %s", s[len(s)-1])
|
||||
}
|
||||
|
||||
return bz, nil
|
||||
}
|
||||
|
||||
// RecordType represents a WNS record.
|
||||
type RecordType struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Names []string `json:"names,omitempty"`
|
||||
BondID string `json:"bondId,omitempty"`
|
||||
CreateTime string `json:"createTime,omitempty"`
|
||||
ExpiryTime string `json:"expiryTime,omitempty"`
|
||||
Deleted bool `json:"deleted,omitempty"`
|
||||
Owners []string `json:"owners,omitempty"`
|
||||
Attributes map[string]interface{} `json:"attributes,omitempty"`
|
||||
}
|
||||
|
||||
// ToRecordObj converts Record to RecordObj.
|
||||
// Why? Because go-amino can't handle maps: https://github.com/tendermint/go-amino/issues/4.
|
||||
func (r *RecordType) ToRecordObj() (Record, error) {
|
||||
attributes, err := payLoadAttributes(r.Attributes)
|
||||
if err != nil {
|
||||
return Record{}, err
|
||||
}
|
||||
|
||||
var resourceObj Record
|
||||
|
||||
resourceObj.Id = r.ID
|
||||
resourceObj.BondId = r.BondID
|
||||
resourceObj.CreateTime = r.CreateTime
|
||||
resourceObj.ExpiryTime = r.ExpiryTime
|
||||
resourceObj.Deleted = r.Deleted
|
||||
resourceObj.Owners = r.Owners
|
||||
resourceObj.Attributes = attributes
|
||||
|
||||
return resourceObj, nil
|
||||
}
|
||||
|
||||
// CanonicalJSON returns the canonical JSON representation of the record.
|
||||
func (r *RecordType) CanonicalJSON() []byte {
|
||||
bytes, err := canonicalJson.Marshal(r.Attributes)
|
||||
if err != nil {
|
||||
panic("Record marshal error.")
|
||||
}
|
||||
|
||||
return bytes
|
||||
}
|
||||
|
||||
// GetSignBytes generates a record hash to be signed.
|
||||
func (r *RecordType) GetSignBytes() ([]byte, []byte) {
|
||||
// Double SHA256 hash.
|
||||
|
||||
// Input to the first round of hashing.
|
||||
bytes := r.CanonicalJSON()
|
||||
|
||||
// First round.
|
||||
first := sha256.New()
|
||||
first.Write(bytes)
|
||||
firstHash := first.Sum(nil)
|
||||
|
||||
// Second round of hashing takes as input the output of the first round.
|
||||
second := sha256.New()
|
||||
second.Write(firstHash)
|
||||
secondHash := second.Sum(nil)
|
||||
|
||||
return secondHash, bytes
|
||||
}
|
||||
|
||||
// GetCID gets the record CID.
|
||||
func (r *RecordType) GetCID() (string, error) {
|
||||
id, err := helpers.GetCid(r.CanonicalJSON())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
Reference in New Issue
Block a user