-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_var_proposal_submission.go
43 lines (35 loc) · 1.22 KB
/
state_var_proposal_submission.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
package commands
import (
"strconv"
commandspb "github.com/elysiumstation/fury/protos/fury/commands/v1"
)
func CheckStateVariableProposal(cmd *commandspb.StateVariableProposal) error {
return checkStateVariableProposal(cmd).ErrorOrNil()
}
func checkStateVariableProposal(cmd *commandspb.StateVariableProposal) Errors {
errs := NewErrors()
if cmd == nil {
return errs.FinalAddForProperty("state_variable_proposal", ErrIsRequired)
}
if cmd.Proposal == nil {
return errs.FinalAddForProperty("state_variable_proposal.missing_proposal", ErrIsRequired)
}
if len(cmd.Proposal.EventId) == 0 {
errs.AddForProperty("state_variable_proposal.event_id", ErrIsRequired)
}
if len(cmd.Proposal.StateVarId) == 0 {
errs.AddForProperty("state_variable_proposal.state_var_id", ErrIsRequired)
}
if len(cmd.Proposal.Kvb) == 0 {
errs.AddForProperty("state_variable_proposal.key_value_bundle", ErrIsRequired)
}
for i, kvb := range cmd.Proposal.Kvb {
if len(kvb.Key) == 0 {
errs.AddForProperty("state_variable_proposal.key_value_bundle."+strconv.Itoa(i)+".key", ErrIsRequired)
}
if kvb.Value == nil {
errs.AddForProperty("state_variable_proposal.key_value_bundle."+strconv.Itoa(i)+".value", ErrIsRequired)
}
}
return errs
}