-
Notifications
You must be signed in to change notification settings - Fork 0
/
noderecord.go
367 lines (291 loc) · 8.18 KB
/
noderecord.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*
* 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 noderecord
import (
"github.com/insolar/insolar/core"
"github.com/insolar/insolar/logicrunner/goplugin/foundation"
"github.com/insolar/insolar/logicrunner/goplugin/proxyctx"
)
type RecordInfo struct {
PublicKey string
Role core.StaticRole
}
// PrototypeReference to prototype of this contract
// error checking hides in generator
var PrototypeReference, _ = core.NewRefFromBase58("11113YT8a5p5H4GizfBz74yNVfzCRzuByNZxcNEm2PU.11111111111111111111111111111111")
// NodeRecord holds proxy type
type NodeRecord struct {
Reference core.RecordRef
Prototype core.RecordRef
Code core.RecordRef
}
// ContractConstructorHolder holds logic with object construction
type ContractConstructorHolder struct {
constructorName string
argsSerialized []byte
}
// AsChild saves object as child
func (r *ContractConstructorHolder) AsChild(objRef core.RecordRef) (*NodeRecord, error) {
ref, err := proxyctx.Current.SaveAsChild(objRef, *PrototypeReference, r.constructorName, r.argsSerialized)
if err != nil {
return nil, err
}
return &NodeRecord{Reference: ref}, nil
}
// AsDelegate saves object as delegate
func (r *ContractConstructorHolder) AsDelegate(objRef core.RecordRef) (*NodeRecord, error) {
ref, err := proxyctx.Current.SaveAsDelegate(objRef, *PrototypeReference, r.constructorName, r.argsSerialized)
if err != nil {
return nil, err
}
return &NodeRecord{Reference: ref}, nil
}
// GetObject returns proxy object
func GetObject(ref core.RecordRef) (r *NodeRecord) {
return &NodeRecord{Reference: ref}
}
// GetPrototype returns reference to the prototype
func GetPrototype() core.RecordRef {
return *PrototypeReference
}
// GetImplementationFrom returns proxy to delegate of given type
func GetImplementationFrom(object core.RecordRef) (*NodeRecord, error) {
ref, err := proxyctx.Current.GetDelegate(object, *PrototypeReference)
if err != nil {
return nil, err
}
return GetObject(ref), nil
}
// NewNodeRecord is constructor
func NewNodeRecord(publicKey string, roleStr string) *ContractConstructorHolder {
var args [2]interface{}
args[0] = publicKey
args[1] = roleStr
var argsSerialized []byte
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
panic(err)
}
return &ContractConstructorHolder{constructorName: "NewNodeRecord", argsSerialized: argsSerialized}
}
// GetReference returns reference of the object
func (r *NodeRecord) GetReference() core.RecordRef {
return r.Reference
}
// GetPrototype returns reference to the code
func (r *NodeRecord) GetPrototype() (core.RecordRef, error) {
if r.Prototype.IsEmpty() {
ret := [2]interface{}{}
var ret0 core.RecordRef
ret[0] = &ret0
var ret1 *foundation.Error
ret[1] = &ret1
res, err := proxyctx.Current.RouteCall(r.Reference, true, "GetPrototype", make([]byte, 0), *PrototypeReference)
if err != nil {
return ret0, err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return ret0, err
}
if ret1 != nil {
return ret0, ret1
}
r.Prototype = ret0
}
return r.Prototype, nil
}
// GetCode returns reference to the code
func (r *NodeRecord) GetCode() (core.RecordRef, error) {
if r.Code.IsEmpty() {
ret := [2]interface{}{}
var ret0 core.RecordRef
ret[0] = &ret0
var ret1 *foundation.Error
ret[1] = &ret1
res, err := proxyctx.Current.RouteCall(r.Reference, true, "GetCode", make([]byte, 0), *PrototypeReference)
if err != nil {
return ret0, err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return ret0, err
}
if ret1 != nil {
return ret0, ret1
}
r.Code = ret0
}
return r.Code, nil
}
// GetNodeInfo is proxy generated method
func (r *NodeRecord) GetNodeInfo() (RecordInfo, error) {
var args [0]interface{}
var argsSerialized []byte
ret := [2]interface{}{}
var ret0 RecordInfo
ret[0] = &ret0
var ret1 *foundation.Error
ret[1] = &ret1
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return ret0, err
}
res, err := proxyctx.Current.RouteCall(r.Reference, true, "GetNodeInfo", argsSerialized, *PrototypeReference)
if err != nil {
return ret0, err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return ret0, err
}
if ret1 != nil {
return ret0, ret1
}
return ret0, nil
}
// GetNodeInfoNoWait is proxy generated method
func (r *NodeRecord) GetNodeInfoNoWait() error {
var args [0]interface{}
var argsSerialized []byte
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return err
}
_, err = proxyctx.Current.RouteCall(r.Reference, false, "GetNodeInfo", argsSerialized, *PrototypeReference)
if err != nil {
return err
}
return nil
}
// GetPublicKey is proxy generated method
func (r *NodeRecord) GetPublicKey() (string, error) {
var args [0]interface{}
var argsSerialized []byte
ret := [2]interface{}{}
var ret0 string
ret[0] = &ret0
var ret1 *foundation.Error
ret[1] = &ret1
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return ret0, err
}
res, err := proxyctx.Current.RouteCall(r.Reference, true, "GetPublicKey", argsSerialized, *PrototypeReference)
if err != nil {
return ret0, err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return ret0, err
}
if ret1 != nil {
return ret0, ret1
}
return ret0, nil
}
// GetPublicKeyNoWait is proxy generated method
func (r *NodeRecord) GetPublicKeyNoWait() error {
var args [0]interface{}
var argsSerialized []byte
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return err
}
_, err = proxyctx.Current.RouteCall(r.Reference, false, "GetPublicKey", argsSerialized, *PrototypeReference)
if err != nil {
return err
}
return nil
}
// GetRole is proxy generated method
func (r *NodeRecord) GetRole() (core.StaticRole, error) {
var args [0]interface{}
var argsSerialized []byte
ret := [2]interface{}{}
var ret0 core.StaticRole
ret[0] = &ret0
var ret1 *foundation.Error
ret[1] = &ret1
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return ret0, err
}
res, err := proxyctx.Current.RouteCall(r.Reference, true, "GetRole", argsSerialized, *PrototypeReference)
if err != nil {
return ret0, err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return ret0, err
}
if ret1 != nil {
return ret0, ret1
}
return ret0, nil
}
// GetRoleNoWait is proxy generated method
func (r *NodeRecord) GetRoleNoWait() error {
var args [0]interface{}
var argsSerialized []byte
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return err
}
_, err = proxyctx.Current.RouteCall(r.Reference, false, "GetRole", argsSerialized, *PrototypeReference)
if err != nil {
return err
}
return nil
}
// Destroy is proxy generated method
func (r *NodeRecord) Destroy() error {
var args [0]interface{}
var argsSerialized []byte
ret := [1]interface{}{}
var ret0 *foundation.Error
ret[0] = &ret0
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return err
}
res, err := proxyctx.Current.RouteCall(r.Reference, true, "Destroy", argsSerialized, *PrototypeReference)
if err != nil {
return err
}
err = proxyctx.Current.Deserialize(res, &ret)
if err != nil {
return err
}
if ret0 != nil {
return ret0
}
return nil
}
// DestroyNoWait is proxy generated method
func (r *NodeRecord) DestroyNoWait() error {
var args [0]interface{}
var argsSerialized []byte
err := proxyctx.Current.Serialize(args, &argsSerialized)
if err != nil {
return err
}
_, err = proxyctx.Current.RouteCall(r.Reference, false, "Destroy", argsSerialized, *PrototypeReference)
if err != nil {
return err
}
return nil
}