-
Notifications
You must be signed in to change notification settings - Fork 204
/
types.go
129 lines (103 loc) · 3.05 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package v1beta2
import (
"bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
types "github.com/akash-network/node/types/v1beta2"
)
type attributesMatching map[string]types.Attributes
const (
// ManifestVersionLength is the length of manifest version
ManifestVersionLength = 32
// DefaultOrderBiddingDuration is the default time limit for an Order being active.
// After the duration, the Order is automatically closed.
// ( 24(hr) * 3600(seconds per hour) ) / 7s-Block
DefaultOrderBiddingDuration = int64(12342)
// MaxBiddingDuration is roughly 30 days of block height
MaxBiddingDuration = DefaultOrderBiddingDuration * int64(30)
)
// ID method returns DeploymentID details of specific deployment
func (obj Deployment) ID() DeploymentID {
return obj.DeploymentID
}
// MatchAttributes method compares provided attributes with specific group attributes
func (g GroupSpec) MatchAttributes(attr types.Attributes) bool {
return types.AttributesSubsetOf(g.Requirements.Attributes, attr)
}
// ID method returns GroupID details of specific group
func (g Group) ID() GroupID {
return g.GroupID
}
// ValidateClosable provides error response if group is already closed,
// and thus should not be closed again, else nil.
func (g Group) ValidateClosable() error {
switch g.State {
case GroupClosed:
return ErrGroupClosed
default:
return nil
}
}
// ValidatePausable provides error response if group is not pausable
func (g Group) ValidatePausable() error {
switch g.State {
case GroupClosed:
return ErrGroupClosed
case GroupPaused:
return ErrGroupPaused
default:
return nil
}
}
// ValidatePausable provides error response if group is not pausable
func (g Group) ValidateStartable() error {
switch g.State {
case GroupClosed:
return ErrGroupClosed
case GroupOpen:
return ErrGroupOpen
default:
return nil
}
}
// GetName method returns group name
func (g Group) GetName() string {
return g.GroupSpec.Name
}
// GetResources method returns resources list in group
func (g Group) GetResources() []types.Resources {
return g.GroupSpec.GetResources()
}
// FullPrice method returns full price of resource
func (r Resource) FullPrice() sdk.DecCoin {
return sdk.NewDecCoinFromDec(r.Price.Denom, r.Price.Amount.MulInt64(int64(r.Count)))
}
// DeploymentResponses is a collection of DeploymentResponse
type DeploymentResponses []QueryDeploymentResponse
func (ds DeploymentResponses) String() string {
var buf bytes.Buffer
const sep = "\n\n"
for _, d := range ds {
buf.WriteString(d.String())
buf.WriteString(sep)
}
if len(ds) > 0 {
buf.Truncate(buf.Len() - len(sep))
}
return buf.String()
}
// Accept returns whether deployment filters valid or not
func (filters DeploymentFilters) Accept(obj Deployment, stateVal Deployment_State) bool {
// Checking owner filter
if filters.Owner != "" && filters.Owner != obj.DeploymentID.Owner {
return false
}
// Checking dseq filter
if filters.DSeq != 0 && filters.DSeq != obj.DeploymentID.DSeq {
return false
}
// Checking state filter
if stateVal != 0 && stateVal != obj.State {
return false
}
return true
}