/
type_tag.go
54 lines (47 loc) · 1 KB
/
type_tag.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
package types
import (
"errors"
"strings"
"github.com/coming-chat/lcs"
)
func init() {
lcs.RegisterEnum(
(*TypeTag)(nil),
TypeTagBool{},
TypeTagU8{},
TypeTagU64{},
TypeTagU128{},
TypeTagAddress{},
TypeTagSigner{},
TypeTagVector{},
TypeTagStruct{},
)
}
type TypeTag interface{}
type TypeTagBool struct{}
type TypeTagU8 struct{}
type TypeTagU64 struct{}
type TypeTagU128 struct{}
type TypeTagAddress struct{}
type TypeTagSigner struct{}
type TypeTagVector struct {
Value TypeTag `lcs:"value"`
}
type TypeTagStruct struct {
Address Address `lcs:"address"`
ModuleName string `lcs:"module_name"`
Name string `lcs:"name"`
TypeArgs []TypeTag `lcs:"type_args"`
}
func NewTypeTagStructFromString(tag string) (*TypeTagStruct, error) {
parts := strings.Split(tag, "::")
if len(parts) != 3 {
return nil, errors.New("Invalid struct tag string")
}
addr := HexToAddress(parts[0])
return &TypeTagStruct{
Address: addr,
ModuleName: parts[1],
Name: parts[2],
}, nil
}