Setup and integrate bond module into the chain (#2)

* Add common message types and update proto gen script

* Update proto gen script to generate pulsar proto code

* Upgrade direct deps

* Populate params and genesis files

* Setup keeper files

* Setup module files with depinject and autocli

* Add placeholder keeper methods

* Integrate bond module into the chain
This commit is contained in:
prathamesh0
2024-02-01 16:28:34 +05:30
committed by GitHub
parent e513f79b81
commit 5ee988ccd8
24 changed files with 4102 additions and 101 deletions
+620
View File
@@ -0,0 +1,620 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cerc/bond/v1/bond.proto
package bond
import (
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/types"
_ "github.com/cosmos/gogoproto/gogoproto"
proto "github.com/cosmos/gogoproto/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
// Params defines the parameters of the bond module.
type Params struct {
// max_bond_amount is maximum amount to bond
MaxBondAmount types.Coin `protobuf:"bytes,1,opt,name=max_bond_amount,json=maxBondAmount,proto3" json:"max_bond_amount" json:"max_bond_amount" yaml:"max_bond_amount"`
}
func (m *Params) Reset() { *m = Params{} }
func (m *Params) String() string { return proto.CompactTextString(m) }
func (*Params) ProtoMessage() {}
func (*Params) Descriptor() ([]byte, []int) {
return fileDescriptor_a3e353c952ca4df9, []int{0}
}
func (m *Params) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) {
xxx_messageInfo_Params.Merge(m, src)
}
func (m *Params) XXX_Size() int {
return m.Size()
}
func (m *Params) XXX_DiscardUnknown() {
xxx_messageInfo_Params.DiscardUnknown(m)
}
var xxx_messageInfo_Params proto.InternalMessageInfo
func (m *Params) GetMaxBondAmount() types.Coin {
if m != nil {
return m.MaxBondAmount
}
return types.Coin{}
}
// Bond represents funds deposited by an account for record rent payments.
type Bond struct {
// id is unique identifier of the bond
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
// owner of the bond
Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"`
// balance of the bond
Balance github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=balance,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balance" json:"balance" yaml:"balance"`
}
func (m *Bond) Reset() { *m = Bond{} }
func (m *Bond) String() string { return proto.CompactTextString(m) }
func (*Bond) ProtoMessage() {}
func (*Bond) Descriptor() ([]byte, []int) {
return fileDescriptor_a3e353c952ca4df9, []int{1}
}
func (m *Bond) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Bond) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Bond.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 *Bond) XXX_Merge(src proto.Message) {
xxx_messageInfo_Bond.Merge(m, src)
}
func (m *Bond) XXX_Size() int {
return m.Size()
}
func (m *Bond) XXX_DiscardUnknown() {
xxx_messageInfo_Bond.DiscardUnknown(m)
}
var xxx_messageInfo_Bond proto.InternalMessageInfo
func (m *Bond) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Bond) GetOwner() string {
if m != nil {
return m.Owner
}
return ""
}
func (m *Bond) GetBalance() github_com_cosmos_cosmos_sdk_types.Coins {
if m != nil {
return m.Balance
}
return nil
}
func init() {
proto.RegisterType((*Params)(nil), "cerc.bond.v1.Params")
proto.RegisterType((*Bond)(nil), "cerc.bond.v1.Bond")
}
func init() { proto.RegisterFile("cerc/bond/v1/bond.proto", fileDescriptor_a3e353c952ca4df9) }
var fileDescriptor_a3e353c952ca4df9 = []byte{
// 344 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0xbd, 0x4e, 0xf3, 0x30,
0x14, 0x8d, 0xdb, 0xef, 0x2b, 0x22, 0xfc, 0x49, 0x51, 0x25, 0x4a, 0x25, 0xd2, 0xaa, 0x2c, 0x5d,
0x6a, 0x2b, 0x45, 0x2c, 0x48, 0x0c, 0x94, 0x17, 0x80, 0x8e, 0x2c, 0x95, 0xe3, 0x44, 0xc1, 0x50,
0xfb, 0x56, 0xb1, 0x1b, 0xd2, 0x95, 0x81, 0x99, 0xe7, 0x60, 0xe7, 0x1d, 0x3a, 0x76, 0x64, 0x2a,
0xa8, 0x7d, 0x03, 0x9e, 0x00, 0xc5, 0x4e, 0x17, 0x90, 0x98, 0x6e, 0xce, 0x39, 0xb9, 0xe7, 0x1e,
0xf9, 0xb8, 0x87, 0x2c, 0x4e, 0x19, 0x09, 0x41, 0x46, 0x24, 0x0b, 0xcc, 0xc4, 0x93, 0x14, 0x34,
0x78, 0xbb, 0x85, 0x80, 0x0d, 0x91, 0x05, 0xcd, 0x7a, 0x02, 0x09, 0x18, 0x81, 0x14, 0x5f, 0xf6,
0x9f, 0xa6, 0xcf, 0x40, 0x09, 0x50, 0x24, 0xa4, 0x2a, 0x26, 0x59, 0x10, 0xc6, 0x9a, 0x06, 0x84,
0x01, 0x97, 0x56, 0xef, 0x3c, 0x21, 0xb7, 0x76, 0x4d, 0x53, 0x2a, 0x94, 0x97, 0xbb, 0x07, 0x82,
0xe6, 0xa3, 0xc2, 0x6f, 0x44, 0x05, 0x4c, 0xa5, 0x6e, 0xa0, 0x36, 0xea, 0xee, 0xf4, 0x8f, 0xb0,
0x35, 0xc1, 0x85, 0x09, 0x2e, 0x4d, 0xf0, 0x15, 0x70, 0x39, 0x38, 0x9b, 0x2f, 0x5b, 0xce, 0xd7,
0xb2, 0xd5, 0xbb, 0x57, 0x20, 0xcf, 0x3b, 0x3f, 0xf6, 0x3b, 0xed, 0x19, 0x15, 0xe3, 0xdf, 0xf4,
0x70, 0x4f, 0xd0, 0x7c, 0x00, 0x32, 0xba, 0xb4, 0xf8, 0x0d, 0xb9, 0xff, 0x0a, 0xe8, 0xed, 0xbb,
0x15, 0x1e, 0x99, 0xab, 0xdb, 0xc3, 0x0a, 0x8f, 0xbc, 0xba, 0xfb, 0x1f, 0x1e, 0x65, 0x9c, 0x36,
0x2a, 0x86, 0xb2, 0xc0, 0x7b, 0x46, 0xee, 0x56, 0x48, 0xc7, 0x54, 0xb2, 0xb8, 0x51, 0x6d, 0x57,
0xff, 0x4e, 0x78, 0x53, 0x26, 0x3c, 0xb6, 0x09, 0xcb, 0xbd, 0x4d, 0xb2, 0x0d, 0x7c, 0xfd, 0x68,
0x75, 0x13, 0xae, 0xef, 0xa6, 0x21, 0x66, 0x20, 0x48, 0xf9, 0x68, 0x76, 0xf4, 0x54, 0xf4, 0x40,
0xf4, 0x6c, 0x12, 0x2b, 0xe3, 0xa8, 0x86, 0x9b, 0xe3, 0x83, 0x8b, 0xf9, 0xca, 0x47, 0x8b, 0x95,
0x8f, 0x3e, 0x57, 0x3e, 0x7a, 0x59, 0xfb, 0xce, 0x62, 0xed, 0x3b, 0xef, 0x6b, 0xdf, 0xb9, 0x3d,
0x49, 0xb8, 0xc6, 0x59, 0x14, 0x62, 0x0d, 0xa4, 0x68, 0xa9, 0xc7, 0x81, 0x8c, 0x29, 0x03, 0xc9,
0x59, 0x3f, 0x22, 0xb9, 0x69, 0x31, 0xac, 0x99, 0x0a, 0x4e, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff,
0xcc, 0xaf, 0x0a, 0xc9, 0xe1, 0x01, 0x00, 0x00,
}
func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
{
size, err := m.MaxBondAmount.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintBond(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0xa
return len(dAtA) - i, nil
}
func (m *Bond) 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 *Bond) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Bond) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Balance) > 0 {
for iNdEx := len(m.Balance) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Balance[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintBond(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
}
}
if len(m.Owner) > 0 {
i -= len(m.Owner)
copy(dAtA[i:], m.Owner)
i = encodeVarintBond(dAtA, i, uint64(len(m.Owner)))
i--
dAtA[i] = 0x12
}
if len(m.Id) > 0 {
i -= len(m.Id)
copy(dAtA[i:], m.Id)
i = encodeVarintBond(dAtA, i, uint64(len(m.Id)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func encodeVarintBond(dAtA []byte, offset int, v uint64) int {
offset -= sovBond(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *Params) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = m.MaxBondAmount.Size()
n += 1 + l + sovBond(uint64(l))
return n
}
func (m *Bond) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Id)
if l > 0 {
n += 1 + l + sovBond(uint64(l))
}
l = len(m.Owner)
if l > 0 {
n += 1 + l + sovBond(uint64(l))
}
if len(m.Balance) > 0 {
for _, e := range m.Balance {
l = e.Size()
n += 1 + l + sovBond(uint64(l))
}
}
return n
}
func sovBond(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozBond(x uint64) (n int) {
return sovBond(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *Params) 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 ErrIntOverflowBond
}
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: Params: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field MaxBondAmount", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowBond
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthBond
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthBond
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.MaxBondAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipBond(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthBond
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *Bond) 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 ErrIntOverflowBond
}
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: Bond: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Bond: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowBond
}
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 ErrInvalidLengthBond
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthBond
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Id = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
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 ErrIntOverflowBond
}
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 ErrInvalidLengthBond
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthBond
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Owner = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowBond
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthBond
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthBond
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Balance = append(m.Balance, types.Coin{})
if err := m.Balance[len(m.Balance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipBond(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthBond
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipBond(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, ErrIntOverflowBond
}
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, ErrIntOverflowBond
}
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, ErrIntOverflowBond
}
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, ErrInvalidLengthBond
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupBond
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthBond
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthBond = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowBond = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupBond = fmt.Errorf("proto: unexpected end of group")
)
+17 -1
View File
@@ -1,10 +1,26 @@
package bond
import (
"github.com/cosmos/cosmos-sdk/codec"
types "github.com/cosmos/cosmos-sdk/codec/types"
)
// 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(&MsgCreateBond{}, "bond/MsgCreateBond", nil)
// cdc.RegisterConcrete(&MsgRefillBond{}, "bond/MsgRefillBond", nil)
// cdc.RegisterConcrete(&MsgWithdrawBond{}, "bond/MsgWithdrawBond", nil)
// cdc.RegisterConcrete(&MsgCancelBond{}, "bond/MsgCancelBond", nil)
}
// RegisterInterfaces registers the interfaces types with the interface registry.
func RegisterInterfaces(registry types.InterfaceRegistry) {
// TODO: Implement
// registry.RegisterImplementations((*sdk.Msg)(nil),
// &MsgCreateBond{},
// &MsgRefillBond{},
// &MsgCancelBond{},
// &MsgWithdrawBond{},
// )
// msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
+27
View File
@@ -0,0 +1,27 @@
package bond
// DefaultGenesisState sets default evm genesis state with empty accounts and default params and
// chain config values.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
Bonds: []*Bond{},
}
}
func NewGenesisState(params Params, bonds []*Bond) *GenesisState {
return &GenesisState{
Params: params,
Bonds: bonds,
}
}
// Validate performs basic genesis state validation returning an error upon any
func (gs *GenesisState) Validate() error {
err := gs.Params.Validate()
if err != nil {
return err
}
return nil
}
+388
View File
@@ -0,0 +1,388 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cerc/bond/v1/genesis.proto
package bond
import (
fmt "fmt"
_ "github.com/cosmos/gogoproto/gogoproto"
proto "github.com/cosmos/gogoproto/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 bond module's genesis state.
type GenesisState struct {
// params defines all the parameters of the module.
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
// bonds defines all the bonds
Bonds []*Bond `protobuf:"bytes,2,rep,name=bonds,proto3" json:"bonds,omitempty" json:"bonds" yaml:"bonds"`
}
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_a5aeefaa96a86c9d, []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) GetBonds() []*Bond {
if m != nil {
return m.Bonds
}
return nil
}
func init() {
proto.RegisterType((*GenesisState)(nil), "cerc.bond.v1.GenesisState")
}
func init() { proto.RegisterFile("cerc/bond/v1/genesis.proto", fileDescriptor_a5aeefaa96a86c9d) }
var fileDescriptor_a5aeefaa96a86c9d = []byte{
// 241 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4a, 0x4e, 0x2d, 0x4a,
0xd6, 0x4f, 0xca, 0xcf, 0x4b, 0xd1, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c,
0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x01, 0xc9, 0xe9, 0x81, 0xe4, 0xf4, 0xca, 0x0c,
0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x12, 0xfa, 0x20, 0x16, 0x44, 0x8d, 0x94, 0x38, 0x8a,
0x7e, 0xb0, 0x5a, 0xb0, 0x84, 0x52, 0x37, 0x23, 0x17, 0x8f, 0x3b, 0xc4, 0xb8, 0xe0, 0x92, 0xc4,
0x92, 0x54, 0x21, 0x23, 0x2e, 0xb6, 0x82, 0xc4, 0xa2, 0xc4, 0xdc, 0x62, 0x09, 0x46, 0x05, 0x46,
0x0d, 0x6e, 0x23, 0x11, 0x3d, 0x64, 0xe3, 0xf5, 0x02, 0xc0, 0x72, 0x4e, 0x2c, 0x27, 0xee, 0xc9,
0x33, 0x04, 0x41, 0x55, 0x0a, 0xb9, 0x73, 0xb1, 0x82, 0xe4, 0x8b, 0x25, 0x98, 0x14, 0x98, 0x35,
0xb8, 0x8d, 0x84, 0x50, 0xb5, 0x38, 0xe5, 0xe7, 0xa5, 0x38, 0xc9, 0x7e, 0xba, 0x27, 0x2f, 0x99,
0x55, 0x9c, 0x9f, 0x67, 0xa5, 0x04, 0x56, 0xaa, 0xa4, 0x50, 0x99, 0x98, 0x9b, 0x03, 0xe3, 0x04,
0x41, 0xf4, 0x3b, 0xd9, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72,
0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x72,
0x7a, 0x66, 0x89, 0x5e, 0x59, 0x4a, 0x92, 0x5e, 0x49, 0xbe, 0x3e, 0xc8, 0x74, 0xdd, 0xcc, 0x7c,
0xfd, 0x9c, 0xc4, 0xe4, 0xfc, 0xbc, 0xcc, 0x64, 0xa3, 0x14, 0xfd, 0x0a, 0xb0, 0x97, 0x92, 0xd8,
0xc0, 0x7e, 0x32, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x34, 0x6b, 0x06, 0xdc, 0x2e, 0x01, 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.Bonds) > 0 {
for iNdEx := len(m.Bonds) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Bonds[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.Bonds) > 0 {
for _, e := range m.Bonds {
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 Bonds", 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.Bonds = append(m.Bonds, &Bond{})
if err := m.Bonds[len(m.Bonds)-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")
)
+25
View File
@@ -0,0 +1,25 @@
package keeper
import (
"git.vdb.to/cerc-io/laconic2d/x/bond"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// InitGenesis initializes the module state from a genesis state.
func (k *Keeper) InitGenesis(ctx sdk.Context, data *bond.GenesisState) error {
k.SetParams(ctx, data.Params)
for _, bond := range data.Bonds {
k.SaveBond(ctx, bond)
}
return nil
}
// ExportGenesis exports the module state to a genesis state.
func (k *Keeper) ExportGenesis(ctx sdk.Context) (*bond.GenesisState, error) {
params := k.GetParams(ctx)
bonds := k.ListBonds(ctx)
return &bond.GenesisState{Params: params, Bonds: bonds}, nil
}
+51 -9
View File
@@ -1,23 +1,65 @@
package keeper
import (
"cosmossdk.io/core/address"
storetypes "cosmossdk.io/store/types"
"git.vdb.to/cerc-io/laconic2d/x/bond"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// TODO: Add genesis.go?
type Keeper struct {
cdc codec.BinaryCodec
addressCodec address.Codec
// Store keys
storeKey storetypes.StoreKey
// TODO: state management
// Codecs
cdc codec.BinaryCodec
// TODO: Later: add bond usage keepers
// External keepers
// accountKeeper auth.AccountKeeper
// bankKeeper bank.Keeper
// Track bond usage in other cosmos-sdk modules (more like a usage tracker).
// usageKeepers []types.BondUsageKeeper
// paramSubspace paramtypes.Subspace
}
// NewKeeper creates a new Keeper instance
// TODO: Implement
func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec) Keeper {
return Keeper{}
// NewKeeper creates new instances of the bond Keeper
func NewKeeper(
cdc codec.BinaryCodec,
// accountKeeper auth.AccountKeeper,
// bankKeeper bank.Keeper,
// usageKeepers []types.BondUsageKeeper,
storeKey storetypes.StoreKey,
// ps paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
// if !ps.HasKeyTable() {
// ps = ps.WithKeyTable(types.ParamKeyTable())
// }
return Keeper{
// accountKeeper: accountKeeper,
// bankKeeper: bankKeeper,
storeKey: storeKey,
cdc: cdc,
// usageKeepers: usageKeepers,
// paramSubspace: ps,
}
}
// TODO: Add keeper methods
// SaveBond - saves a bond to the store.
func (k Keeper) SaveBond(ctx sdk.Context, bond *bond.Bond) {
// TODO: Implement
}
// ListBonds - get all bonds.
func (k Keeper) ListBonds(ctx sdk.Context) []*bond.Bond {
// TODO: Implement
var bonds []*bond.Bond
return bonds
}
+23
View File
@@ -0,0 +1,23 @@
package keeper
import (
"git.vdb.to/cerc-io/laconic2d/x/bond"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// GetMaxBondAmount max bond amount
func (k Keeper) GetMaxBondAmount(ctx sdk.Context) (res sdk.Coin) {
// TODO: Implement
return sdk.Coin{}
}
// GetParams - Get all parameter as types.Params.
func (k Keeper) GetParams(ctx sdk.Context) (params bond.Params) {
getMaxBondAmount := k.GetMaxBondAmount(ctx)
return bond.Params{MaxBondAmount: getMaxBondAmount}
}
// SetParams - set the params.
func (k Keeper) SetParams(ctx sdk.Context, params bond.Params) {
// TODO: Implement
}
+7 -2
View File
@@ -1,5 +1,10 @@
package bond
const ModuleName = "bond"
const (
ModuleName = "bond"
// TODO: Add required keys
// StoreKey is the string store representation
StoreKey = ModuleName
// TODO: Add required keys
)
+15
View File
@@ -1 +1,16 @@
package module
import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/autocli"
)
var _ autocli.HasAutoCLIConfig = AppModule{}
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
return &autocliv1.ModuleOptions{
Query: nil,
Tx: nil,
}
}
+47
View File
@@ -1 +1,48 @@
package module
import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
modulev1 "git.vdb.to/cerc-io/laconic2d/api/cerc/bond/module/v1"
"git.vdb.to/cerc-io/laconic2d/x/bond/keeper"
)
var _ appmodule.AppModule = AppModule{}
// IsOnePerModuleType implements the depinject.OnePerModuleType interface.
func (am AppModule) IsOnePerModuleType() {}
// IsAppModule implements the appmodule.AppModule interface.
func (am AppModule) IsAppModule() {}
func init() {
appmodule.Register(
&modulev1.Module{},
appmodule.Provide(ProvideModule),
)
}
type ModuleInputs struct {
depinject.In
Key *storetypes.KVStoreKey
Cdc codec.Codec
}
type ModuleOutputs struct {
depinject.Out
Keeper keeper.Keeper
Module appmodule.AppModule
}
func ProvideModule(in ModuleInputs) ModuleOutputs {
k := keeper.NewKeeper(in.Cdc, in.Key)
m := NewAppModule(in.Cdc, k)
return ModuleOutputs{Module: m, Keeper: k}
}
+114 -1
View File
@@ -1,4 +1,117 @@
package module
type Module struct {
import (
"encoding/json"
"fmt"
"cosmossdk.io/core/appmodule"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"git.vdb.to/cerc-io/laconic2d/x/bond"
"git.vdb.to/cerc-io/laconic2d/x/bond/keeper"
)
// TODO: Port remaining AppModule methods
var (
_ module.AppModuleBasic = AppModule{}
_ appmodule.AppModule = AppModule{}
_ module.HasGenesis = AppModule{}
_ module.HasServices = AppModule{}
)
// ConsensusVersion defines the current module consensus version
const ConsensusVersion = 1
type AppModule struct {
cdc codec.Codec
keeper keeper.Keeper
}
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper) AppModule {
return AppModule{
cdc: cdc,
keeper: keeper,
}
}
func NewAppModuleBasic(m AppModule) module.AppModuleBasic {
return module.CoreAppModuleBasicAdaptor(m.Name(), m)
}
// module.AppModuleBasic
// Name returns the bond module's name.
func (AppModule) Name() string { return bond.ModuleName }
// RegisterLegacyAminoCodec registers the bond module's types on the LegacyAmino codec.
// New modules do not need to support Amino.
func (AppModule) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
bond.RegisterLegacyAminoCodec(cdc)
}
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the bond module.
func (AppModule) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *gwruntime.ServeMux) {
// if err := bond.RegisterQueryHandlerClient(context.Background(), mux, bond.NewQueryClient(clientCtx)); err != nil {
// panic(err)
// }
}
// RegisterInterfaces registers interfaces and implementations of the bond module.
func (AppModule) RegisterInterfaces(registry codectypes.InterfaceRegistry) {
bond.RegisterInterfaces(registry)
}
// module.HasGenesis
// DefaultGenesis returns default genesis state as raw bytes for the module.
func (AppModule) DefaultGenesis(jsonCodec codec.JSONCodec) json.RawMessage {
return jsonCodec.MustMarshalJSON(bond.DefaultGenesisState())
}
// ValidateGenesis performs genesis state validation for the module.
func (AppModule) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, message json.RawMessage) error {
var data bond.GenesisState
if err := cdc.UnmarshalJSON(message, &data); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", bond.ModuleName, err)
}
return data.Validate()
}
// InitGenesis performs genesis initialization for the checkers module.
// It returns no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
var genesisState bond.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
if err := am.keeper.InitGenesis(ctx, &genesisState); err != nil {
panic(fmt.Sprintf("failed to initialize %s genesis state: %v", bond.ModuleName, err))
}
}
// ExportGenesis returns the exported genesis state as raw bytes for the circuit
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
gs, err := am.keeper.ExportGenesis(ctx)
if err != nil {
panic(fmt.Sprintf("failed to export %s genesis state: %v", bond.ModuleName, err))
}
return cdc.MustMarshalJSON(gs)
}
// module.HasServices
func (am AppModule) RegisterServices(cfg module.Configurator) {
// Register servers
// bond.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
// bond.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
}
+55 -1
View File
@@ -1,3 +1,57 @@
package bond
// TODO: Add required params types
import (
"errors"
fmt "fmt"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)
var _ paramtypes.ParamSet = &Params{}
// Default parameter values.
var DefaultMaxBondAmountTokens = sdkmath.NewInt(100000000000)
// Parameter keys
var ParamStoreKeyMaxBondAmount = []byte("MaxBondAmount")
func NewParams(maxBondAmount sdk.Coin) Params {
return Params{MaxBondAmount: maxBondAmount}
}
// DefaultParams returns default module parameters
// ExtraEIPs is empty to prevent overriding the latest hard fork instruction set
func DefaultParams() Params {
return NewParams(sdk.NewCoin(sdk.DefaultBondDenom, DefaultMaxBondAmountTokens))
}
// ParamSetPairs returns the parameter set pairs.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMaxBondAmount, &p.MaxBondAmount, validateMaxBondAmount),
}
}
func validateMaxBondAmount(i interface{}) error {
v, ok := i.(sdk.Coin)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.Amount.IsNegative() {
return errors.New("max bond amount must be positive")
}
return nil
}
// Validate checks that the parameters have valid values
func (p Params) Validate() error {
if err := validateMaxBondAmount(p.MaxBondAmount); err != nil {
return err
}
return nil
}