-
Notifications
You must be signed in to change notification settings - Fork 2
/
operations.go
628 lines (519 loc) · 19.1 KB
/
operations.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
package proto_012_Psithaca
//go:generate go run ../../cmd/genmarshaller.go
import (
"math/big"
tz "github.com/ecadlabs/gotez/v2"
"github.com/ecadlabs/gotez/v2/encoding"
"github.com/ecadlabs/gotez/v2/protocol/core"
"github.com/ecadlabs/gotez/v2/protocol/core/expression"
)
//json:kind=OperationKind()
type ActivateAccount struct {
PKH *tz.Ed25519PublicKeyHash `json:"pkh"`
Secret *tz.Bytes20 `json:"secret"`
}
func (*ActivateAccount) OperationKind() string { return "activate_account" }
//json:kind=OperationKind()
type Proposals struct {
Source tz.PublicKeyHash `json:"source"`
Period int32 `json:"period"`
Proposals []*tz.ProtocolHash `tz:"dyn" json:"proposals"`
}
var _ core.OperationWithSource = (*Proposals)(nil)
func (*Proposals) OperationKind() string { return "proposals" }
func (p *Proposals) GetSource() core.TransactionDestination {
return core.ImplicitContract{PublicKeyHash: p.Source}
}
func (*Proposals) OperationContentsAndResult() {}
func (op *Proposals) GetMetadata() any { return op }
//json:kind=OperationKind()
type Ballot struct {
Source tz.PublicKeyHash `json:"source"`
Period int32 `json:"period"`
Proposal *tz.ProtocolHash `json:"proposal"`
Ballot core.BallotKind `json:"ballot"`
}
var _ core.OperationWithSource = (*Ballot)(nil)
func (op *Ballot) GetSource() core.TransactionDestination {
return core.ImplicitContract{PublicKeyHash: op.Source}
}
func (*Ballot) OperationKind() string { return "ballot" }
func (*Ballot) OperationContentsAndResult() {}
func (op *Ballot) GetMetadata() any { return op }
type ManagerOperation struct {
Source tz.PublicKeyHash `json:"source"`
Fee tz.BigUint `json:"fee"`
Counter tz.BigUint `json:"counter"`
GasLimit tz.BigUint `json:"gas_limit"`
StorageLimit tz.BigUint `json:"storage_limit"`
}
func (m *ManagerOperation) GetSource() core.TransactionDestination {
return core.ImplicitContract{PublicKeyHash: m.Source}
}
func (m *ManagerOperation) GetSourceAddress() tz.PublicKeyHash { return m.Source }
func (m *ManagerOperation) GetFee() tz.BigUint { return m.Fee }
func (m *ManagerOperation) GetCounter() tz.BigUint { return m.Counter }
func (m *ManagerOperation) GetGasLimit() tz.BigUint { return m.GasLimit }
func (m *ManagerOperation) GetStorageLimit() tz.BigUint { return m.StorageLimit }
func (m *ManagerOperation) SetFee(v tz.BigUint) { m.Fee = v }
func (m *ManagerOperation) SetCounter(v tz.BigUint) { m.Counter = v }
func (m *ManagerOperation) SetGasLimit(v tz.BigUint) { m.GasLimit = v }
func (m *ManagerOperation) SetStorageLimit(v tz.BigUint) { m.StorageLimit = v }
type Script struct {
Code expression.Expression `tz:"dyn" json:"code"`
Storage expression.Expression `tz:"dyn" json:"storage"`
}
//json:kind=OperationKind()
type Delegation struct {
ManagerOperation
Delegate tz.Option[tz.PublicKeyHash] `json:"delegate"`
}
func (*Delegation) OperationKind() string { return "delegation" }
//json:kind=OperationKind()
type Reveal struct {
ManagerOperation
PublicKey tz.PublicKey `json:"public_key"`
}
func (*Reveal) OperationKind() string { return "reveal" }
//json:kind=OperationKind()
type SeedNonceRevelation struct {
Level int32 `json:"level"`
Nonce *tz.SeedNonce `json:"nonce"`
}
func (*SeedNonceRevelation) OperationKind() string { return "seed_nonce_revelation" }
//json:kind=OperationKind()
type FailingNoop struct {
Arbitrary tz.Bytes `tz:"dyn" json:"arbitrary"`
}
func (*FailingNoop) OperationKind() string { return "failing_noop" }
//json:kind=OperationKind()
type RegisterGlobalConstant struct {
ManagerOperation
Value expression.Expression `tz:"dyn" json:"value"`
}
func (*RegisterGlobalConstant) OperationKind() string { return "register_global_constant" }
//json:kind=OperationKind()
type SetDepositsLimit struct {
ManagerOperation
Limit tz.Option[tz.BigUint] `json:"limit"`
}
func (*SetDepositsLimit) OperationKind() string { return "set_deposits_limit" }
//json:kind=OperationKind()
type Endorsement struct {
Slot uint16 `json:"slot"`
Level int32 `json:"level"`
Round int32 `json:"round"`
BlockPayloadHash *tz.BlockPayloadHash `json:"block_payload_hash"`
}
func (*Endorsement) InlinedEndorsementContents() {}
func (*Endorsement) OperationKind() string { return "endorsement" }
type InlinedEndorsement struct {
Branch *tz.BlockHash `json:"branch"`
Contents InlinedEndorsementContents `json:"contents"`
Signature tz.AnySignature `json:"signature"`
}
type InlinedEndorsementContents interface {
InlinedEndorsementContents()
}
func init() {
encoding.RegisterEnum(&encoding.Enum[InlinedEndorsementContents]{
Variants: encoding.Variants[InlinedEndorsementContents]{
21: (*Endorsement)(nil),
},
})
}
//json:kind=OperationKind()
type DoubleEndorsementEvidence struct {
Op1 InlinedEndorsement `tz:"dyn" json:"op1"`
Op2 InlinedEndorsement `tz:"dyn" json:"op2"`
}
func (*DoubleEndorsementEvidence) OperationKind() string { return "double_endorsement_evidence" }
//json:kind=OperationKind()
type DoublePreendorsementEvidence struct {
Op1 InlinedPreendorsement `tz:"dyn" json:"op1"`
Op2 InlinedPreendorsement `tz:"dyn" json:"op2"`
}
func (*DoublePreendorsementEvidence) OperationKind() string { return "double_preendorsement_evidence" }
type InlinedPreendorsement struct {
Branch *tz.BlockHash `json:"branch"`
Contents InlinedPreendorsementContents `json:"contents"`
Signature *tz.GenericSignature `json:"signature"`
}
type InlinedPreendorsementContents interface {
InlinedPreendorsementContents()
}
func init() {
encoding.RegisterEnum(&encoding.Enum[InlinedPreendorsementContents]{
Variants: encoding.Variants[InlinedPreendorsementContents]{
20: (*Preendorsement)(nil),
},
})
}
//json:kind=OperationKind()
type Preendorsement Endorsement
func (*Preendorsement) InlinedPreendorsementContents() {}
func (*Preendorsement) OperationKind() string { return "preendorsement" }
//json:kind=OperationKind()
type DoubleBakingEvidence struct {
Block1 BlockHeader `tz:"dyn" json:"block1"`
Block2 BlockHeader `tz:"dyn" json:"block2"`
}
func (*DoubleBakingEvidence) OperationKind() string { return "double_baking_evidence" }
type OperationContents interface {
core.OperationContents
}
func init() {
encoding.RegisterEnum(&encoding.Enum[OperationContents]{
Variants: encoding.Variants[OperationContents]{
1: (*SeedNonceRevelation)(nil),
2: (*DoubleEndorsementEvidence)(nil),
3: (*DoubleBakingEvidence)(nil),
4: (*ActivateAccount)(nil),
5: (*Proposals)(nil),
6: (*Ballot)(nil),
7: (*DoublePreendorsementEvidence)(nil),
17: (*FailingNoop)(nil),
20: (*Preendorsement)(nil),
21: (*Endorsement)(nil),
107: (*Reveal)(nil),
108: (*Transaction)(nil),
109: (*Origination)(nil),
110: (*Delegation)(nil),
111: (*RegisterGlobalConstant)(nil),
112: (*SetDepositsLimit)(nil),
},
})
}
//json:kind=OperationKind()
type SeedNonceRevelationContentsAndResult struct {
SeedNonceRevelation
Metadata BalanceUpdates `json:"metadata"`
}
func (*SeedNonceRevelationContentsAndResult) OperationContentsAndResult() {}
func (op *SeedNonceRevelationContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type DoubleEndorsementEvidenceContentsAndResult struct {
DoubleEndorsementEvidence
Metadata BalanceUpdates `json:"metadata"`
}
func (*DoubleEndorsementEvidenceContentsAndResult) OperationContentsAndResult() {}
func (op *DoubleEndorsementEvidenceContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type DoubleBakingEvidenceContentsAndResult struct {
DoubleBakingEvidence
Metadata BalanceUpdates `json:"metadata"`
}
func (*DoubleBakingEvidenceContentsAndResult) OperationContentsAndResult() {}
func (op *DoubleBakingEvidenceContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type ActivateAccountContentsAndResult struct {
ActivateAccount
Metadata BalanceUpdates `json:"metadata"`
}
func (*ActivateAccountContentsAndResult) OperationContentsAndResult() {}
func (op *ActivateAccountContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type DoublePreendorsementEvidenceContentsAndResult struct {
DoublePreendorsementEvidence
Metadata BalanceUpdates `json:"metadata"`
}
func (*DoublePreendorsementEvidenceContentsAndResult) OperationContentsAndResult() {}
func (op *DoublePreendorsementEvidenceContentsAndResult) GetMetadata() any {
return &op.Metadata
}
type EndorsementMetadata struct {
BalanceUpdates
Delegate tz.PublicKeyHash `json:"delegate"`
EndorsementPower int32 `json:"endorsement_power"`
}
//json:kind=OperationKind()
type EndorsementContentsAndResult struct {
Endorsement
Metadata EndorsementMetadata `json:"metadata"`
}
func (*EndorsementContentsAndResult) OperationContentsAndResult() {}
func (op *EndorsementContentsAndResult) GetMetadata() any {
return &op.Metadata
}
type PreendorsementMetadata = EndorsementMetadata
//json:kind=OperationKind()
type PreendorsementContentsAndResult struct {
Preendorsement
Metadata PreendorsementMetadata `json:"metadata"`
}
func (*PreendorsementContentsAndResult) OperationContentsAndResult() {}
func (op *PreendorsementContentsAndResult) GetMetadata() any {
return &op.Metadata
}
type OperationContentsAndResult interface {
core.OperationContentsAndResult
}
type ConsumedGasResultContents struct {
ConsumedGas tz.BigUint `json:"consumed_gas"`
ConsumedMilligas tz.BigUint `json:"consumed_milligas"`
}
func (r *ConsumedGasResultContents) GetConsumedMilligas() tz.BigUint { return r.ConsumedMilligas }
type ConsumedGasResult interface {
core.ManagerOperationResult
}
func init() {
encoding.RegisterEnum(&encoding.Enum[ConsumedGasResult]{
Variants: encoding.Variants[ConsumedGasResult]{
0: (*core.OperationResultApplied[*ConsumedGasResultContents])(nil),
1: (*core.OperationResultFailed)(nil),
2: (*core.OperationResultSkipped)(nil),
3: (*core.OperationResultBacktracked[*ConsumedGasResultContents])(nil),
},
})
}
type RevealResultContents = ConsumedGasResultContents
//json:kind=OperationKind()
type RevealSuccessfulManagerResult struct {
core.OperationResultApplied[*ConsumedGasResultContents]
}
func (*RevealSuccessfulManagerResult) OperationKind() string { return "reveal" }
//json:kind=OperationKind()
type RevealContentsAndResult struct {
Reveal
Metadata ManagerMetadata[ConsumedGasResult] `json:"metadata"`
}
func (*RevealContentsAndResult) OperationContentsAndResult() {}
func (op *RevealContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type DelegationContentsAndResult struct {
Delegation
Metadata ManagerMetadata[ConsumedGasResult] `json:"metadata"`
}
func (*DelegationContentsAndResult) OperationContentsAndResult() {}
func (op *DelegationContentsAndResult) GetMetadata() any {
return &op.Metadata
}
type DelegationResultContents = ConsumedGasResultContents
//json:kind=OperationKind()
type DelegationSuccessfulManagerResult struct {
core.OperationResultApplied[*ConsumedGasResultContents]
}
func (*DelegationSuccessfulManagerResult) OperationKind() string { return "delegation" }
type SetDepositsLimitResultContents = ConsumedGasResultContents
//json:kind=OperationKind()
type SetDepositsLimitSuccessfulManagerResult struct {
core.OperationResultApplied[*ConsumedGasResultContents]
}
func (*SetDepositsLimitSuccessfulManagerResult) OperationKind() string { return "set_deposits_limit" }
type RegisterGlobalConstantResultContents struct {
BalanceUpdates
ConsumedGas tz.BigUint `json:"consumed_gas"`
StorageSize tz.BigInt `json:"storage_size"`
GlobalAddress *tz.ScriptExprHash `json:"global_address"`
}
func (r *RegisterGlobalConstantResultContents) GetConsumedMilligas() tz.BigUint {
x := r.ConsumedGas.Int()
x.Mul(x, big.NewInt(1000))
v, _ := tz.NewBigUint(x)
return v
}
func (r *RegisterGlobalConstantResultContents) GetStorageSize() tz.BigInt { return r.StorageSize }
func (r *RegisterGlobalConstantResultContents) EstimateStorageSize(constants core.Constants) *big.Int {
return r.StorageSize.Int()
}
type RegisterGlobalConstantResult interface {
core.ManagerOperationResult
}
func init() {
encoding.RegisterEnum(&encoding.Enum[RegisterGlobalConstantResult]{
Variants: encoding.Variants[RegisterGlobalConstantResult]{
0: (*core.OperationResultApplied[*RegisterGlobalConstantResultContents])(nil),
1: (*core.OperationResultFailed)(nil),
2: (*core.OperationResultSkipped)(nil),
3: (*core.OperationResultBacktracked[*RegisterGlobalConstantResultContents])(nil),
},
})
}
//json:kind=OperationKind()
type RegisterGlobalConstantContentsAndResult struct {
RegisterGlobalConstant
Metadata ManagerMetadata[RegisterGlobalConstantResult] `json:"metadata"`
}
func (*RegisterGlobalConstantContentsAndResult) OperationContentsAndResult() {}
func (op *RegisterGlobalConstantContentsAndResult) GetMetadata() any {
return &op.Metadata
}
//json:kind=OperationKind()
type SetDepositsLimitContentsAndResult struct {
SetDepositsLimit
Metadata ManagerMetadata[ConsumedGasResult] `json:"metadata"`
}
func (*SetDepositsLimitContentsAndResult) OperationContentsAndResult() {}
func (op *SetDepositsLimitContentsAndResult) GetMetadata() any {
return &op.Metadata
}
func init() {
encoding.RegisterEnum(&encoding.Enum[OperationContentsAndResult]{
Variants: encoding.Variants[OperationContentsAndResult]{
1: (*SeedNonceRevelationContentsAndResult)(nil),
2: (*DoubleEndorsementEvidenceContentsAndResult)(nil),
3: (*DoubleBakingEvidenceContentsAndResult)(nil),
4: (*ActivateAccountContentsAndResult)(nil),
5: (*Proposals)(nil),
6: (*Ballot)(nil),
7: (*DoublePreendorsementEvidenceContentsAndResult)(nil),
20: (*PreendorsementContentsAndResult)(nil),
21: (*EndorsementContentsAndResult)(nil),
107: (*RevealContentsAndResult)(nil),
108: (*TransactionContentsAndResult)(nil),
109: (*OriginationContentsAndResult)(nil),
110: (*DelegationContentsAndResult)(nil),
111: (*RegisterGlobalConstantContentsAndResult)(nil),
112: (*SetDepositsLimitContentsAndResult)(nil),
},
})
}
type ManagerMetadata[T core.ManagerOperationResult] struct {
BalanceUpdates
OperationResult T `json:"operation_result"`
InternalOperationResults []InternalOperationResult `tz:"dyn" json:"internal_operation_results"`
}
func (m *ManagerMetadata[T]) GetResult() core.ManagerOperationResult {
return m.OperationResult
}
func (m *ManagerMetadata[T]) GetInternalOperationResults() []core.InternalOperationResult {
out := make([]core.InternalOperationResult, len(m.InternalOperationResults))
for i, r := range m.InternalOperationResults {
out[i] = r
}
return out
}
//json:kind=OperationKind()
type DelegationInternalOperationResult struct {
Source core.ContractID `json:"source"`
Nonce uint16 `json:"nonce"`
Delegate tz.Option[tz.PublicKeyHash] `json:"delegate"`
Result ConsumedGasResult `json:"result"`
}
var _ core.InternalOperationResult = (*DelegationInternalOperationResult)(nil)
func (r *DelegationInternalOperationResult) GetSource() core.TransactionDestination {
switch d := r.Source.(type) {
case core.ImplicitContract:
return d
case core.OriginatedContract:
return d
default:
panic("unexpected contract id type")
}
}
func (r *DelegationInternalOperationResult) GetResult() core.ManagerOperationResult {
return r.Result
}
func (*DelegationInternalOperationResult) OperationKind() string { return "delegation" }
//json:kind=OperationKind()
type RevealInternalOperationResult struct {
Source core.ContractID `json:"source"`
Nonce uint16 `json:"nonce"`
PublicKey tz.PublicKey `json:"public_key"`
Result ConsumedGasResult `json:"result"`
}
var _ core.InternalOperationResult = (*RevealInternalOperationResult)(nil)
func (r *RevealInternalOperationResult) GetSource() core.TransactionDestination {
switch d := r.Source.(type) {
case core.ImplicitContract:
return d
case core.OriginatedContract:
return d
default:
panic("unexpected contract id type")
}
}
func (r *RevealInternalOperationResult) GetResult() core.ManagerOperationResult {
return r.Result
}
func (*RevealInternalOperationResult) OperationKind() string { return "reveal" }
//json:kind=OperationKind()
type RegisterGlobalConstantInternalOperationResult struct {
Source core.ContractID `json:"source"`
Nonce uint16 `json:"nonce"`
Value expression.Expression `tz:"dyn" json:"value"`
Result RegisterGlobalConstantResult `json:"result"`
}
var _ core.InternalOperationResult = (*RegisterGlobalConstantInternalOperationResult)(nil)
func (r *RegisterGlobalConstantInternalOperationResult) GetSource() core.TransactionDestination {
switch d := r.Source.(type) {
case core.ImplicitContract:
return d
case core.OriginatedContract:
return d
default:
panic("unexpected contract id type")
}
}
func (*RegisterGlobalConstantInternalOperationResult) OperationKind() string {
return "register_global_constant"
}
func (r *RegisterGlobalConstantInternalOperationResult) GetResult() core.ManagerOperationResult {
return r.Result
}
//json:kind=OperationKind()
type SetDepositsLimitInternalOperationResult struct {
Source core.ContractID `json:"source"`
Nonce uint16 `json:"nonce"`
Limit tz.Option[tz.BigUint] `json:"limit"`
Result ConsumedGasResult `json:"result"`
}
var _ core.InternalOperationResult = (*SetDepositsLimitInternalOperationResult)(nil)
func (r *SetDepositsLimitInternalOperationResult) GetSource() core.TransactionDestination {
switch d := r.Source.(type) {
case core.ImplicitContract:
return d
case core.OriginatedContract:
return d
default:
panic("unexpected contract id type")
}
}
func (*SetDepositsLimitInternalOperationResult) OperationKind() string {
return "set_deposits_limit"
}
func (r *SetDepositsLimitInternalOperationResult) GetResult() core.ManagerOperationResult {
return r.Result
}
type InternalOperationResult interface {
core.InternalOperationResult
}
func init() {
encoding.RegisterEnum(&encoding.Enum[InternalOperationResult]{
Variants: encoding.Variants[InternalOperationResult]{
0: (*RevealInternalOperationResult)(nil),
1: (*TransactionInternalOperationResult)(nil),
2: (*OriginationInternalOperationResult)(nil),
3: (*DelegationInternalOperationResult)(nil),
4: (*RegisterGlobalConstantInternalOperationResult)(nil),
5: (*SetDepositsLimitInternalOperationResult)(nil),
},
})
}
type SuccessfulManagerOperationResult interface {
core.SuccessfulManagerOperationResult
}
func init() {
encoding.RegisterEnum(&encoding.Enum[SuccessfulManagerOperationResult]{
Variants: encoding.Variants[SuccessfulManagerOperationResult]{
0: (*RevealSuccessfulManagerResult)(nil),
1: (*TransactionSuccessfulManagerResult)(nil),
2: (*OriginationSuccessfulManagerResult)(nil),
3: (*DelegationSuccessfulManagerResult)(nil),
5: (*SetDepositsLimitSuccessfulManagerResult)(nil),
},
})
}
func ListOperations() []OperationContents {
return encoding.ListVariants[OperationContents]()
}