make bids for lowest rather than highest

master
michael 2022-09-01 02:02:23 +00:00
parent 0d1513e35d
commit 8f4f5d270a
7 changed files with 30 additions and 30 deletions

View File

@ -9,7 +9,7 @@ message Auction {
string index = 1; string index = 1;
string name = 2; string name = 2;
string description = 3; string description = 3;
Bid topBid = 4; Bid best = 4;
uint64 deadline = 5; uint64 deadline = 5;
} }

View File

@ -29,7 +29,7 @@ func (k *Keeper) EndExpiredAuctions(ctx types.Context) {
if uint64(ctx.BlockHeight()) >= auction.Deadline-auctionconfig.AuctionTime { if uint64(ctx.BlockHeight()) >= auction.Deadline-auctionconfig.AuctionTime {
var err error var err error
auction.TopBid, err = memdb.BidDB.GetHighestBid(auctionId) auction.Best, err = memdb.BidDB.GetLowestBid(auctionId)
if err != nil { if err != nil {
return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err) return errors.Errorf("could not get highest bid for auction %s: %s", auctionId, err)
} }

View File

@ -24,7 +24,7 @@ func (k msgServer) NewAuction(goCtx context.Context, msg *types.MsgNewAuction) (
Index: index, Index: index,
Name: msg.Name, Name: msg.Name,
Description: msg.Description, Description: msg.Description,
TopBid: new(types.Bid), Best: new(types.Bid),
Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime, Deadline: uint64(ctx.BlockHeight()) + auctionconfig.AuctionTime,
} }

View File

@ -38,7 +38,7 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("bid amount must be greater than 0") return nil, fmt.Errorf("bid amount must be greater than 0")
} }
highestBid, err := memdb.BidDB.GetHighestBid(msg.AuctionIndex) highestBid, err := memdb.BidDB.GetLowestBid(msg.AuctionIndex)
// we manually handle KeyNotFound in GetHighestBid, so should return (nil, nil) if not found // we manually handle KeyNotFound in GetHighestBid, so should return (nil, nil) if not found
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get highest bid: %s", reflect.TypeOf(err)) return nil, fmt.Errorf("failed to get highest bid: %s", reflect.TypeOf(err))
@ -51,8 +51,8 @@ func (k msgServer) NewBid(goCtx context.Context, msg *types.MsgNewBid) (*types.M
return nil, fmt.Errorf("failed to convert max bid (%s) to a large integer", msg.Amount) return nil, fmt.Errorf("failed to convert max bid (%s) to a large integer", msg.Amount)
} }
if amt.Cmp(amtPrev) < 1 { if amt.Cmp(amtPrev) != -1 {
return nil, fmt.Errorf("bid amount must be greater than largest bid") return nil, fmt.Errorf("bid amount must be less than current lowest bid (%s)", amtPrev)
} }
} }

View File

