forked from hyperledger-labs/yui-relayer
/
ics24.go
59 lines (50 loc) · 1.51 KB
/
ics24.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
package core
import (
"fmt"
"strings"
host "github.com/cosmos/ibc-go/modules/core/24-host"
)
// Vclient validates the client identifier in the path
func (pe *PathEnd) Vclient() error {
return host.ClientIdentifierValidator(pe.ClientID)
}
// Vconn validates the connection identifier in the path
func (pe *PathEnd) Vconn() error {
return host.ConnectionIdentifierValidator(pe.ConnectionID)
}
// Vchan validates the channel identifier in the path
func (pe *PathEnd) Vchan() error {
return host.ChannelIdentifierValidator(pe.ChannelID)
}
// Vport validates the port identifier in the path
func (pe *PathEnd) Vport() error {
return host.PortIdentifierValidator(pe.PortID)
}
// Vversion validates the version identifier in the path
func (pe *PathEnd) Vversion() error {
// TODO: version validation
return nil
}
func (pe PathEnd) String() string {
return fmt.Sprintf("%s:cl(%s):co(%s):ch(%s):pt(%s)", pe.ChainID, pe.ClientID, pe.ConnectionID, pe.ChannelID, pe.PortID)
}
// Validate returns errors about invalid identifiers as well as
// unset path variables for the appropriate type
func (pe *PathEnd) Validate() error {
if err := pe.Vclient(); err != nil {
return err
}
if err := pe.Vconn(); err != nil {
return err
}
if err := pe.Vchan(); err != nil {
return err
}
if err := pe.Vport(); err != nil {
return err
}
if !(strings.ToUpper(pe.Order) == "ORDERED" || strings.ToUpper(pe.Order) == "UNORDERED") {
return fmt.Errorf("channel must be either 'ORDERED' or 'UNORDERED' is '%s'", pe.Order)
}
return nil
}