forked from cerc-io/laconicd
Add commands to create and get auctions (#2)
To be added in an upcoming PR: - commands to commit, reveal and get bids Reviewed-on: deep-stack/laconic2d#2 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
parent
328c06d919
commit
cb1f723475
@ -13,57 +13,6 @@ import (
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
var _ protoreflect.List = (*_GenesisState_2_list)(nil)
|
||||
|
||||
type _GenesisState_2_list struct {
|
||||
list *[]*Auction
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) Len() int {
|
||||
if x.list == nil {
|
||||
return 0
|
||||
}
|
||||
return len(*x.list)
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) Get(i int) protoreflect.Value {
|
||||
return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect())
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) Set(i int, value protoreflect.Value) {
|
||||
valueUnwrapped := value.Message()
|
||||
concreteValue := valueUnwrapped.Interface().(*Auction)
|
||||
(*x.list)[i] = concreteValue
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) Append(value protoreflect.Value) {
|
||||
valueUnwrapped := value.Message()
|
||||
concreteValue := valueUnwrapped.Interface().(*Auction)
|
||||
*x.list = append(*x.list, concreteValue)
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) AppendMutable() protoreflect.Value {
|
||||
v := new(Auction)
|
||||
*x.list = append(*x.list, v)
|
||||
return protoreflect.ValueOfMessage(v.ProtoReflect())
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) Truncate(n int) {
|
||||
for i := n; i < len(*x.list); i++ {
|
||||
(*x.list)[i] = nil
|
||||
}
|
||||
*x.list = (*x.list)[:n]
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) NewElement() protoreflect.Value {
|
||||
v := new(Auction)
|
||||
return protoreflect.ValueOfMessage(v.ProtoReflect())
|
||||
}
|
||||
|
||||
func (x *_GenesisState_2_list) IsValid() bool {
|
||||
return x.list != nil
|
||||
}
|
||||
|
||||
var (
|
||||
md_GenesisState protoreflect.MessageDescriptor
|
||||
fd_GenesisState_params protoreflect.FieldDescriptor
|
||||
@ -148,8 +97,8 @@ func (x *fastReflection_GenesisState) Range(f func(protoreflect.FieldDescriptor,
|
||||
return
|
||||
}
|
||||
}
|
||||
if len(x.Auctions) != 0 {
|
||||
value := protoreflect.ValueOfList(&_GenesisState_2_list{list: &x.Auctions})
|
||||
if x.Auctions != nil {
|
||||
value := protoreflect.ValueOfMessage(x.Auctions.ProtoReflect())
|
||||
if !f(fd_GenesisState_auctions, value) {
|
||||
return
|
||||
}
|
||||
@ -172,7 +121,7 @@ func (x *fastReflection_GenesisState) Has(fd protoreflect.FieldDescriptor) bool
|
||||
case "cerc.auction.v1.GenesisState.params":
|
||||
return x.Params != nil
|
||||
case "cerc.auction.v1.GenesisState.auctions":
|
||||
return len(x.Auctions) != 0
|
||||
return x.Auctions != nil
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cerc.auction.v1.GenesisState"))
|
||||
@ -213,11 +162,8 @@ func (x *fastReflection_GenesisState) Get(descriptor protoreflect.FieldDescripto
|
||||
value := x.Params
|
||||
return protoreflect.ValueOfMessage(value.ProtoReflect())
|
||||
case "cerc.auction.v1.GenesisState.auctions":
|
||||
if len(x.Auctions) == 0 {
|
||||
return protoreflect.ValueOfList(&_GenesisState_2_list{})
|
||||
}
|
||||
listValue := &_GenesisState_2_list{list: &x.Auctions}
|
||||
return protoreflect.ValueOfList(listValue)
|
||||
value := x.Auctions
|
||||
return protoreflect.ValueOfMessage(value.ProtoReflect())
|
||||
default:
|
||||
if descriptor.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cerc.auction.v1.GenesisState"))
|
||||
@ -241,9 +187,7 @@ func (x *fastReflection_GenesisState) Set(fd protoreflect.FieldDescriptor, value
|
||||
case "cerc.auction.v1.GenesisState.params":
|
||||
x.Params = value.Message().Interface().(*Params)
|
||||
case "cerc.auction.v1.GenesisState.auctions":
|
||||
lv := value.List()
|
||||
clv := lv.(*_GenesisState_2_list)
|
||||
x.Auctions = *clv.list
|
||||
x.Auctions = value.Message().Interface().(*Auctions)
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cerc.auction.v1.GenesisState"))
|
||||
@ -271,10 +215,9 @@ func (x *fastReflection_GenesisState) Mutable(fd protoreflect.FieldDescriptor) p
|
||||
return protoreflect.ValueOfMessage(x.Params.ProtoReflect())
|
||||
case "cerc.auction.v1.GenesisState.auctions":
|
||||
if x.Auctions == nil {
|
||||
x.Auctions = []*Auction{}
|
||||
x.Auctions = new(Auctions)
|
||||
}
|
||||
value := &_GenesisState_2_list{list: &x.Auctions}
|
||||
return protoreflect.ValueOfList(value)
|
||||
return protoreflect.ValueOfMessage(x.Auctions.ProtoReflect())
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cerc.auction.v1.GenesisState"))
|
||||
@ -292,8 +235,8 @@ func (x *fastReflection_GenesisState) NewField(fd protoreflect.FieldDescriptor)
|
||||
m := new(Params)
|
||||
return protoreflect.ValueOfMessage(m.ProtoReflect())
|
||||
case "cerc.auction.v1.GenesisState.auctions":
|
||||
list := []*Auction{}
|
||||
return protoreflect.ValueOfList(&_GenesisState_2_list{list: &list})
|
||||
m := new(Auctions)
|
||||
return protoreflect.ValueOfMessage(m.ProtoReflect())
|
||||
default:
|
||||
if fd.IsExtension() {
|
||||
panic(fmt.Errorf("proto3 declared messages do not support extensions: cerc.auction.v1.GenesisState"))
|
||||
@ -367,12 +310,10 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods {
|
||||
l = options.Size(x.Params)
|
||||
n += 1 + l + runtime.Sov(uint64(l))
|
||||
}
|
||||
if len(x.Auctions) > 0 {
|
||||
for _, e := range x.Auctions {
|
||||
l = options.Size(e)
|
||||
if x.Auctions != nil {
|
||||
l = options.Size(x.Auctions)
|
||||
n += 1 + l + runtime.Sov(uint64(l))
|
||||
}
|
||||
}
|
||||
if x.unknownFields != nil {
|
||||
n += len(x.unknownFields)
|
||||
}
|
||||
@ -402,9 +343,8 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods {
|
||||
i -= len(x.unknownFields)
|
||||
copy(dAtA[i:], x.unknownFields)
|
||||
}
|
||||
if len(x.Auctions) > 0 {
|
||||
for iNdEx := len(x.Auctions) - 1; iNdEx >= 0; iNdEx-- {
|
||||
encoded, err := options.Marshal(x.Auctions[iNdEx])
|
||||
if x.Auctions != nil {
|
||||
encoded, err := options.Marshal(x.Auctions)
|
||||
if err != nil {
|
||||
return protoiface.MarshalOutput{
|
||||
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
|
||||
@ -417,7 +357,6 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods {
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
if x.Params != nil {
|
||||
encoded, err := options.Marshal(x.Params)
|
||||
if err != nil {
|
||||
@ -546,8 +485,10 @@ func (x *fastReflection_GenesisState) ProtoMethods() *protoiface.Methods {
|
||||
if postIndex > l {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
|
||||
}
|
||||
x.Auctions = append(x.Auctions, &Auction{})
|
||||
if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Auctions[len(x.Auctions)-1]); err != nil {
|
||||
if x.Auctions == nil {
|
||||
x.Auctions = &Auctions{}
|
||||
}
|
||||
if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Auctions); err != nil {
|
||||
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
@ -606,7 +547,7 @@ type GenesisState struct {
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"`
|
||||
Auctions []*Auction `protobuf:"bytes,2,rep,name=auctions,proto3" json:"auctions,omitempty"`
|
||||
Auctions *Auctions `protobuf:"bytes,2,opt,name=auctions,proto3" json:"auctions,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GenesisState) Reset() {
|
||||
@ -636,7 +577,7 @@ func (x *GenesisState) GetParams() *Params {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *GenesisState) GetAuctions() []*Auction {
|
||||
func (x *GenesisState) GetAuctions() *Auctions {
|
||||
if x != nil {
|
||||
return x.Auctions
|
||||
}
|
||||
@ -652,29 +593,30 @@ var file_cerc_auction_v1_genesis_proto_rawDesc = []byte{
|
||||
0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1d, 0x63, 0x65, 0x72, 0x63, 0x2f, 0x61, 0x75, 0x63,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa0, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69,
|
||||
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa1, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69,
|
||||
0x73, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x35, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x61, 0x75,
|
||||
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42,
|
||||
0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x59, 0x0a,
|
||||
0x08, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
||||
0x18, 0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76,
|
||||
0x31, 0x2e, 0x41, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x23, 0xf2, 0xde, 0x1f, 0x1f, 0x6a,
|
||||
0x73, 0x6f, 0x6e, 0x3a, 0x22, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x20, 0x79,
|
||||
0x61, 0x6d, 0x6c, 0x3a, 0x22, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x52, 0x08,
|
||||
0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0xbd, 0x01, 0x0a, 0x13, 0x63, 0x6f, 0x6d,
|
||||
0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76, 0x31,
|
||||
0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01,
|
||||
0x5a, 0x3a, 0x67, 0x69, 0x74, 0x2e, 0x76, 0x64, 0x62, 0x2e, 0x74, 0x6f, 0x2f, 0x63, 0x65, 0x72,
|
||||
0x63, 0x2d, 0x69, 0x6f, 0x2f, 0x6c, 0x61, 0x63, 0x6f, 0x6e, 0x69, 0x63, 0x32, 0x64, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x2f, 0x63, 0x65, 0x72, 0x63, 0x2f, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2f,
|
||||
0x76, 0x31, 0x3b, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43,
|
||||
0x41, 0x58, 0xaa, 0x02, 0x0f, 0x43, 0x65, 0x72, 0x63, 0x2e, 0x41, 0x75, 0x63, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0f, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x41, 0x75, 0x63, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1b, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x41, 0x75,
|
||||
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
|
||||
0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x43, 0x65, 0x72, 0x63, 0x3a, 0x3a, 0x41, 0x75, 0x63,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x5a, 0x0a,
|
||||
0x08, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x19, 0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76,
|
||||
0x31, 0x2e, 0x41, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x23, 0xf2, 0xde, 0x1f, 0x1f,
|
||||
0x6a, 0x73, 0x6f, 0x6e, 0x3a, 0x22, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x20,
|
||||
0x79, 0x61, 0x6d, 0x6c, 0x3a, 0x22, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x52,
|
||||
0x08, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0xbd, 0x01, 0x0a, 0x13, 0x63, 0x6f,
|
||||
0x6d, 0x2e, 0x63, 0x65, 0x72, 0x63, 0x2e, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x76,
|
||||
0x31, 0x42, 0x0c, 0x47, 0x65, 0x6e, 0x65, 0x73, 0x69, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50,
|
||||
0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x2e, 0x76, 0x64, 0x62, 0x2e, 0x74, 0x6f, 0x2f, 0x63, 0x65,
|
||||
0x72, 0x63, 0x2d, 0x69, 0x6f, 0x2f, 0x6c, 0x61, 0x63, 0x6f, 0x6e, 0x69, 0x63, 0x32, 0x64, 0x2f,
|
||||
0x61, 0x70, 0x69, 0x2f, 0x63, 0x65, 0x72, 0x63, 0x2f, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x2f, 0x76, 0x31, 0x3b, 0x61, 0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x76, 0x31, 0xa2, 0x02, 0x03,
|
||||
0x43, 0x41, 0x58, 0xaa, 0x02, 0x0f, 0x43, 0x65, 0x72, 0x63, 0x2e, 0x41, 0x75, 0x63, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0f, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x41, 0x75, 0x63,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x1b, 0x43, 0x65, 0x72, 0x63, 0x5c, 0x41,
|
||||
0x75, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74,
|
||||
0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x11, 0x43, 0x65, 0x72, 0x63, 0x3a, 0x3a, 0x41, 0x75,
|
||||
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -693,11 +635,11 @@ var file_cerc_auction_v1_genesis_proto_msgTypes = make([]protoimpl.MessageInfo,
|
||||
var file_cerc_auction_v1_genesis_proto_goTypes = []interface{}{
|
||||
(*GenesisState)(nil), // 0: cerc.auction.v1.GenesisState
|
||||
(*Params)(nil), // 1: cerc.auction.v1.Params
|
||||
(*Auction)(nil), // 2: cerc.auction.v1.Auction
|
||||
(*Auctions)(nil), // 2: cerc.auction.v1.Auctions
|
||||
}
|
||||
var file_cerc_auction_v1_genesis_proto_depIdxs = []int32{
|
||||
1, // 0: cerc.auction.v1.GenesisState.params:type_name -> cerc.auction.v1.Params
|
||||
2, // 1: cerc.auction.v1.GenesisState.auctions:type_name -> cerc.auction.v1.Auction
|
||||
2, // 1: cerc.auction.v1.GenesisState.auctions:type_name -> cerc.auction.v1.Auctions
|
||||
2, // [2:2] is the sub-list for method output_type
|
||||
2, // [2:2] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
|
@ -10,5 +10,5 @@ option go_package = "git.vdb.to/cerc-io/laconic2d/x/auction";
|
||||
// GenesisState defines the genesis state of the auction module
|
||||
message GenesisState {
|
||||
Params params = 1 [(gogoproto.nullable) = false];
|
||||
repeated Auction auctions = 2 [(gogoproto.moretags) = "json:\"auctions\" yaml:\"auctions\""];
|
||||
Auctions auctions = 2 [(gogoproto.moretags) = "json:\"auctions\" yaml:\"auctions\""];
|
||||
}
|
||||
|
@ -82,7 +82,10 @@ message QueryGetBondsByOwnerRequest {
|
||||
|
||||
// QueryGetBondsByOwnerResponse is response type for Query/GetBondsByOwner RPC Method
|
||||
message QueryGetBondsByOwnerResponse {
|
||||
repeated Bond bonds = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "json:\"bonds\" yaml:\"bonds\""];
|
||||
repeated Bond bonds = 1 [
|
||||
(gogoproto.nullable) = false,
|
||||
(gogoproto.moretags) = "json:\"bonds\" yaml:\"bonds\""
|
||||
];
|
||||
|
||||
// pagination defines the pagination in the response.
|
||||
cosmos.base.query.v1beta1.PageResponse pagination = 2;
|
||||
|
19
x/auction/events.go
Normal file
19
x/auction/events.go
Normal file
@ -0,0 +1,19 @@
|
||||
package auction
|
||||
|
||||
const (
|
||||
EventTypeCreateAuction = "create-auction"
|
||||
EventTypeCommitBid = "commit-bid"
|
||||
EventTypeRevealBid = "reveal-bid"
|
||||
|
||||
AttributeKeyCommitsDuration = "commits-duration"
|
||||
AttributeKeyRevealsDuration = "reveals-duration"
|
||||
AttributeKeyCommitFee = "commit-fee"
|
||||
AttributeKeyRevealFee = "reveal-fee"
|
||||
AttributeKeyMinimumBid = "minimum-bid"
|
||||
AttributeKeySigner = "signer"
|
||||
AttributeKeyAuctionID = "auction-id"
|
||||
AttributeKeyCommitHash = "commit-hash"
|
||||
AttributeKeyReveal = "reveal"
|
||||
|
||||
AttributeValueCategory = ModuleName
|
||||
)
|
@ -3,14 +3,14 @@ package auction
|
||||
func DefaultGenesisState() *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: DefaultParams(),
|
||||
Auctions: []*Auction{},
|
||||
Auctions: &Auctions{Auctions: []Auction{}},
|
||||
}
|
||||
}
|
||||
|
||||
func NewGenesisState(params Params, auctions []*Auction) *GenesisState {
|
||||
func NewGenesisState(params Params, auctions []Auction) *GenesisState {
|
||||
return &GenesisState{
|
||||
Params: params,
|
||||
Auctions: auctions,
|
||||
Auctions: &Auctions{Auctions: auctions},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
// GenesisState defines the genesis state of the auction module
|
||||
type GenesisState struct {
|
||||
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
|
||||
Auctions []*Auction `protobuf:"bytes,2,rep,name=auctions,proto3" json:"auctions,omitempty" json:"auctions" yaml:"auctions"`
|
||||
Auctions *Auctions `protobuf:"bytes,2,opt,name=auctions,proto3" json:"auctions,omitempty" json:"auctions" yaml:"auctions"`
|
||||
}
|
||||
|
||||
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
||||
@ -69,7 +69,7 @@ func (m *GenesisState) GetParams() Params {
|
||||
return Params{}
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetAuctions() []*Auction {
|
||||
func (m *GenesisState) GetAuctions() *Auctions {
|
||||
if m != nil {
|
||||
return m.Auctions
|
||||
}
|
||||
@ -83,23 +83,22 @@ func init() {
|
||||
func init() { proto.RegisterFile("cerc/auction/v1/genesis.proto", fileDescriptor_7571460e3af58ef5) }
|
||||
|
||||
var fileDescriptor_7571460e3af58ef5 = []byte{
|
||||
// 242 bytes of a gzipped FileDescriptorProto
|
||||
// 240 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4d, 0x4e, 0x2d, 0x4a,
|
||||
0xd6, 0x4f, 0x2c, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b,
|
||||
0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x07, 0x49, 0xeb, 0x41, 0xa5,
|
||||
0xf5, 0xca, 0x0c, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x72, 0xfa, 0x20, 0x16, 0x44, 0x99,
|
||||
0x14, 0x86, 0x29, 0x30, 0x1d, 0x60, 0x69, 0xa5, 0x05, 0x8c, 0x5c, 0x3c, 0xee, 0x10, 0x73, 0x83,
|
||||
0x14, 0x86, 0x29, 0x30, 0x1d, 0x60, 0x69, 0xa5, 0x85, 0x8c, 0x5c, 0x3c, 0xee, 0x10, 0x73, 0x83,
|
||||
0x4b, 0x12, 0x4b, 0x52, 0x85, 0x4c, 0xb9, 0xd8, 0x0a, 0x12, 0x8b, 0x12, 0x73, 0x8b, 0x25, 0x18,
|
||||
0x15, 0x18, 0x35, 0xb8, 0x8d, 0xc4, 0xf5, 0xd0, 0xec, 0xd1, 0x0b, 0x00, 0x4b, 0x3b, 0xb1, 0x9c,
|
||||
0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, 0x2c, 0x14, 0xc9, 0xc5, 0x01, 0x55, 0x52, 0x2c, 0xc1, 0xa4,
|
||||
0xc0, 0xac, 0xc1, 0x6d, 0x24, 0x81, 0xa1, 0xd1, 0x11, 0xc2, 0x74, 0x52, 0xfe, 0x74, 0x4f, 0x5e,
|
||||
0x3e, 0xab, 0x38, 0x3f, 0xcf, 0x4a, 0x09, 0xa6, 0x47, 0x49, 0xa1, 0x32, 0x31, 0x37, 0x07, 0x89,
|
||||
0x1f, 0x04, 0x37, 0xce, 0xc9, 0xe1, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c,
|
||||
0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2,
|
||||
0xd4, 0xd2, 0x33, 0x4b, 0xf4, 0xca, 0x52, 0x92, 0xf4, 0x4a, 0xf2, 0xf5, 0x41, 0x96, 0xe9, 0x66,
|
||||
0xe6, 0xeb, 0xe7, 0x24, 0x26, 0xe7, 0xe7, 0x65, 0x26, 0x1b, 0xa5, 0xe8, 0x57, 0xc0, 0xbc, 0x9a,
|
||||
0xc4, 0x06, 0xf6, 0xab, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x69, 0xca, 0xb3, 0x2b, 0x52, 0x01,
|
||||
0x00, 0x00,
|
||||
0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, 0x2c, 0x14, 0xc5, 0xc5, 0x01, 0x55, 0x52, 0x2c, 0xc1, 0x04,
|
||||
0xd6, 0x28, 0x89, 0xa1, 0xd1, 0x11, 0xaa, 0xc0, 0x49, 0xf9, 0xd3, 0x3d, 0x79, 0xf9, 0xac, 0xe2,
|
||||
0xfc, 0x3c, 0x2b, 0x25, 0x98, 0x26, 0x25, 0x85, 0xca, 0xc4, 0xdc, 0x1c, 0x24, 0x7e, 0x10, 0xdc,
|
||||
0x3c, 0x27, 0x87, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71,
|
||||
0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x52, 0x4b, 0xcf,
|
||||
0x2c, 0xd1, 0x2b, 0x4b, 0x49, 0xd2, 0x2b, 0xc9, 0xd7, 0x07, 0xd9, 0xa6, 0x9b, 0x99, 0xaf, 0x9f,
|
||||
0x93, 0x98, 0x9c, 0x9f, 0x97, 0x99, 0x6c, 0x94, 0xa2, 0x5f, 0x01, 0xf3, 0x6b, 0x12, 0x1b, 0xd8,
|
||||
0xb3, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1e, 0x3c, 0x5f, 0xc5, 0x53, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
||||
@ -122,10 +121,9 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.Auctions) > 0 {
|
||||
for iNdEx := len(m.Auctions) - 1; iNdEx >= 0; iNdEx-- {
|
||||
if m.Auctions != nil {
|
||||
{
|
||||
size, err := m.Auctions[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
size, err := m.Auctions.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@ -135,7 +133,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
}
|
||||
}
|
||||
{
|
||||
size, err := m.Params.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
@ -168,12 +165,10 @@ func (m *GenesisState) Size() (n int) {
|
||||
_ = l
|
||||
l = m.Params.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
if len(m.Auctions) > 0 {
|
||||
for _, e := range m.Auctions {
|
||||
l = e.Size()
|
||||
if m.Auctions != nil {
|
||||
l = m.Auctions.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
@ -274,8 +269,10 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Auctions = append(m.Auctions, &Auction{})
|
||||
if err := m.Auctions[len(m.Auctions)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
if m.Auctions == nil {
|
||||
m.Auctions = &Auctions{}
|
||||
}
|
||||
if err := m.Auctions.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
|
@ -1,41 +1,40 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// InitGenesis initializes the module state from a genesis state.
|
||||
func (k *Keeper) InitGenesis(ctx context.Context, data *auction.GenesisState) error {
|
||||
func (k *Keeper) InitGenesis(ctx sdk.Context, data *auction.GenesisState) error {
|
||||
if err := k.Params.Set(ctx, data.Params); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Save auctions in store.
|
||||
// for _, auction := range data.Auctions {
|
||||
// if err := k.Auctions.Set(ctx, auction.Id, *auction); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
for _, auction := range data.Auctions.Auctions {
|
||||
if err := k.Auctions.Set(ctx, auction.Id, auction); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportGenesis exports the module state to a genesis state.
|
||||
func (k *Keeper) ExportGenesis(ctx context.Context) (*auction.GenesisState, error) {
|
||||
func (k *Keeper) ExportGenesis(ctx sdk.Context) (*auction.GenesisState, error) {
|
||||
params, err := k.Params.Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// auctions, err := k.ListAuctions(ctx)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
auctions, err := k.ListAuctions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auction.GenesisState{
|
||||
Params: params,
|
||||
// Auctions: auctions,
|
||||
Auctions: &auction.Auctions{Auctions: auctions},
|
||||
}, nil
|
||||
}
|
||||
|
@ -1,16 +1,44 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/collections/indexes"
|
||||
storetypes "cosmossdk.io/core/store"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
|
||||
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
|
||||
|
||||
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
)
|
||||
|
||||
type AuctionsIndexes struct {
|
||||
Owner *indexes.Multi[string, string, auctiontypes.Auction]
|
||||
}
|
||||
|
||||
func (a AuctionsIndexes) IndexesList() []collections.Index[string, auctiontypes.Auction] {
|
||||
return []collections.Index[string, auctiontypes.Auction]{a.Owner}
|
||||
}
|
||||
|
||||
func newAuctionIndexes(sb *collections.SchemaBuilder) AuctionsIndexes {
|
||||
return AuctionsIndexes{
|
||||
Owner: indexes.NewMulti(
|
||||
sb, auctiontypes.AuctionOwnerIndexPrefix, "auctions_by_owner",
|
||||
collections.StringKey, collections.StringKey,
|
||||
func(_ string, v auctiontypes.Auction) (string, error) {
|
||||
return v.OwnerAddress, nil
|
||||
},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add required methods
|
||||
|
||||
type Keeper struct {
|
||||
// Codecs
|
||||
cdc codec.BinaryCodec
|
||||
@ -25,8 +53,7 @@ type Keeper struct {
|
||||
// state management
|
||||
Schema collections.Schema
|
||||
Params collections.Item[auctiontypes.Params]
|
||||
// TODO
|
||||
// Auctions ...
|
||||
Auctions *collections.IndexedMap[string, auctiontypes.Auction, AuctionsIndexes]
|
||||
}
|
||||
|
||||
// NewKeeper creates a new Keeper instance
|
||||
@ -42,7 +69,8 @@ func NewKeeper(
|
||||
accountKeeper: accountKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
Params: collections.NewItem(sb, auctiontypes.ParamsKeyPrefix, "params", codec.CollValue[auctiontypes.Params](cdc)),
|
||||
// Auctions: ...
|
||||
Auctions: collections.NewIndexedMap(sb, auctiontypes.AuctionsKeyPrefix, "auctions", collections.StringKey, codec.CollValue[auctiontypes.Auction](cdc), newAuctionIndexes(sb)),
|
||||
// usageKeepers: usageKeepers,
|
||||
}
|
||||
|
||||
schema, err := sb.Build()
|
||||
@ -58,3 +86,124 @@ func NewKeeper(
|
||||
// func (k *Keeper) SetUsageKeepers(usageKeepers []types.AuctionUsageKeeper) {
|
||||
// k.usageKeepers = usageKeepers
|
||||
// }
|
||||
|
||||
// SaveAuction - saves a auction to the store.
|
||||
func (k Keeper) SaveAuction(ctx sdk.Context, auction *auctiontypes.Auction) error {
|
||||
return k.Auctions.Set(ctx, auction.Id, *auction)
|
||||
|
||||
// // Notify interested parties.
|
||||
// for _, keeper := range k.usageKeepers {
|
||||
// keeper.OnAuction(ctx, auction.Id)
|
||||
// }
|
||||
// return nil
|
||||
}
|
||||
|
||||
// ListAuctions - get all auctions.
|
||||
func (k Keeper) ListAuctions(ctx sdk.Context) ([]auctiontypes.Auction, error) {
|
||||
var auctions []auctiontypes.Auction
|
||||
|
||||
iter, err := k.Auctions.Iterate(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for ; iter.Valid(); iter.Next() {
|
||||
auction, err := iter.Value()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
auctions = append(auctions, auction)
|
||||
}
|
||||
|
||||
return auctions, nil
|
||||
}
|
||||
|
||||
// GetAuction - gets a record from the store.
|
||||
func (k Keeper) GetAuctionById(ctx sdk.Context, id string) (auctiontypes.Auction, error) {
|
||||
auction, err := k.Auctions.Get(ctx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, collections.ErrNotFound) {
|
||||
return auctiontypes.Auction{}, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
|
||||
}
|
||||
return auctiontypes.Auction{}, err
|
||||
}
|
||||
|
||||
return auction, nil
|
||||
}
|
||||
|
||||
func (k Keeper) GetAuctionsByOwner(ctx sdk.Context, owner string) ([]auctiontypes.Auction, error) {
|
||||
iter, err := k.Auctions.Indexes.Owner.MatchExact(ctx, owner)
|
||||
if err != nil {
|
||||
return []auctiontypes.Auction{}, err
|
||||
}
|
||||
|
||||
return indexes.CollectValues(ctx, k.Auctions, iter)
|
||||
}
|
||||
|
||||
// CreateAuction creates a new auction.
|
||||
func (k Keeper) CreateAuction(ctx sdk.Context, msg auctiontypes.MsgCreateAuction) (*auctiontypes.Auction, error) {
|
||||
// TODO: Setup checks
|
||||
// Might be called from another module directly, always validate.
|
||||
// err := msg.ValidateBasic()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Generate auction Id.
|
||||
account := k.accountKeeper.GetAccount(ctx, signerAddress)
|
||||
if account == nil {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
|
||||
}
|
||||
|
||||
auctionId := auctiontypes.AuctionId{
|
||||
Address: signerAddress,
|
||||
AccNum: account.GetAccountNumber(),
|
||||
Sequence: account.GetSequence(),
|
||||
}.Generate()
|
||||
|
||||
// Compute timestamps.
|
||||
now := ctx.BlockTime()
|
||||
commitsEndTime := now.Add(msg.CommitsDuration)
|
||||
revealsEndTime := now.Add(msg.CommitsDuration + msg.RevealsDuration)
|
||||
|
||||
auction := auctiontypes.Auction{
|
||||
Id: auctionId,
|
||||
Status: auctiontypes.AuctionStatusCommitPhase,
|
||||
OwnerAddress: signerAddress.String(),
|
||||
CreateTime: now,
|
||||
CommitsEndTime: commitsEndTime,
|
||||
RevealsEndTime: revealsEndTime,
|
||||
CommitFee: msg.CommitFee,
|
||||
RevealFee: msg.RevealFee,
|
||||
MinimumBid: msg.MinimumBid,
|
||||
}
|
||||
|
||||
// Save auction in store.
|
||||
k.SaveAuction(ctx, &auction)
|
||||
|
||||
return &auction, nil
|
||||
}
|
||||
|
||||
func (k Keeper) CommitBid(ctx sdk.Context, msg auctiontypes.MsgCommitBid) (*auctiontypes.Bid, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (k Keeper) RevealBid(ctx sdk.Context, msg auctiontypes.MsgRevealBid) (*auctiontypes.Auction, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetParams gets the auction module's parameters.
|
||||
func (k Keeper) GetParams(ctx sdk.Context) (*auctiontypes.Params, error) {
|
||||
params, err := k.Params.Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ¶ms, nil
|
||||
}
|
||||
|
@ -1,14 +1,112 @@
|
||||
package keeper
|
||||
|
||||
// TODO: Add required read methods
|
||||
import (
|
||||
"context"
|
||||
|
||||
// var _ auctiontypes.MsgServer = msgServer{}
|
||||
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
var _ auctiontypes.MsgServer = msgServer{}
|
||||
|
||||
type msgServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
||||
// func NewMsgServerImpl(keeper Keeper) auctiontypes.MsgServer {
|
||||
// return &msgServer{k: keeper}
|
||||
// }
|
||||
func NewMsgServerImpl(keeper Keeper) auctiontypes.MsgServer {
|
||||
return &msgServer{k: keeper}
|
||||
}
|
||||
|
||||
func (ms msgServer) CreateAuction(c context.Context, msg *auctiontypes.MsgCreateAuction) (*auctiontypes.MsgCreateAuctionResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ms.k.CreateAuction(ctx, *msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeCreateAuction,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitsDuration, msg.CommitsDuration.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitFee, msg.CommitFee.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyRevealFee, msg.RevealFee.String()),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyMinimumBid, msg.MinimumBid.String()),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
||||
),
|
||||
})
|
||||
|
||||
return &auctiontypes.MsgCreateAuctionResponse{Auction: resp}, nil
|
||||
}
|
||||
|
||||
// CommitBid is the command for committing a bid
|
||||
// nolint: all
|
||||
func (ms msgServer) CommitBid(c context.Context, msg *auctiontypes.MsgCommitBid) (*auctiontypes.MsgCommitBidResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ms.k.CommitBid(ctx, *msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeCommitBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionID, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyCommitHash, msg.CommitHash),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
||||
),
|
||||
})
|
||||
|
||||
return &auctiontypes.MsgCommitBidResponse{Bid: resp}, nil
|
||||
}
|
||||
|
||||
// RevealBid is the command for revealing a bid
|
||||
// nolint: all
|
||||
func (ms msgServer) RevealBid(c context.Context, msg *auctiontypes.MsgRevealBid) (*auctiontypes.MsgRevealBidResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ms.k.RevealBid(ctx, *msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx.EventManager().EmitEvents(sdk.Events{
|
||||
sdk.NewEvent(
|
||||
auctiontypes.EventTypeRevealBid,
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyAuctionID, msg.AuctionId),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeyReveal, msg.Reveal),
|
||||
),
|
||||
sdk.NewEvent(
|
||||
sdk.EventTypeMessage,
|
||||
sdk.NewAttribute(sdk.AttributeKeyModule, auctiontypes.AttributeValueCategory),
|
||||
sdk.NewAttribute(auctiontypes.AttributeKeySigner, signerAddress.String()),
|
||||
),
|
||||
})
|
||||
|
||||
return &auctiontypes.MsgRevealBidResponse{Auction: resp}, nil
|
||||
}
|
||||
|
@ -1,14 +1,100 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
|
||||
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
)
|
||||
|
||||
// TODO: Add required read methods
|
||||
|
||||
// var _ auctiontypes.QueryServer = queryServer{}
|
||||
var _ auctiontypes.QueryServer = queryServer{}
|
||||
|
||||
type queryServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
// NewQueryServerImpl returns an implementation of the module QueryServer.
|
||||
// func NewQueryServerImpl(k Keeper) auctiontypes.QueryServer {
|
||||
// return queryServer{k}
|
||||
// }
|
||||
func NewQueryServerImpl(k Keeper) auctiontypes.QueryServer {
|
||||
return queryServer{k}
|
||||
}
|
||||
|
||||
// Params implements the params query command
|
||||
func (qs queryServer) Params(c context.Context, req *auctiontypes.QueryParamsRequest) (*auctiontypes.QueryParamsResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
params, err := qs.k.GetParams(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auctiontypes.QueryParamsResponse{Params: params}, nil
|
||||
}
|
||||
|
||||
// Auctions queries all auctions
|
||||
func (qs queryServer) Auctions(c context.Context, req *auctiontypes.QueryAuctionsRequest) (*auctiontypes.QueryAuctionsResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
resp, err := qs.k.ListAuctions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auctiontypes.QueryAuctionsResponse{Auctions: &auctiontypes.Auctions{Auctions: resp}}, nil
|
||||
}
|
||||
|
||||
// GetAuction queries an auction by id
|
||||
func (qs queryServer) GetAuction(c context.Context, req *auctiontypes.QueryAuctionRequest) (*auctiontypes.QueryAuctionResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
if req.Id == "" {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction id is required")
|
||||
}
|
||||
|
||||
auction, err := qs.k.GetAuctionById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auctiontypes.QueryAuctionResponse{Auction: &auction}, nil
|
||||
}
|
||||
|
||||
// GetBid queries and auction bid
|
||||
func (qs queryServer) GetBid(c context.Context, req *auctiontypes.QueryBidRequest) (*auctiontypes.QueryBidResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// GetBids queries all auction bids
|
||||
func (qs queryServer) GetBids(c context.Context, req *auctiontypes.QueryBidsRequest) (*auctiontypes.QueryBidsResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// AuctionsByBidder queries auctions by bidder
|
||||
func (qs queryServer) AuctionsByBidder(c context.Context, req *auctiontypes.QueryAuctionsByBidderRequest) (*auctiontypes.QueryAuctionsByBidderResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// AuctionsByOwner queries auctions by owner
|
||||
func (qs queryServer) AuctionsByOwner(c context.Context, req *auctiontypes.QueryAuctionsByOwnerRequest) (*auctiontypes.QueryAuctionsByOwnerResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
if req.OwnerAddress == "" {
|
||||
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner address is required")
|
||||
}
|
||||
|
||||
auctions, err := qs.k.GetAuctionsByOwner(ctx, req.OwnerAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auctiontypes.QueryAuctionsByOwnerResponse{Auctions: &auctiontypes.Auctions{Auctions: auctions}}, nil
|
||||
}
|
||||
|
||||
// GetAuctionModuleBalance queries the auction module account balance
|
||||
func (qs queryServer) GetAuctionModuleBalance(c context.Context, req *auctiontypes.QueryGetAuctionModuleBalanceRequest) (*auctiontypes.QueryGetAuctionModuleBalanceResponse, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
@ -13,4 +13,7 @@ const (
|
||||
var (
|
||||
// ParamsKey is the prefix for params key
|
||||
ParamsKeyPrefix = collections.NewPrefix(0)
|
||||
|
||||
AuctionsKeyPrefix = collections.NewPrefix(1)
|
||||
AuctionOwnerIndexPrefix = collections.NewPrefix(2)
|
||||
)
|
||||
|
@ -3,6 +3,8 @@ package module
|
||||
import (
|
||||
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
|
||||
"cosmossdk.io/client/v2/autocli"
|
||||
|
||||
auctionv1 "git.vdb.to/cerc-io/laconic2d/api/cerc/auction/v1"
|
||||
)
|
||||
|
||||
var _ autocli.HasAutoCLIConfig = AppModule{}
|
||||
@ -10,7 +12,55 @@ var _ autocli.HasAutoCLIConfig = AppModule{}
|
||||
// AutoCLIOptions implements the autocli.HasAutoCLIConfig interface.
|
||||
func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
return &autocliv1.ModuleOptions{
|
||||
Query: nil,
|
||||
Tx: nil,
|
||||
Query: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: auctionv1.Query_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "Params",
|
||||
Use: "params",
|
||||
Short: "Get the current auction parameters",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
|
||||
},
|
||||
{
|
||||
RpcMethod: "Auctions",
|
||||
Use: "list",
|
||||
Short: "List auctions",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
|
||||
},
|
||||
{
|
||||
RpcMethod: "GetAuction",
|
||||
Use: "get [auction-id]",
|
||||
Short: "Get auction info by auction id",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "id"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "AuctionsByOwner",
|
||||
Use: "by-owner [owner-address]",
|
||||
Short: "Get auctions list by owner / creator address",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "owner_address"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Tx: &autocliv1.ServiceCommandDescriptor{
|
||||
Service: auctionv1.Msg_ServiceDesc.ServiceName,
|
||||
RpcCommandOptions: []*autocliv1.RpcCommandOptions{
|
||||
{
|
||||
RpcMethod: "CreateAuction",
|
||||
Use: "create [commits-duration] [reveals-duration] [commit-fee] [reveal-fee] [minimum-bid]",
|
||||
Short: "Create an auction",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "commits_duration"},
|
||||
{ProtoField: "reveals_duration"},
|
||||
{ProtoField: "commit_fee"},
|
||||
{ProtoField: "reveal_fee"},
|
||||
{ProtoField: "minimum_bid"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -116,8 +116,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
|
||||
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
// Register servers
|
||||
// auction.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
// auction.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
||||
auction.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
|
||||
auction.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.keeper))
|
||||
}
|
||||
|
||||
// appmodule.HasEndBlocker
|
||||
|
65
x/auction/types.go
Normal file
65
x/auction/types.go
Normal file
@ -0,0 +1,65 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Auction status values.
|
||||
const (
|
||||
// Auction is in commit phase.
|
||||
AuctionStatusCommitPhase = "commit"
|
||||
|
||||
// Auction is in reveal phase.
|
||||
AuctionStatusRevealPhase = "reveal"
|
||||
|
||||
// Auction has ended (no reveals allowed).
|
||||
AuctionStatusExpired = "expired"
|
||||
|
||||
// Auction has completed (winner selected).
|
||||
AuctionStatusCompleted = "completed"
|
||||
)
|
||||
|
||||
// Bid status values.
|
||||
const (
|
||||
BidStatusCommitted = "commit"
|
||||
BidStatusRevealed = "reveal"
|
||||
)
|
||||
|
||||
// AuctionId simplifies generation of auction IDs.
|
||||
type AuctionId struct {
|
||||
Address sdk.Address
|
||||
AccNum uint64
|
||||
Sequence uint64
|
||||
}
|
||||
|
||||
// Generate creates the auction ID.
|
||||
func (auctionId AuctionId) Generate() string {
|
||||
hasher := sha256.New()
|
||||
str := fmt.Sprintf("%s:%d:%d", auctionId.Address.String(), auctionId.AccNum, auctionId.Sequence)
|
||||
hasher.Write([]byte(str))
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
||||
func (auction Auction) GetCreateTime() string {
|
||||
return string(sdk.FormatTimeBytes(auction.CreateTime))
|
||||
}
|
||||
|
||||
func (auction Auction) GetCommitsEndTime() string {
|
||||
return string(sdk.FormatTimeBytes(auction.CommitsEndTime))
|
||||
}
|
||||
|
||||
func (auction Auction) GetRevealsEndTime() string {
|
||||
return string(sdk.FormatTimeBytes(auction.RevealsEndTime))
|
||||
}
|
||||
|
||||
func (bid Bid) GetCommitTime() string {
|
||||
return string(sdk.FormatTimeBytes(bid.CommitTime))
|
||||
}
|
||||
|
||||
func (bid Bid) GetRevealTime() string {
|
||||
return string(sdk.FormatTimeBytes(bid.RevealTime))
|
||||
}
|
@ -8,12 +8,12 @@ import (
|
||||
"git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
)
|
||||
|
||||
var _ bond.MsgServer = msgServer{}
|
||||
|
||||
type msgServer struct {
|
||||
k Keeper
|
||||
}
|
||||
|
||||
var _ bond.MsgServer = msgServer{}
|
||||
|
||||
// NewMsgServerImpl returns an implementation of the module MsgServer interface.
|
||||
func NewMsgServerImpl(keeper Keeper) bond.MsgServer {
|
||||
return &msgServer{k: keeper}
|
||||
|
Loading…
Reference in New Issue
Block a user