-
Notifications
You must be signed in to change notification settings - Fork 55
/
utils.go
96 lines (77 loc) · 2.51 KB
/
utils.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
package cli
import (
"encoding/json"
"os"
"time"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/crescent-network/crescent/v2/x/farming/types"
)
// PrivateFixedPlanRequest defines CLI request for a private fixed plan.
type PrivateFixedPlanRequest struct {
Name string `json:"name"`
StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
EpochAmount sdk.Coins `json:"epoch_amount"`
}
// PrivateRatioPlanRequest defines CLI request for a private ratio plan.
type PrivateRatioPlanRequest struct {
Name string `json:"name"`
StakingCoinWeights sdk.DecCoins `json:"staking_coin_weights"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
EpochRatio sdk.Dec `json:"epoch_ratio"`
}
// ParsePrivateFixedPlan reads and parses a PrivateFixedPlanRequest from a file.
func ParsePrivateFixedPlan(file string) (PrivateFixedPlanRequest, error) {
plan := PrivateFixedPlanRequest{}
contents, err := os.ReadFile(file)
if err != nil {
return plan, err
}
if err = json.Unmarshal(contents, &plan); err != nil {
return plan, err
}
return plan, nil
}
// ParsePrivateRatioPlan reads and parses a PrivateRatioPlanRequest from a file.
func ParsePrivateRatioPlan(file string) (PrivateRatioPlanRequest, error) {
plan := PrivateRatioPlanRequest{}
contents, err := os.ReadFile(file)
if err != nil {
return plan, err
}
if err = json.Unmarshal(contents, &plan); err != nil {
return plan, err
}
return plan, nil
}
// ParsePublicPlanProposal reads and parses a PublicPlanProposal from a file.
func ParsePublicPlanProposal(cdc codec.JSONCodec, proposalFile string) (types.PublicPlanProposal, error) {
proposal := types.PublicPlanProposal{}
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err = cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
return proposal, nil
}
// String returns a human readable string representation of the request.
func (req PrivateFixedPlanRequest) String() string {
result, err := json.Marshal(&req)
if err != nil {
panic(err)
}
return string(result)
}
// String returns a human readable string representation of the request.
func (req PrivateRatioPlanRequest) String() string {
result, err := json.Marshal(&req)
if err != nil {
panic(err)
}
return string(result)
}