Skip to content

Commit e9862c5

Browse files
committed
feedback improvements [1]
1 parent 0930eae commit e9862c5

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed

internal/adapters/entrypoints/rest/common.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,9 @@ func PositiveStringValidationRule(value string) bool {
3030
return bigIntValue.Cmp(big.NewInt(0)) > 0
3131
}
3232

33-
func ZeroOrPositiveStringValidationRule(value string) bool {
34-
bigIntValue := new(big.Int)
35-
bigIntValue.SetString(value, 10)
36-
return bigIntValue.Cmp(big.NewInt(0)) >= 0
37-
}
38-
39-
func NonNegativeStringValidationRule(value string) bool {
40-
bigIntValue := new(big.Int)
41-
bigIntValue.SetString(value, 10)
42-
return bigIntValue.Cmp(big.NewInt(0)) >= 0
43-
}
44-
4533
func percentageFeeValidator(fl validator.FieldLevel) bool {
4634
val := fl.Field().Float()
47-
if val < 0 || val > 100 {
35+
if val < 0 || val >= 100 {
4836
return false
4937
}
5038
valTimes100 := val * 100
@@ -67,19 +55,6 @@ func registerValidations() error {
6755
if err := RequestValidator.RegisterValidation("percentage_fee", percentageFeeValidator); err != nil {
6856
return fmt.Errorf("registering percentage_fee validation: %w", err)
6957
}
70-
71-
if err := RequestValidator.RegisterValidation("non_negative_string", func(field validator.FieldLevel) bool {
72-
return NonNegativeStringValidationRule(field.Field().String())
73-
}); err != nil {
74-
return fmt.Errorf("registering non_negative_string validation: %w", err)
75-
}
76-
77-
if err := RequestValidator.RegisterValidation("zero_or_positive_string", func(field validator.FieldLevel) bool {
78-
return ZeroOrPositiveStringValidationRule(field.Field().String())
79-
}); err != nil {
80-
return fmt.Errorf("registering zero_or_positive_string validation: %w", err)
81-
}
82-
8358
return nil
8459
}
8560

internal/entities/utils/encoding.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,16 @@ func (bf *BigFloat) MarshalJSON() ([]byte, error) {
3030
if bf == nil {
3131
return []byte("null"), nil
3232
}
33-
valueStr := bf.Native().Text('f', -1)
34-
return json.Marshal(valueStr)
33+
value, _ := bf.Native().Float64()
34+
return json.Marshal(value)
3535
}
3636

3737
func (bf *BigFloat) UnmarshalJSON(b []byte) error {
38-
var valueStr string
39-
if err := json.Unmarshal(b, &valueStr); err != nil {
38+
var value float64
39+
if err := json.Unmarshal(b, &value); err != nil {
4040
return err
4141
}
42-
_, ok := bf.Native().SetString(valueStr)
43-
if !ok {
44-
return fmt.Errorf("invalid BigFloat value: %s", valueStr)
45-
}
42+
bf.Native().SetFloat64(value)
4643
return nil
4744
}
4845

pkg/liquidity_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type PeginConfigurationDTO struct {
4646
TimeForDeposit uint32 `json:"timeForDeposit" validate:"required"`
4747
CallTime uint32 `json:"callTime" validate:"required"`
4848
PenaltyFee string `json:"penaltyFee" validate:"required,numeric,positive_string"`
49-
FixedFee string `json:"fixedFee" validate:"required,numeric,zero_or_positive_string"`
50-
FeePercentage float64 `json:"feePercentage" validate:"numeric,percentage_fee,zero_or_positive_string"`
49+
FixedFee string `json:"fixedFee" validate:"required,numeric,min=0"`
50+
FeePercentage float64 `json:"feePercentage" validate:"numeric,percentage_fee"`
5151
MaxValue string `json:"maxValue" validate:"required,numeric,positive_string"`
5252
MinValue string `json:"minValue" validate:"required,numeric,positive_string"`
5353
}
@@ -60,8 +60,8 @@ type PegoutConfigurationDTO struct {
6060
TimeForDeposit uint32 `json:"timeForDeposit" validate:"required"`
6161
ExpireTime uint32 `json:"expireTime" validate:"required"`
6262
PenaltyFee string `json:"penaltyFee" validate:"required,numeric,positive_string"`
63-
FixedFee string `json:"fixedFee" validate:"required,numeric,zero_or_positive_string"`
64-
FeePercentage float64 `json:"feePercentage" validate:"required,percentage_fee,zero_or_positive_string"`
63+
FixedFee string `json:"fixedFee" validate:"required,numeric,min=0"`
64+
FeePercentage float64 `json:"feePercentage" validate:"required,percentage_fee"`
6565
MaxValue string `json:"maxValue" validate:"required,numeric,positive_string"`
6666
MinValue string `json:"minValue" validate:"required,numeric,positive_string"`
6767
ExpireBlocks uint64 `json:"expireBlocks" validate:"required"`

0 commit comments

Comments
 (0)