diff --git a/go/node/market/v1beta4/bid.go b/go/node/market/v1beta4/bid.go index f1c38424..2af74ceb 100644 --- a/go/node/market/v1beta4/bid.go +++ b/go/node/market/v1beta4/bid.go @@ -3,13 +3,42 @@ package v1beta4 import ( "sort" - "github.com/akash-network/akash-api/go/node/deployment/v1beta3" + dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3" ) type ResourcesOffer []ResourceOffer var _ sort.Interface = (*ResourcesOffer)(nil) +func (s ResourcesOffer) MatchGSpec(gspec dtypes.GroupSpec) bool { + if len(s) == 0 { + return true + } + + ru := make(map[uint32]*dtypes.ResourceUnit) + + for _, res := range gspec.Resources { + ru[res.ID] = &res + } + + for _, ro := range s { + res, exists := ru[ro.Resources.ID] + if !exists { + return false + } + + ru[ro.Resources.ID] = nil + + if res.Count != ro.Count { + return false + } + + // TODO @troian check resources boundaries + } + + return true +} + func (r *ResourceOffer) Dup() ResourceOffer { return ResourceOffer{ Resources: r.Resources.Dup(), @@ -39,7 +68,7 @@ func (s ResourcesOffer) Dup() ResourcesOffer { return s } -func ResourceOfferFromRU(ru v1beta3.ResourceUnits) ResourcesOffer { +func ResourceOfferFromRU(ru dtypes.ResourceUnits) ResourcesOffer { res := make(ResourcesOffer, 0, len(ru)) for _, r := range ru { diff --git a/go/node/types/v1beta3/resources.go b/go/node/types/v1beta3/resources.go index 16137dc3..123ca57f 100644 --- a/go/node/types/v1beta3/resources.go +++ b/go/node/types/v1beta3/resources.go @@ -131,3 +131,64 @@ func (m Volumes) Dup() Volumes { return res } + +func (this *CPU) EqualUnits(that *CPU) bool { + if that == nil { + return this == nil + } else if this == nil { + return false + } + + if !this.Units.Equal(&that.Units) { + return false + } + + return true +} + +func (this *GPU) EqualUnits(that *GPU) bool { + if that == nil { + return this == nil + } else if this == nil { + return false + } + + if !this.Units.Equal(&that.Units) { + return false + } + + return true +} + +func (this *Memory) EqualUnits(that *Memory) bool { + if that == nil { + return this == nil + } else if this == nil { + return false + } + + if !this.Quantity.Equal(&that.Quantity) { + return false + } + + return true +} + +func (this Volumes) EqualUnits(that Volumes) bool { + if len(this) != len(that) { + return false + } + + for idx, vol := range this { + if vol.Name != that[idx].Name { + return false + } + + if !vol.Quantity.Equal(&that[idx].Quantity) { + return false + } + + } + + return true +}