-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
58 lines (42 loc) · 1.04 KB
/
types.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
package rnsgo
import (
"github.com/go-resty/resty/v2"
"strings"
)
type RNS struct {
client *resty.Client
}
type Name string
func (n Name) String() string {
return string(n)
}
func (n Name) Valid() bool {
return strings.HasSuffix(string(n), RNSLabelSuffix) && len(strings.TrimSuffix(string(n), RNSLabelSuffix)) >= 3
}
type Address string
func (a Address) String() string {
return string(a)
}
func (a Address) Normalize() Address {
return Address(strings.Replace(string(a), RoninAddressPrefix, EthAddressPrefix, 1))
}
func (a Address) Valid() bool {
return strings.HasPrefix(string(a), EthAddressPrefix) && len(string(a)) == 42
}
type BatchRequest interface {
Route() string
}
type BatchAddressRequest struct {
Addresses []Address `json:"addresses"`
}
func (b *BatchAddressRequest) Route() string {
return "/batch/lookup"
}
type BatchNameRequest struct {
Names []Name `json:"names"`
}
func (b *BatchNameRequest) Route() string {
return "/batch/resolve"
}
type BatchAddressResponse map[Name]*Address
type BatchNameResponse map[Address]*Name