-
Notifications
You must be signed in to change notification settings - Fork 22
/
object_change.go
282 lines (225 loc) · 4.98 KB
/
object_change.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package state
import (
"bytes"
"github.com/Venachain/Venachain/common"
"github.com/Venachain/Venachain/crypto"
)
//ObjectChange 用于记录state_object的变更内容
type ObjectChange interface {
change(*StateDB) //实际的变更内容
getAddr() common.Address //获取变更的地址
getObject() *stateObject //获取变更的stateobject
setVersion(version int)
getVersion() int
}
//CreateAccount 创建账户的变更操作
type CreateAccount struct {
account common.Address
prev *stateObject
newObj *stateObject
version int
}
func NewCreateAccount(po *stateObject, no *stateObject) *CreateAccount {
return &CreateAccount{
account: no.address,
prev: po,
newObj: no,
}
}
func (ca *CreateAccount) change(s *StateDB) {
if ca.prev != nil {
ca.newObj.setBalance(ca.prev.Balance())
}
}
func (ca *CreateAccount) getAddr() common.Address {
return ca.account
}
func (ca *CreateAccount) getObject() *stateObject {
return ca.newObj
}
func (ca *CreateAccount) getVersion() int {
return ca.version
}
func (ca *CreateAccount) setVersion(version int) {
ca.version = version
}
type SetCode struct {
address common.Address
obj *stateObject
code []byte
hash common.Hash
version int
}
func NewSetCode(stateObject *stateObject, addr common.Address, code []byte) *SetCode {
hashCode := crypto.Keccak256Hash(code)
return &SetCode{
address: addr,
obj: stateObject,
code: code,
hash: hashCode,
}
}
func (ca *SetCode) change(s *StateDB) {
ca.obj.setCode(ca.hash, ca.code)
}
func (ca *SetCode) getAddr() common.Address {
return ca.address
}
func (ca *SetCode) getObject() *stateObject {
return ca.obj
}
func (ca *SetCode) getVersion() int {
return ca.version
}
func (ca *SetCode) setVersion(version int) {
ca.version = version
}
type SetAbi struct {
address common.Address
obj *stateObject
code []byte
hash common.Hash
version int
}
func NewSetAbi(stateObject *stateObject, addr common.Address, code []byte) *SetAbi {
hashCode := crypto.Keccak256Hash(code)
return &SetAbi{
address: addr,
obj: stateObject,
code: code,
hash: hashCode,
}
}
func (ca *SetAbi) change(s *StateDB) {
ca.obj.setAbi(ca.hash, ca.code)
}
func (ca *SetAbi) getAddr() common.Address {
return ca.address
}
func (ca *SetAbi) getObject() *stateObject {
return ca.obj
}
func (ca *SetAbi) getVersion() int {
return ca.version
}
func (ca *SetAbi) setVersion(version int) {
ca.version = version
}
type Suicide struct {
address common.Address
obj *stateObject
version int
}
func NewSuicide(stateObject *stateObject, addr common.Address) *Suicide {
return &Suicide{
address: addr,
obj: stateObject,
}
}
func (ca *Suicide) change(s *StateDB) {
ca.obj.markSuicided()
s.deleteStateObject(ca.obj)
}
func (ca *Suicide) getAddr() common.Address {
return ca.address
}
func (ca *Suicide) getObject() *stateObject {
return ca.obj
}
func (ca *Suicide) getVersion() int {
return ca.version
}
func (ca *Suicide) setVersion(version int) {
ca.version = version
}
type SetFwData struct {
address common.Address
obj *stateObject
data FwData
version int
}
func NewSetFwData(object *stateObject, addr common.Address, data FwData) *SetFwData {
return &SetFwData{
address: addr,
obj: object,
data: data,
}
}
func (ca *SetFwData) change(s *StateDB) {
ca.obj.setFwData(ca.data)
}
func (ca *SetFwData) getAddr() common.Address {
return ca.address
}
func (ca *SetFwData) getObject() *stateObject {
return ca.obj
}
func (ca *SetFwData) getVersion() int {
return ca.version
}
func (ca *SetFwData) setVersion(version int) {
ca.version = version
}
type SetFwActive struct {
address common.Address
obj *stateObject
active uint64
version int
}
func NewSetFwActive(object *stateObject, addr common.Address, active uint64) *SetFwActive {
return &SetFwActive{
address: addr,
obj: object,
active: active,
}
}
func (ca *SetFwActive) change(s *StateDB) {
pre := ca.obj.data.FwActive
result := ca.active ^ pre
if result == 1 {
ca.obj.setFwActive(ca.active)
}
}
func (ca *SetFwActive) getAddr() common.Address {
return ca.address
}
func (ca *SetFwActive) getObject() *stateObject {
return ca.obj
}
func (ca *SetFwActive) getVersion() int {
return ca.version
}
func (ca SetFwActive) setVersion(version int) {
ca.version = version
}
type SetCreator struct {
address common.Address
obj *stateObject
creator common.Address
version int
}
func NewSetCreator(object *stateObject, addr common.Address, creator common.Address) *SetCreator {
return &SetCreator{
address: addr,
obj: object,
creator: creator,
}
}
func (ca *SetCreator) change(s *StateDB) {
if bytes.Equal(ca.obj.CodeHash(), emptyCodeHash) {
return
}
ca.obj.setContractCreator(ca.creator)
}
func (ca *SetCreator) getAddr() common.Address {
return ca.address
}
func (ca *SetCreator) getObject() *stateObject {
return ca.obj
}
func (ca *SetCreator) getVersion() int {
return ca.version
}
func (ca *SetCreator) setVersion(version int) {
ca.version = version
}