Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(market): add resource offer into bid object #89

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions go/node/deployment/v1beta3/resourceunit.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions go/node/market/v1beta3/errors.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1beta3

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"errors"
)

const (
Expand Down Expand Up @@ -41,67 +41,67 @@ const (

var (
// ErrEmptyProvider is the error when provider is empty
ErrEmptyProvider = sdkerrors.Register(ModuleName, errCodeEmptyProvider, "empty provider")
ErrEmptyProvider = errors.New("empty provider")
// ErrSameAccount is the error when owner and provider are the same account
ErrSameAccount = sdkerrors.Register(ModuleName, errCodeSameAccount, "owner and provider are the same account")
ErrSameAccount = errors.New("owner and provider are the same account")
// ErrInternal is the error for internal error
ErrInternal = sdkerrors.Register(ModuleName, errCodeInternal, "internal error")
ErrInternal = errors.New("internal error")
// ErrBidOverOrder is the error when bid price is above max order price
ErrBidOverOrder = sdkerrors.Register(ModuleName, errCodeOverOrder, "bid price above max order price")
ErrBidOverOrder = errors.New("bid price above max order price")
// ErrAttributeMismatch is the error for attribute mismatch
ErrAttributeMismatch = sdkerrors.Register(ModuleName, errCodeAttributeMismatch, "attribute mismatch")
ErrAttributeMismatch = errors.New("attribute mismatch")
// ErrCapabilitiesMismatch is the error for capabilities mismatch
ErrCapabilitiesMismatch = sdkerrors.Register(ModuleName, errCodeCapabilitiesMismatch, "capabilities mismatch")
ErrCapabilitiesMismatch = errors.New("capabilities mismatch")
// ErrUnknownBid is the error for unknown bid
ErrUnknownBid = sdkerrors.Register(ModuleName, errCodeUnknownBid, "unknown bid")
ErrUnknownBid = errors.New("unknown bid")
// ErrUnknownLease is the error for unknown bid
ErrUnknownLease = sdkerrors.Register(ModuleName, errCodeUnknownLease, "unknown lease")
ErrUnknownLease = errors.New("unknown lease")
// ErrUnknownLeaseForBid is the error when lease is unknown for bid
ErrUnknownLeaseForBid = sdkerrors.Register(ModuleName, errCodeUnknownLeaseForOrder, "unknown lease for bid")
ErrUnknownLeaseForBid = errors.New("unknown lease for bid")
// ErrUnknownOrderForBid is the error when order is unknown for bid
ErrUnknownOrderForBid = sdkerrors.Register(ModuleName, errCodeUnknownOrderForBid, "unknown order for bid")
ErrUnknownOrderForBid = errors.New("unknown order for bid")
// ErrLeaseNotActive is the error when lease is not active
ErrLeaseNotActive = sdkerrors.Register(ModuleName, errCodeLeaseNotActive, "lease not active")
ErrLeaseNotActive = errors.New("lease not active")
// ErrBidNotActive is the error when bid is not matched
ErrBidNotActive = sdkerrors.Register(ModuleName, errCodeBidNotActive, "bid not active")
ErrBidNotActive = errors.New("bid not active")
// ErrBidNotOpen is the error when bid is not matched
ErrBidNotOpen = sdkerrors.Register(ModuleName, errCodeBidNotOpen, "bid not open")
ErrBidNotOpen = errors.New("bid not open")
// ErrNoLeaseForOrder is the error when there is no lease for order
ErrNoLeaseForOrder = sdkerrors.Register(ModuleName, errCodeNoLeaseForOrder, "no lease for order")
ErrNoLeaseForOrder = errors.New("no lease for order")
// ErrOrderNotFound order not found
ErrOrderNotFound = sdkerrors.Register(ModuleName, errCodeOrderNotFound, "invalid order: order not found")
ErrOrderNotFound = errors.New("invalid order: order not found")
// ErrGroupNotFound order not found
ErrGroupNotFound = sdkerrors.Register(ModuleName, errCodeGroupNotFound, "order not found")
ErrGroupNotFound = errors.New("order not found")
// ErrGroupNotOpen order not found
ErrGroupNotOpen = sdkerrors.Register(ModuleName, errCodeGroupNotOpen, "order not open")
ErrGroupNotOpen = errors.New("order not open")
// ErrOrderNotOpen order not found
ErrOrderNotOpen = sdkerrors.Register(ModuleName, errCodeOrderNotOpen, "bid: order not open")
ErrOrderNotOpen = errors.New("bid: order not open")
// ErrBidNotFound bid not found
ErrBidNotFound = sdkerrors.Register(ModuleName, errCodeBidNotFound, "invalid bid: bid not found")
ErrBidNotFound = errors.New("invalid bid: bid not found")
// ErrBidZeroPrice zero price
ErrBidZeroPrice = sdkerrors.Register(ModuleName, errCodeBidZeroPrice, "invalid bid: zero price")
ErrBidZeroPrice = errors.New("invalid bid: zero price")
// ErrLeaseNotFound lease not found
ErrLeaseNotFound = sdkerrors.Register(ModuleName, errCodeLeaseNotFound, "invalid lease: lease not found")
ErrLeaseNotFound = errors.New("invalid lease: lease not found")
// ErrBidExists bid exists
ErrBidExists = sdkerrors.Register(ModuleName, errCodeBidExists, "invalid bid: bid exists from provider")
ErrBidExists = errors.New("invalid bid: bid exists from provider")
// ErrBidInvalidPrice bid invalid price
ErrBidInvalidPrice = sdkerrors.Register(ModuleName, errCodeInvalidPrice, "bid price is invalid")
ErrBidInvalidPrice = errors.New("bid price is invalid")
// ErrOrderActive order active
ErrOrderActive = sdkerrors.New(ModuleName, errCodeOrderActive, "order active")
ErrOrderActive = errors.New("order active")
// ErrOrderClosed order closed
ErrOrderClosed = sdkerrors.New(ModuleName, errCodeOrderClosed, "order closed")
ErrOrderClosed = errors.New("order closed")
// ErrOrderExists indicates a new order was proposed overwrite the existing store key
ErrOrderExists = sdkerrors.New(ModuleName, errCodeOrderExists, "order already exists in store")
ErrOrderExists = errors.New("order already exists in store")
// ErrOrderTooEarly to match bid
ErrOrderTooEarly = sdkerrors.New(ModuleName, errCodeOrderTooEarly, "order: chain height to low for bidding")
ErrOrderTooEarly = errors.New("order: chain height to low for bidding")
// ErrOrderDurationExceeded order should be closed
ErrOrderDurationExceeded = sdkerrors.New(ModuleName, errCodeOrderDurationExceeded, "order duration has exceeded the bidding duration")
ErrOrderDurationExceeded = errors.New("order duration has exceeded the bidding duration")
// ErrInvalidDeposit indicates an invalid deposit
ErrInvalidDeposit = sdkerrors.Register(ModuleName, errInvalidDeposit, "Deposit invalid")
ErrInvalidDeposit = errors.New("deposit invalid")
// ErrInvalidParam indicates an invalid chain parameter
ErrInvalidParam = sdkerrors.Register(ModuleName, errInvalidParam, "parameter invalid")
ErrInvalidParam = errors.New("parameter invalid")
// ErrUnknownProvider indicates an invalid chain parameter
ErrUnknownProvider = sdkerrors.Register(ModuleName, errUnknownProvider, "unknown provider")
ErrUnknownProvider = errors.New("unknown provider")
// ErrInvalidBid indicates an invalid chain parameter
ErrInvalidBid = sdkerrors.Register(ModuleName, errInvalidBid, "unknown provider")
ErrInvalidBid = errors.New("unknown provider")
)
38 changes: 38 additions & 0 deletions go/node/market/v1beta4/bid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v1beta4

import (
"sort"
)

type ResourcesOffer []ResourceOffer

var _ sort.Interface = (*ResourcesOffer)(nil)

func (r *ResourceOffer) Dup() ResourceOffer {
return ResourceOffer{
Resources: r.Resources.Dup(),
Count: r.Count,
}

Check warning on line 15 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L11-L15

Added lines #L11 - L15 were not covered by tests
}

func (s ResourcesOffer) Len() int {
return len(s)

Check warning on line 19 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}

func (s ResourcesOffer) Swap(i, j int) {
s[i], s[j] = s[j], s[i]

Check warning on line 23 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L22-L23

Added lines #L22 - L23 were not covered by tests
}

func (s ResourcesOffer) Less(i, j int) bool {
return s[i].Resources.ID < s[j].Resources.ID

Check warning on line 27 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L26-L27

Added lines #L26 - L27 were not covered by tests
}

func (s ResourcesOffer) Dup() ResourcesOffer {
res := make(ResourcesOffer, 0, len(s))

for _, ru := range s {
res = append(res, ru.Dup())
}

Check warning on line 35 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L30-L35

Added lines #L30 - L35 were not covered by tests

return s

Check warning on line 37 in go/node/market/v1beta4/bid.go

View check run for this annotation

Codecov / codecov/patch

go/node/market/v1beta4/bid.go#L37

Added line #L37 was not covered by tests
}
Loading