Skip to content

Commit a244d83

Browse files
committed
chore: remote IsValid method from price
1 parent e47b812 commit a244d83

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

types/v1/price.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ func (p Price) Validate() error {
181181
return nil
182182
}
183183

184-
// IsValid returns true if the Price passes validation.
185-
func (p Price) IsValid() bool {
186-
return p.Validate() == nil
187-
}
188-
189184
// negative returns the negated Price (both base and quote).
190185
func (p Price) negative() Price {
191186
return Price{
@@ -356,11 +351,6 @@ func (p Prices) Validate() error {
356351
return nil
357352
}
358353

359-
// IsValid checks if the Prices slice is valid.
360-
func (p Prices) IsValid() bool {
361-
return p.Validate() == nil
362-
}
363-
364354
// Len returns the number of Prices.
365355
func (p Prices) Len() int {
366356
return len(p)

x/node/types/v3/msg.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ func (m *MsgRegisterNodeRequest) ValidateBasic() error {
5151
return types.NewErrorInvalidMessage(fmt.Errorf("invalid from: %w", err))
5252
}
5353

54-
if prices := m.GetGigabytePrices(); !prices.IsValid() {
55-
return types.NewErrorInvalidMessage("gigabyte_prices must be valid")
54+
gigabytePrices := m.GetGigabytePrices()
55+
if err := gigabytePrices.Validate(); err != nil {
56+
return types.NewErrorInvalidMessage(fmt.Errorf("invalid gigabyte_prices: %w", err))
5657
}
5758

58-
if prices := m.GetHourlyPrices(); !prices.IsValid() {
59-
return types.NewErrorInvalidMessage("hourly_prices must be valid")
59+
hourlyPrices := m.GetHourlyPrices()
60+
if err := hourlyPrices.Validate(); err != nil {
61+
return types.NewErrorInvalidMessage(fmt.Errorf("invalid hourly_prices: %w", err))
6062
}
6163

6264
if len(m.RemoteAddrs) == 0 {
@@ -110,12 +112,14 @@ func (m *MsgUpdateNodeDetailsRequest) ValidateBasic() error {
110112
return types.NewErrorInvalidMessage(fmt.Errorf("invalid from: %w", err))
111113
}
112114

113-
if prices := m.GetGigabytePrices(); !prices.IsValid() {
114-
return types.NewErrorInvalidMessage("gigabyte_prices must be valid")
115+
gigabytePrices := m.GetGigabytePrices()
116+
if err := gigabytePrices.Validate(); err != nil {
117+
return types.NewErrorInvalidMessage(fmt.Errorf("invalid gigabyte_prices: %w", err))
115118
}
116119

117-
if prices := m.GetHourlyPrices(); !prices.IsValid() {
118-
return types.NewErrorInvalidMessage("hourly_prices must be valid")
120+
hourlyPrices := m.GetHourlyPrices()
121+
if err := hourlyPrices.Validate(); err != nil {
122+
return types.NewErrorInvalidMessage(fmt.Errorf("invalid hourly_prices: %w", err))
119123
}
120124

121125
if len(m.RemoteAddrs) > 0 {

x/node/types/v3/node.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ func (m *Node) Validate() error {
3030
return fmt.Errorf("invalid address: %w", err)
3131
}
3232

33-
if prices := m.GetGigabytePrices(); !prices.IsValid() {
34-
return errors.New("gigabyte_prices must be valid")
33+
gigabytePrices := m.GetGigabytePrices()
34+
if err := gigabytePrices.Validate(); err != nil {
35+
return fmt.Errorf("invalid gigabyte_prices: %w", err)
3536
}
3637

37-
if prices := m.GetHourlyPrices(); !prices.IsValid() {
38-
return errors.New("hourly_prices must be valid")
38+
hourlyPrices := m.GetHourlyPrices()
39+
if err := hourlyPrices.Validate(); err != nil {
40+
return fmt.Errorf("invalid hourly_prices: %w", err)
3941
}
4042

4143
if err := validateRemoteAddrs(m.RemoteAddrs); err != nil {

x/plan/types/v3/msg.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ func (m *MsgCreatePlanRequest) ValidateBasic() error {
6868
return types.NewErrorInvalidMessage("duration cannot be negative")
6969
}
7070

71-
if prices := m.GetPrices(); !prices.IsValid() {
72-
return types.NewErrorInvalidMessage("prices must be valid")
71+
prices := m.GetPrices()
72+
if err := prices.Validate(); err != nil {
73+
return types.NewErrorInvalidMessage(fmt.Errorf("invalid prices: %w", err))
7374
}
7475

7576
return nil

x/plan/types/v3/plan.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ func (m *Plan) Validate() error {
6262
return errors.New("duration cannot be negative")
6363
}
6464

65-
if prices := m.GetPrices(); !prices.IsValid() {
66-
return errors.New("prices must be valid")
65+
prices := m.GetPrices()
66+
if err := prices.Validate(); err != nil {
67+
return fmt.Errorf("invalid prices: %w", err)
6768
}
6869

6970
if !m.Status.IsOneOf(v1base.StatusActive, v1base.StatusInactive) {

0 commit comments

Comments
 (0)