/
result.go
204 lines (167 loc) · 5.4 KB
/
result.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
/*
* Copyright 2019 Insolar Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package record
import (
"io"
"github.com/insolar/insolar/core"
)
// State is a state of lifeline records.
type State int
const (
// StateUndefined is used for special cases.
StateUndefined = State(iota)
// StateActivation means it's an activation record.
StateActivation
// StateAmend means it's an amend record.
StateAmend
// StateDeactivation means it's a deactivation record.
StateDeactivation
)
// ObjectState is common object state record.
type ObjectState interface {
// State returns state id.
State() State
// GetImage returns state code.
GetImage() *core.RecordRef
// GetIsPrototype returns state code.
GetIsPrototype() bool
// GetMemory returns state memory.
GetMemory() *core.RecordID
// PrevStateID returns previous state id.
PrevStateID() *core.RecordID
}
// ResultRecord represents result of a VM method.
type ResultRecord struct {
Object core.RecordID
Request core.RecordRef
Payload []byte
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *ResultRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// SideEffectRecord is a record which is created in response to a request.
type SideEffectRecord struct {
Domain core.RecordRef
Request core.RecordRef
}
// TypeRecord is a code interface declaration.
type TypeRecord struct {
SideEffectRecord
TypeDeclaration []byte
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *TypeRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// CodeRecord is a code storage record.
type CodeRecord struct {
SideEffectRecord
Code *core.RecordID
MachineType core.MachineType
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *CodeRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// ObjectStateRecord is a record containing data for an object state.
type ObjectStateRecord struct {
Memory *core.RecordID
Image core.RecordRef // If code or prototype object reference.
IsPrototype bool // If true, Image should point to a prototype object. Otherwise to a code.
}
// GetMemory returns state memory.
func (r *ObjectStateRecord) GetMemory() *core.RecordID {
return r.Memory
}
// GetImage returns state code.
func (r *ObjectStateRecord) GetImage() *core.RecordRef {
return &r.Image
}
// GetIsPrototype returns state code.
func (r *ObjectStateRecord) GetIsPrototype() bool {
return r.IsPrototype
}
// ObjectActivateRecord is produced when we instantiate new object from an available prototype.
type ObjectActivateRecord struct {
SideEffectRecord
ObjectStateRecord
Parent core.RecordRef
IsDelegate bool
}
// PrevStateID returns previous state id.
func (r *ObjectActivateRecord) PrevStateID() *core.RecordID {
return nil
}
// State returns state id.
func (r *ObjectActivateRecord) State() State {
return StateActivation
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *ObjectActivateRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// ObjectAmendRecord is an amendment record for objects.
type ObjectAmendRecord struct {
SideEffectRecord
ObjectStateRecord
PrevState core.RecordID
}
// PrevStateID returns previous state id.
func (r *ObjectAmendRecord) PrevStateID() *core.RecordID {
return &r.PrevState
}
// State returns state id.
func (r *ObjectAmendRecord) State() State {
return StateAmend
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *ObjectAmendRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// DeactivationRecord marks targeted object as disabled.
type DeactivationRecord struct {
SideEffectRecord
PrevState core.RecordID
}
// PrevStateID returns previous state id.
func (r *DeactivationRecord) PrevStateID() *core.RecordID {
return &r.PrevState
}
// State returns state id.
func (r *DeactivationRecord) State() State {
return StateDeactivation
}
// WriteHashData writes record data to provided writer. This data is used to calculate record's hash.
func (r *DeactivationRecord) WriteHashData(w io.Writer) (int, error) {
return w.Write(SerializeRecord(r))
}
// GetMachineType returns state code machine type.
func (*DeactivationRecord) GetMachineType() core.MachineType {
return core.MachineTypeNotExist
}
// GetMemory returns state memory.
func (*DeactivationRecord) GetMemory() *core.RecordID {
return nil
}
// GetImage returns state code.
func (r *DeactivationRecord) GetImage() *core.RecordRef {
return nil
}
// GetIsPrototype returns state code.
func (r *DeactivationRecord) GetIsPrototype() bool {
return false
}