@ -74,7 +74,7 @@ func (b *bidDB) AddBid(auctionId string, bid *types.Bid) error {
} }
// Get the highest bid in the list under specified auction key. // Get the highest bid in the list under specified auction key.
func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) { func (b *bidDB) GetLowestBid(auctionId string) (*types.Bid, error) {
k := []byte(auctionId) k := []byte(auctionId)
var bid *types.Bid var bid *types.Bid
@ -108,7 +108,7 @@ func (b *bidDB) GetHighestBid(auctionId string) (*types.Bid, error) {
amt.SetString(rBid.Amount, 10) amt.SetString(rBid.Amount, 10)
} else { } else {
rAmt.SetString(rBid.Amount, 10) rAmt.SetString(rBid.Amount, 10)
if rAmt.Cmp(amt) == 1 { if rAmt.Cmp(amt) == -1 {
bid = rBid bid = rBid
} }
} }

View File

@ -35,7 +35,7 @@ func TestBasicFlow(t *testing.T) {
} }
// check highest bid // check highest bid
if bid, err := BidDB.GetHighestBid("0"); err != nil { if bid, err := BidDB.GetLowestBid("0"); err != nil {
panic(err) panic(err)
} else { } else {
if bid.Owner != "cosmos456" || bid.Amount != "200" { if bid.Owner != "cosmos456" || bid.Amount != "200" {

View File

@ -26,7 +26,7 @@ type Auction struct {
Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"` Index string `protobuf:"bytes,1,opt,name=index,proto3" json:"index,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
TopBid *Bid `protobuf:"bytes,4,opt,name=topBid,proto3" json:"topBid,omitempty"` Best *Bid `protobuf:"bytes,4,opt,name=best,proto3" json:"best,omitempty"`
Deadline uint64 `protobuf:"varint,5,opt,name=deadline,proto3" json:"deadline,omitempty"` Deadline uint64 `protobuf:"varint,5,opt,name=deadline,proto3" json:"deadline,omitempty"`
} }
@ -84,9 +84,9 @@ func (m *Auction) GetDescription() string {
return "" return ""
} }
func (m *Auction) GetTopBid() *Bid { func (m *Auction) GetBest() *Bid {
if m != nil { if m != nil {
return m.TopBid return m.Best
} }
return nil return nil
} }
@ -105,21 +105,21 @@ func init() {
func init() { proto.RegisterFile("cosmostest/auction.proto", fileDescriptor_631f6f59914101d9) } func init() { proto.RegisterFile("cosmostest/auction.proto", fileDescriptor_631f6f59914101d9) }
var fileDescriptor_631f6f59914101d9 = []byte{ var fileDescriptor_631f6f59914101d9 = []byte{
// 223 bytes of a gzipped FileDescriptorProto // 221 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0xce, 0x2f, 0xce, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x48, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0x2e, 0x49, 0x2d, 0x2e, 0xd1, 0x4f, 0x2c, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x2b, 0xcd, 0x2f, 0x2e, 0x49, 0x2d, 0x2e, 0xd1, 0x4f, 0x2c, 0x4d, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x2b,
0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x45, 0xc8, 0xe8, 0x21, 0x98, 0x52, 0x22, 0x48, 0x1a, 0x92, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x45, 0xc8, 0xe8, 0x21, 0x98, 0x52, 0x22, 0x48, 0x1a, 0x92,
0x32, 0x53, 0x20, 0x8a, 0x95, 0x96, 0x32, 0x72, 0xb1, 0x3b, 0x42, 0xb4, 0x0b, 0x89, 0x70, 0xb1, 0x32, 0x53, 0x20, 0x8a, 0x95, 0x16, 0x32, 0x72, 0xb1, 0x3b, 0x42, 0xb4, 0x0b, 0x89, 0x70, 0xb1,
0x66, 0xe6, 0xa5, 0xa4, 0x56, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x38, 0x42, 0x42, 0x66, 0xe6, 0xa5, 0xa4, 0x56, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x38, 0x42, 0x42,
0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x4c, 0x60, 0x41, 0x30, 0x5b, 0x48, 0x81, 0x8b, 0x3b, 0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x4c, 0x60, 0x41, 0x30, 0x5b, 0x48, 0x81, 0x8b, 0x3b,
0x25, 0xb5, 0x38, 0xb9, 0x28, 0xb3, 0x00, 0xa4, 0x51, 0x82, 0x19, 0x2c, 0x85, 0x2c, 0x24, 0x64, 0x25, 0xb5, 0x38, 0xb9, 0x28, 0xb3, 0x00, 0xa4, 0x51, 0x82, 0x19, 0x2c, 0x85, 0x2c, 0x24, 0xa4,
0xc4, 0xc5, 0x56, 0x92, 0x5f, 0xe0, 0x94, 0x99, 0x22, 0xc1, 0xa2, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xc7, 0xc5, 0x92, 0x94, 0x5a, 0x5c, 0x22, 0xc1, 0xa2, 0xc0, 0xa8, 0xc1, 0x6d, 0x24, 0xa5, 0x87,
0xa5, 0x87, 0xd5, 0x55, 0x7a, 0x4e, 0x99, 0x29, 0x41, 0x50, 0x95, 0x42, 0x52, 0x5c, 0x1c, 0x29, 0xd5, 0x4d, 0x7a, 0x4e, 0x99, 0x29, 0x41, 0x60, 0x75, 0x42, 0x52, 0x5c, 0x1c, 0x29, 0xa9, 0x89,
0xa9, 0x89, 0x29, 0x39, 0x99, 0x79, 0xa9, 0x12, 0xac, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x70, 0xbe, 0x29, 0x39, 0x99, 0x79, 0xa9, 0x12, 0xac, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x70, 0xbe, 0x93, 0xc5,
0x93, 0xc5, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c,
0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xc9, 0x41, 0x4c, 0xd3, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xc9, 0x41, 0xcc, 0xd2, 0x05, 0x7b,
0x05, 0x7b, 0xac, 0x42, 0x1f, 0xc9, 0x97, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x8f, 0xaa, 0x42, 0x1f, 0xc9, 0x87, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x4f, 0x1a, 0x03,
0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x84, 0x5a, 0xc2, 0xfb, 0x31, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb5, 0xb0, 0xd9, 0xd2, 0x2d, 0x01, 0x00, 0x00,
} }
func (m *Auction) Marshal() (dAtA []byte, err error) { func (m *Auction) Marshal() (dAtA []byte, err error) {
@ -147,9 +147,9 @@ func (m *Auction) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i-- i--
dAtA[i] = 0x28 dAtA[i] = 0x28
} }
if m.TopBid != nil { if m.Best != nil {
{ {
size, err := m.TopBid.MarshalToSizedBuffer(dAtA[:i]) size, err := m.Best.MarshalToSizedBuffer(dAtA[:i])
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -212,8 +212,8 @@ func (m *Auction) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovAuction(uint64(l)) n += 1 + l + sovAuction(uint64(l))
} }
if m.TopBid != nil { if m.Best != nil {
l = m.TopBid.Size() l = m.Best.Size()
n += 1 + l + sovAuction(uint64(l)) n += 1 + l + sovAuction(uint64(l))
} }
if m.Deadline != 0 { if m.Deadline != 0 {
@ -355,7 +355,7 @@ func (m *Auction) Unmarshal(dAtA []byte) error {
iNdEx = postIndex iNdEx = postIndex
case 4: case 4:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field TopBid", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Best", wireType)
} }
var msglen int var msglen int
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
@ -382,10 +382,10 @@ func (m *Auction) Unmarshal(dAtA []byte) error {
if postIndex > l { if postIndex > l {
return io.ErrUnexpectedEOF return io.ErrUnexpectedEOF
} }
if m.TopBid == nil { if m.Best == nil {
m.TopBid = &Bid{} m.Best = &Bid{}
} }
if err := m.TopBid.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { if err := m.Best.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err return err
} }
iNdEx = postIndex iNdEx = postIndex