This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
signing_proposal_validation.go
80 lines (74 loc) · 1.87 KB
/
signing_proposal_validation.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
package requests
import (
"errors"
"fmt"
)
func (m *MessageToSign) Validate() error {
if m.MessageID == "" {
return errors.New("{MessageID} cannot be empty")
}
if len(m.Payload) == 0 {
return errors.New("{Payload} cannot zero length")
}
return nil
}
func (m *SigningTask) Validate() error {
if m.MessageID == "" {
return errors.New("{MessageID} cannot be empty")
}
if len(m.Payload) == 0 && m.RangeStart > m.RangeEnd {
return errors.New("{Payload} cannot zero length and RangeStart cannot be greater than RangeEnd")
}
return nil
}
func (r *SigningBatchProposalStartRequest) Validate() error {
if len(r.BatchID) == 0 {
return fmt.Errorf("{BatchID} can not be empty")
}
if len(r.SigningTasks) == 0 {
return fmt.Errorf("{SigningTasks} can not be empty")
}
if r.ParticipantId < 0 {
return errors.New("{ParticipantId} cannot be a negative number")
}
if r.CreatedAt.IsZero() {
return errors.New("{CreatedAt} is not set")
}
for _, m := range r.SigningTasks {
err := m.Validate()
if err != nil {
return fmt.Errorf("failed to validate signing task %+v: %w", m, err)
}
}
return nil
}
func (s *PartialSign) Validate() error {
if len(s.MessageID) == 0 {
return fmt.Errorf("{MessageID} can not be empty")
}
if len(s.Sign) == 0 {
return fmt.Errorf("{Sign} can not be empty")
}
return nil
}
func (r *SigningProposalBatchPartialSignRequests) Validate() error {
if len(r.BatchID) == 0 {
return fmt.Errorf("{BatchID} can not be empty")
}
if r.CreatedAt.IsZero() {
return errors.New("{CreatedAt} is not set")
}
if r.ParticipantId < 0 {
return errors.New("{ParticipantId} cannot be a negative number")
}
if len(r.PartialSigns) == 0 {
return fmt.Errorf("{MessagesToSign} can not be empty")
}
for _, s := range r.PartialSigns {
err := s.Validate()
if err != nil {
return fmt.Errorf("failed to validate partial sign %+v: %w", s, err)
}
}
return nil
}