-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
chaintype.go
64 lines (53 loc) · 1.59 KB
/
chaintype.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
package chaintype
import (
"fmt"
"strings"
"github.com/pkg/errors"
)
// ChainType denotes the chain or network to work with
type ChainType string
const (
// EVM for Ethereum or other chains supporting the EVM
EVM ChainType = "evm"
// Solana for the Solana chain
Solana ChainType = "solana"
// Terra for the Terra chain
Terra ChainType = "terra"
// StarkNet for the StarkNet chain
StarkNet ChainType = "starknet"
)
type ChainTypes []ChainType
func (c ChainTypes) String() (out string) {
var sb strings.Builder
for i, chain := range c {
if i != 0 {
sb.WriteString(", ")
}
sb.WriteString(string(chain))
}
return sb.String()
}
// SupportedChainTypes contain all chains that are supported
var SupportedChainTypes = ChainTypes{EVM, Solana, Terra, StarkNet}
// ErrInvalidChainType is an error to indicate an unsupported chain type
var ErrInvalidChainType error
func init() {
supported := make([]string, 0, len(SupportedChainTypes))
for _, chainType := range SupportedChainTypes {
supported = append(supported, fmt.Sprintf(`"%s"`, chainType))
}
ErrInvalidChainType = fmt.Errorf("valid types include: [%s]", strings.Join(supported, ", "))
}
// IsSupportedChainType checks to see if the chain is supported
func IsSupportedChainType(chainType ChainType) bool {
for _, v := range SupportedChainTypes {
if v == chainType {
return true
}
}
return false
}
// NewErrInvalidChainType returns an error wrapping ErrInvalidChainType for an unsupported chain
func NewErrInvalidChainType(chainType ChainType) error {
return errors.Wrapf(ErrInvalidChainType, `unknown chain type "%s"`, chainType)
}