This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
features.go
112 lines (102 loc) · 2.29 KB
/
features.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) 2020-2021 Blockwatch Data Inc.
// Author: alex@blockwatch.cc
package micheline
import (
"encoding/json"
"strings"
)
type Features uint16
const (
FeatureSpendable Features = 1 << iota
FeatureDelegatable
FeatureAccountFactory
FeatureContractFactory
FeatureSetDelegate
FeatureLambda
FeatureTransferTokens
FeatureChainId
FeatureTicket
FeatureSapling
FeatureView
FeatureGlobalConstant
FeatureTimelock
)
func (f Features) Contains(x Features) bool {
return f&x > 0
}
func (f Features) String() string {
return strings.Join(f.Array(), ",")
}
func (f Features) Array() []string {
s := make([]string, 0)
var i Features = 1
for f > 0 {
switch f & i {
case FeatureAccountFactory:
s = append(s, "account_factory")
case FeatureContractFactory:
s = append(s, "contract_factory")
case FeatureSetDelegate:
s = append(s, "set_delegate")
case FeatureLambda:
s = append(s, "lambda")
case FeatureTransferTokens:
s = append(s, "transfer_tokens")
case FeatureChainId:
s = append(s, "chain_id")
case FeatureTicket:
s = append(s, "ticket")
case FeatureSapling:
s = append(s, "sapling")
case FeatureView:
s = append(s, "view")
case FeatureGlobalConstant:
s = append(s, "global_constant")
case FeatureTimelock:
s = append(s, "timelock")
}
f &= ^i
i <<= 1
}
return s
}
func (f Features) MarshalJSON() ([]byte, error) {
return json.Marshal(f.Array())
}
func (s *Script) Features() Features {
return s.Code.Param.Features() |
s.Code.Storage.Features() |
s.Code.Code.Features() |
s.Code.View.Features()
}
func (p Prim) Features() Features {
var f Features
_ = p.Walk(func(p Prim) error {
switch p.OpCode {
case I_CREATE_ACCOUNT:
f |= FeatureAccountFactory
case I_CREATE_CONTRACT:
f |= FeatureContractFactory
case I_SET_DELEGATE:
f |= FeatureSetDelegate
case I_LAMBDA, I_EXEC, I_APPLY:
f |= FeatureLambda
case I_TRANSFER_TOKENS:
f |= FeatureTransferTokens
case I_CHAIN_ID:
f |= FeatureChainId
case I_TICKET, I_READ_TICKET, I_SPLIT_TICKET, I_JOIN_TICKETS:
f |= FeatureTicket
case I_SAPLING_VERIFY_UPDATE:
f |= FeatureSapling
case H_CONSTANT:
f |= FeatureGlobalConstant
case K_VIEW:
f |= FeatureView
case T_CHEST_KEY, T_CHEST, I_OPEN_CHEST:
f |= FeatureTimelock
}
return nil
})
return f
}