-
Notifications
You must be signed in to change notification settings - Fork 73
/
aspect_store_key.go
175 lines (149 loc) · 4.74 KB
/
aspect_store_key.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package types
import (
"bytes"
"encoding/binary"
"math"
"strings"
artela "github.com/artela-network/aspect-core/types"
"github.com/emirpasic/gods/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
)
var _ binary.ByteOrder
const (
// AspectCodeKeyPrefix is the prefix to retrieve all AspectCodeStore
AspectCodeKeyPrefix = "AspectStore/Code/"
AspectCodeVersionKeyPrefix = "AspectStore/Version/"
AspectPropertyKeyPrefix = "AspectStore/Property/"
ContractBindKeyPrefix = "AspectStore/ContractBind/"
VerifierBindingKeyPrefix = "AspectStore/VerifierBind/"
AspectRefKeyPrefix = "AspectStore/AspectRef/"
AspectBlockKeyPrefix = "AspectStore/Block/"
AspectStateKeyPrefix = "AspectStore/State/"
AspectJoinPointRunKeyPrefix = "AspectStore/JoinPointRun/"
AspectIdMapKey = "aspectId"
VersionMapKey = "version"
PriorityMapKey = "priority"
AspectStateBeginBlock = "State/BeginBlock"
AspectStateDeliverTxState = "State/DeliverTx"
AspectStateEndBlock = "State/EndBlock"
AspectAccountKey = "Aspect_@Acount@_"
AspectProofKey = "Aspect_@Proof@_"
AspectRunJoinPointKey = "Aspect_@Run@JoinPoint@_"
AspectPropertyAllKeyPrefix = "Aspect_@Property@AllKey@_"
AspectPropertyAllKeySplit = "^^^"
AspectPropertyLimit = math.MaxUint8
)
var (
PathSeparator = []byte("/")
PathSeparatorLen = len(PathSeparator)
)
func GetAspectStatePoint(point string) string {
if strings.EqualFold(point, string(artela.ON_BLOCK_INITIALIZE_METHOD)) {
return AspectStateBeginBlock
} else if strings.EqualFold(point, string(artela.ON_BLOCK_FINALIZE_METHOD)) {
return AspectStateEndBlock
} else if strings.EqualFold(point, string(artela.POST_TX_COMMIT)) ||
strings.EqualFold(point, string(artela.PRE_TX_EXECUTE_METHOD)) ||
strings.EqualFold(point, string(artela.POST_TX_EXECUTE_METHOD)) ||
strings.EqualFold(point, string(artela.PRE_CONTRACT_CALL_METHOD)) ||
strings.EqualFold(point, string(artela.POST_CONTRACT_CALL_METHOD)) ||
strings.EqualFold(point, string(artela.OPERATION_METHOD)) {
return AspectStateDeliverTxState
}
return ""
}
func AspectArrayKey(keys ...[]byte) []byte {
var key []byte
for _, b := range keys {
key = append(key, b...)
key = append(key, PathSeparator...)
}
return key
}
// AspectCodeStoreKey returns the store key to retrieve a AspectCodeStore from the index fields
func AspectPropertyKey(
aspectId []byte,
propertyKey []byte,
) []byte {
key := make([]byte, 0, len(aspectId)+PathSeparatorLen*2+len(propertyKey))
key = append(key, aspectId...)
key = append(key, PathSeparator...)
key = append(key, propertyKey...)
key = append(key, PathSeparator...)
return key
}
func AspectVersionKey(
aspectId []byte,
version []byte,
) []byte {
key := make([]byte, 0, len(aspectId)+PathSeparatorLen*2+len(version))
key = append(key, aspectId...)
key = append(key, PathSeparator...)
key = append(key, version...)
key = append(key, PathSeparator...)
return key
}
func AspectIdKey(
aspectId []byte,
) []byte {
key := make([]byte, 0, len(aspectId)+PathSeparatorLen)
key = append(key, aspectId...)
key = append(key, PathSeparator...)
return key
}
func AspectBlockKey() []byte {
var key []byte
key = append(key, []byte("AspectBlock")...)
key = append(key, PathSeparator...)
return key
}
func AccountKey(
account []byte,
) []byte {
key := make([]byte, 0, len(account)+PathSeparatorLen)
key = append(key, account...)
key = append(key, PathSeparator...)
return key
}
type AspectInfo struct {
AspectId common.Address `json:"AspectId"`
Version uint64 `json:"Version"`
Priority int8 `json:"Priority"`
}
type AspectMeta struct {
Id common.Address `json:"id"`
Version *uint256.Int `json:"version"`
Priority int64 `json:"priority"`
}
type Property struct {
Key string `json:"Key"`
Value []byte `json:"Value"`
}
type BoundAspectCode struct {
AspectId common.Address `json:"aspectId"`
Version *uint256.Int `json:"version"`
Priority int64 `json:"priority"`
Code []byte `json:"code"`
}
func ByMapKeyPriority(a, b interface{}) int {
priorityA, ok := a.(map[string]interface{})[PriorityMapKey]
if !ok {
priorityA = 0
}
priorityB, okb := b.(map[string]interface{})[PriorityMapKey]
if !okb {
priorityB = 1
}
return utils.IntComparator(priorityA, priorityB) // "-" descending order
}
func NewBindingPriorityComparator(x []*AspectMeta) func(i, j int) bool {
return func(i, j int) bool {
return x[i].Priority < x[j].Priority && (bytes.Compare(x[i].Id.Bytes(), x[j].Id.Bytes()) < 0)
}
}
func NewBindingAspectPriorityComparator(x []*artela.AspectCode) func(i, j int) bool {
return func(i, j int) bool {
return (x[i].Priority < x[j].Priority) && (strings.Compare(x[i].AspectId, x[j].AspectId) < 0)
}
}