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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
|
// Copyright (C) 2019-2022 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.
package logic
import (
"fmt"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/protocol"
)
//go:generate stringer -type=TxnField,GlobalField,AssetParamsField,AppParamsField,AssetHoldingField,OnCompletionConstType,EcdsaCurve,Base64Encoding -output=fields_string.go
// TxnField is an enum type for `txn` and `gtxn`
type TxnField int
const (
// Sender Transaction.Sender
Sender TxnField = iota
// Fee Transaction.Fee
Fee
// FirstValid Transaction.FirstValid
FirstValid
// FirstValidTime panic
FirstValidTime
// LastValid Transaction.LastValid
LastValid
// Note Transaction.Note
Note
// Lease Transaction.Lease
Lease
// Receiver Transaction.Receiver
Receiver
// Amount Transaction.Amount
Amount
// CloseRemainderTo Transaction.CloseRemainderTo
CloseRemainderTo
// VotePK Transaction.VotePK
VotePK
// SelectionPK Transaction.SelectionPK
SelectionPK
// VoteFirst Transaction.VoteFirst
VoteFirst
// VoteLast Transaction.VoteLast
VoteLast
// VoteKeyDilution Transaction.VoteKeyDilution
VoteKeyDilution
// Type Transaction.Type
Type
// TypeEnum int(Transaction.Type)
TypeEnum
// XferAsset Transaction.XferAsset
XferAsset
// AssetAmount Transaction.AssetAmount
AssetAmount
// AssetSender Transaction.AssetSender
AssetSender
// AssetReceiver Transaction.AssetReceiver
AssetReceiver
// AssetCloseTo Transaction.AssetCloseTo
AssetCloseTo
// GroupIndex i for txngroup[i] == Txn
GroupIndex
// TxID Transaction.ID()
TxID
// ApplicationID basics.AppIndex
ApplicationID
// OnCompletion OnCompletion
OnCompletion
// ApplicationArgs [][]byte
ApplicationArgs
// NumAppArgs len(ApplicationArgs)
NumAppArgs
// Accounts []basics.Address
Accounts
// NumAccounts len(Accounts)
NumAccounts
// ApprovalProgram []byte
ApprovalProgram
// ClearStateProgram []byte
ClearStateProgram
// RekeyTo basics.Address
RekeyTo
// ConfigAsset basics.AssetIndex
ConfigAsset
// ConfigAssetTotal AssetParams.Total
ConfigAssetTotal
// ConfigAssetDecimals AssetParams.Decimals
ConfigAssetDecimals
// ConfigAssetDefaultFrozen AssetParams.AssetDefaultFrozen
ConfigAssetDefaultFrozen
// ConfigAssetUnitName AssetParams.UnitName
ConfigAssetUnitName
// ConfigAssetName AssetParams.AssetName
ConfigAssetName
// ConfigAssetURL AssetParams.URL
ConfigAssetURL
// ConfigAssetMetadataHash AssetParams.MetadataHash
ConfigAssetMetadataHash
// ConfigAssetManager AssetParams.Manager
ConfigAssetManager
// ConfigAssetReserve AssetParams.Reserve
ConfigAssetReserve
// ConfigAssetFreeze AssetParams.Freeze
ConfigAssetFreeze
// ConfigAssetClawback AssetParams.Clawback
ConfigAssetClawback
//FreezeAsset basics.AssetIndex
FreezeAsset
// FreezeAssetAccount basics.Address
FreezeAssetAccount
// FreezeAssetFrozen bool
FreezeAssetFrozen
// Assets []basics.AssetIndex
Assets
// NumAssets len(ForeignAssets)
NumAssets
// Applications []basics.AppIndex
Applications
// NumApplications len(ForeignApps)
NumApplications
// GlobalNumUint uint64
GlobalNumUint
// GlobalNumByteSlice uint64
GlobalNumByteSlice
// LocalNumUint uint64
LocalNumUint
// LocalNumByteSlice uint64
LocalNumByteSlice
// ExtraProgramPages AppParams.ExtraProgramPages
ExtraProgramPages
// Nonparticipation Transaction.Nonparticipation
Nonparticipation
// Logs Transaction.ApplyData.EvalDelta.Logs
Logs
// NumLogs len(Logs)
NumLogs
// CreatedAssetID Transaction.ApplyData.EvalDelta.ConfigAsset
CreatedAssetID
// CreatedApplicationID Transaction.ApplyData.EvalDelta.ApplicationID
CreatedApplicationID
invalidTxnField // fence for some setup that loops from Sender..invalidTxnField
)
// TxnFieldNames are arguments to the 'txn' and 'txnById' opcodes
var TxnFieldNames []string
// TxnFieldTypes is StackBytes or StackUint64 parallel to TxnFieldNames
var TxnFieldTypes []StackType
var txnFieldSpecByField map[TxnField]txnFieldSpec
var txnFieldSpecByName tfNameSpecMap
// simple interface used by doc generator for fields versioning
type tfNameSpecMap map[string]txnFieldSpec
func (s tfNameSpecMap) getExtraFor(name string) (extra string) {
if s[name].version > 1 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
type txnFieldSpec struct {
field TxnField
ftype StackType
version uint64 // When this field become available to txn/gtxn. 0=always
itxVersion uint64 // When this field become available to itxn_field. 0=never
effects bool // Is this a field on the "effects"? That is, something in ApplyData
}
var txnFieldSpecs = []txnFieldSpec{
{Sender, StackBytes, 0, 5, false},
{Fee, StackUint64, 0, 5, false},
{FirstValid, StackUint64, 0, 0, false},
{FirstValidTime, StackUint64, 0, 0, false},
{LastValid, StackUint64, 0, 0, false},
{Note, StackBytes, 0, 6, false},
{Lease, StackBytes, 0, 0, false},
{Receiver, StackBytes, 0, 5, false},
{Amount, StackUint64, 0, 5, false},
{CloseRemainderTo, StackBytes, 0, 5, false},
{VotePK, StackBytes, 0, 6, false},
{SelectionPK, StackBytes, 0, 6, false},
{VoteFirst, StackUint64, 0, 6, false},
{VoteLast, StackUint64, 0, 6, false},
{VoteKeyDilution, StackUint64, 0, 6, false},
{Type, StackBytes, 0, 5, false},
{TypeEnum, StackUint64, 0, 5, false},
{XferAsset, StackUint64, 0, 5, false},
{AssetAmount, StackUint64, 0, 5, false},
{AssetSender, StackBytes, 0, 5, false},
{AssetReceiver, StackBytes, 0, 5, false},
{AssetCloseTo, StackBytes, 0, 5, false},
{GroupIndex, StackUint64, 0, 0, false},
{TxID, StackBytes, 0, 0, false},
{ApplicationID, StackUint64, 2, 0, false},
{OnCompletion, StackUint64, 2, 0, false},
{ApplicationArgs, StackBytes, 2, 0, false},
{NumAppArgs, StackUint64, 2, 0, false},
{Accounts, StackBytes, 2, 0, false},
{NumAccounts, StackUint64, 2, 0, false},
{ApprovalProgram, StackBytes, 2, 0, false},
{ClearStateProgram, StackBytes, 2, 0, false},
{RekeyTo, StackBytes, 2, 6, false},
{ConfigAsset, StackUint64, 2, 5, false},
{ConfigAssetTotal, StackUint64, 2, 5, false},
{ConfigAssetDecimals, StackUint64, 2, 5, false},
{ConfigAssetDefaultFrozen, StackUint64, 2, 5, false},
{ConfigAssetUnitName, StackBytes, 2, 5, false},
{ConfigAssetName, StackBytes, 2, 5, false},
{ConfigAssetURL, StackBytes, 2, 5, false},
{ConfigAssetMetadataHash, StackBytes, 2, 5, false},
{ConfigAssetManager, StackBytes, 2, 5, false},
{ConfigAssetReserve, StackBytes, 2, 5, false},
{ConfigAssetFreeze, StackBytes, 2, 5, false},
{ConfigAssetClawback, StackBytes, 2, 5, false},
{FreezeAsset, StackUint64, 2, 5, false},
{FreezeAssetAccount, StackBytes, 2, 5, false},
{FreezeAssetFrozen, StackUint64, 2, 5, false},
{Assets, StackUint64, 3, 0, false},
{NumAssets, StackUint64, 3, 0, false},
{Applications, StackUint64, 3, 0, false},
{NumApplications, StackUint64, 3, 0, false},
{GlobalNumUint, StackUint64, 3, 0, false},
{GlobalNumByteSlice, StackUint64, 3, 0, false},
{LocalNumUint, StackUint64, 3, 0, false},
{LocalNumByteSlice, StackUint64, 3, 0, false},
{ExtraProgramPages, StackUint64, 4, 0, false},
{Nonparticipation, StackUint64, 5, 6, false},
{Logs, StackBytes, 5, 5, true},
{NumLogs, StackUint64, 5, 5, true},
{CreatedAssetID, StackUint64, 5, 5, true},
{CreatedApplicationID, StackUint64, 5, 5, true},
}
// TxnaFieldNames are arguments to the 'txna' opcode
// It is a subset of txn transaction fields so initialized here in-place
var TxnaFieldNames = []string{ApplicationArgs.String(), Accounts.String(), Assets.String(), Applications.String(), Logs.String()}
// TxnaFieldTypes is StackBytes or StackUint64 parallel to TxnaFieldNames
var TxnaFieldTypes = []StackType{
txnaFieldSpecByField[ApplicationArgs].ftype,
txnaFieldSpecByField[Accounts].ftype,
txnaFieldSpecByField[Assets].ftype,
txnaFieldSpecByField[Applications].ftype,
txnaFieldSpecByField[Logs].ftype,
}
var txnaFieldSpecByField = map[TxnField]txnFieldSpec{
ApplicationArgs: {ApplicationArgs, StackBytes, 2, 0, false},
Accounts: {Accounts, StackBytes, 2, 0, false},
Assets: {Assets, StackUint64, 3, 0, false},
Applications: {Applications, StackUint64, 3, 0, false},
Logs: {Logs, StackBytes, 5, 5, true},
}
var innerTxnTypes = map[string]uint64{
string(protocol.PaymentTx): 5,
string(protocol.KeyRegistrationTx): 6,
string(protocol.AssetTransferTx): 5,
string(protocol.AssetConfigTx): 5,
string(protocol.AssetFreezeTx): 5,
}
// TxnTypeNames is the values of Txn.Type in enum order
var TxnTypeNames = []string{
string(protocol.UnknownTx),
string(protocol.PaymentTx),
string(protocol.KeyRegistrationTx),
string(protocol.AssetConfigTx),
string(protocol.AssetTransferTx),
string(protocol.AssetFreezeTx),
string(protocol.ApplicationCallTx),
}
// map TxnTypeName to its enum index, for `txn TypeEnum`
var txnTypeIndexes map[string]uint64
// map symbolic name to uint64 for assembleInt
var txnTypeConstToUint64 map[string]uint64
// OnCompletionConstType is the same as transactions.OnCompletion
type OnCompletionConstType transactions.OnCompletion
const (
// NoOp = transactions.NoOpOC
NoOp OnCompletionConstType = OnCompletionConstType(transactions.NoOpOC)
// OptIn = transactions.OptInOC
OptIn OnCompletionConstType = OnCompletionConstType(transactions.OptInOC)
// CloseOut = transactions.CloseOutOC
CloseOut OnCompletionConstType = OnCompletionConstType(transactions.CloseOutOC)
// ClearState = transactions.ClearStateOC
ClearState OnCompletionConstType = OnCompletionConstType(transactions.ClearStateOC)
// UpdateApplication = transactions.UpdateApplicationOC
UpdateApplication OnCompletionConstType = OnCompletionConstType(transactions.UpdateApplicationOC)
// DeleteApplication = transactions.DeleteApplicationOC
DeleteApplication OnCompletionConstType = OnCompletionConstType(transactions.DeleteApplicationOC)
// end of constants
invalidOnCompletionConst OnCompletionConstType = DeleteApplication + 1
)
// OnCompletionNames is the string names of Txn.OnCompletion, array index is the const value
var OnCompletionNames []string
// onCompletionConstToUint64 map symbolic name to uint64 for assembleInt
var onCompletionConstToUint64 map[string]uint64
// GlobalField is an enum for `global` opcode
type GlobalField uint64
const (
// MinTxnFee ConsensusParams.MinTxnFee
MinTxnFee GlobalField = iota
// MinBalance ConsensusParams.MinBalance
MinBalance
// MaxTxnLife ConsensusParams.MaxTxnLife
MaxTxnLife
// ZeroAddress [32]byte{0...}
ZeroAddress
// GroupSize len(txn group)
GroupSize
// v2
// LogicSigVersion ConsensusParams.LogicSigVersion
LogicSigVersion
// Round basics.Round
Round
// LatestTimestamp uint64
LatestTimestamp
// CurrentApplicationID uint64
CurrentApplicationID
// v3
// CreatorAddress [32]byte
CreatorAddress
// v5
// CurrentApplicationAddress [32]byte
CurrentApplicationAddress
// GroupID [32]byte
GroupID
invalidGlobalField
)
// GlobalFieldNames are arguments to the 'global' opcode
var GlobalFieldNames []string
// GlobalFieldTypes is StackUint64 StackBytes in parallel with GlobalFieldNames
var GlobalFieldTypes []StackType
type globalFieldSpec struct {
field GlobalField
ftype StackType
mode runMode
version uint64
}
var globalFieldSpecs = []globalFieldSpec{
{MinTxnFee, StackUint64, modeAny, 0}, // version 0 is the same as TEAL v1 (initial TEAL release)
{MinBalance, StackUint64, modeAny, 0},
{MaxTxnLife, StackUint64, modeAny, 0},
{ZeroAddress, StackBytes, modeAny, 0},
{GroupSize, StackUint64, modeAny, 0},
{LogicSigVersion, StackUint64, modeAny, 2},
{Round, StackUint64, runModeApplication, 2},
{LatestTimestamp, StackUint64, runModeApplication, 2},
{CurrentApplicationID, StackUint64, runModeApplication, 2},
{CreatorAddress, StackBytes, runModeApplication, 3},
{CurrentApplicationAddress, StackBytes, runModeApplication, 5},
{GroupID, StackBytes, modeAny, 5},
}
// GlobalFieldSpecByField maps GlobalField to spec
var globalFieldSpecByField map[GlobalField]globalFieldSpec
var globalFieldSpecByName gfNameSpecMap
// simple interface used by doc generator for fields versioning
type gfNameSpecMap map[string]globalFieldSpec
func (s gfNameSpecMap) getExtraFor(name string) (extra string) {
if s[name].version > 1 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
// EcdsaCurve is an enum for `ecdsa_` opcodes
type EcdsaCurve int
const (
// Secp256k1 curve for bitcoin/ethereum
Secp256k1 EcdsaCurve = iota
invalidEcdsaCurve
)
// EcdsaCurveNames are arguments to the 'ecdsa_' opcode
var EcdsaCurveNames []string
type ecdsaCurveSpec struct {
field EcdsaCurve
version uint64
}
var ecdsaCurveSpecs = []ecdsaCurveSpec{
{Secp256k1, 5},
}
var ecdsaCurveSpecByField map[EcdsaCurve]ecdsaCurveSpec
var ecdsaCurveSpecByName ecDsaCurveNameSpecMap
// simple interface used by doc generator for fields versioning
type ecDsaCurveNameSpecMap map[string]ecdsaCurveSpec
func (s ecDsaCurveNameSpecMap) getExtraFor(name string) (extra string) {
// Uses 5 here because ecdsa fields were introduced in 5
if s[name].version > 5 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
// Base64Encoding is an enum for the `base64decode` opcode
type Base64Encoding int
const (
// URLEncoding represents the base64url encoding defined in https://www.rfc-editor.org/rfc/rfc4648.html
URLEncoding Base64Encoding = iota
// StdEncoding represents the standard encoding of the RFC
StdEncoding
invalidBase64Alphabet
)
// After running `go generate` these strings will be available:
var base64EncodingNames [2]string = [...]string{URLEncoding.String(), StdEncoding.String()}
type base64EncodingSpec struct {
field Base64Encoding
ftype StackType
version uint64
}
var base64EncodingSpecs = []base64EncodingSpec{
{URLEncoding, StackBytes, 6},
{StdEncoding, StackBytes, 6},
}
var base64EncodingSpecByField map[Base64Encoding]base64EncodingSpec
var base64EncodingSpecByName base64EncodingSpecMap
type base64EncodingSpecMap map[string]base64EncodingSpec
func (s base64EncodingSpecMap) getExtraFor(name string) (extra string) {
// Uses 6 here because base64_decode fields were introduced in 6
if s[name].version > 6 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
// AssetHoldingField is an enum for `asset_holding_get` opcode
type AssetHoldingField int
const (
// AssetBalance AssetHolding.Amount
AssetBalance AssetHoldingField = iota
// AssetFrozen AssetHolding.Frozen
AssetFrozen
invalidAssetHoldingField
)
// AssetHoldingFieldNames are arguments to the 'asset_holding_get' opcode
var AssetHoldingFieldNames []string
// AssetHoldingFieldTypes is StackUint64 StackBytes in parallel with AssetHoldingFieldNames
var AssetHoldingFieldTypes []StackType
type assetHoldingFieldSpec struct {
field AssetHoldingField
ftype StackType
version uint64
}
var assetHoldingFieldSpecs = []assetHoldingFieldSpec{
{AssetBalance, StackUint64, 2},
{AssetFrozen, StackUint64, 2},
}
var assetHoldingFieldSpecByField map[AssetHoldingField]assetHoldingFieldSpec
var assetHoldingFieldSpecByName ahfNameSpecMap
// simple interface used by doc generator for fields versioning
type ahfNameSpecMap map[string]assetHoldingFieldSpec
func (s ahfNameSpecMap) getExtraFor(name string) (extra string) {
// Uses 2 here because asset fields were introduced in 2
if s[name].version > 2 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
// AssetParamsField is an enum for `asset_params_get` opcode
type AssetParamsField int
const (
// AssetTotal AssetParams.Total
AssetTotal AssetParamsField = iota
// AssetDecimals AssetParams.Decimals
AssetDecimals
// AssetDefaultFrozen AssetParams.AssetDefaultFrozen
AssetDefaultFrozen
// AssetUnitName AssetParams.UnitName
AssetUnitName
// AssetName AssetParams.AssetName
AssetName
// AssetURL AssetParams.URL
AssetURL
// AssetMetadataHash AssetParams.MetadataHash
AssetMetadataHash
// AssetManager AssetParams.Manager
AssetManager
// AssetReserve AssetParams.Reserve
AssetReserve
// AssetFreeze AssetParams.Freeze
AssetFreeze
// AssetClawback AssetParams.Clawback
AssetClawback
// AssetCreator is not *in* the Params, but it is uniquely determined.
AssetCreator
invalidAssetParamsField
)
// AssetParamsFieldNames are arguments to the 'asset_params_get' opcode
var AssetParamsFieldNames []string
// AssetParamsFieldTypes is StackUint64 StackBytes in parallel with AssetParamsFieldNames
var AssetParamsFieldTypes []StackType
type assetParamsFieldSpec struct {
field AssetParamsField
ftype StackType
version uint64
}
var assetParamsFieldSpecs = []assetParamsFieldSpec{
{AssetTotal, StackUint64, 2},
{AssetDecimals, StackUint64, 2},
{AssetDefaultFrozen, StackUint64, 2},
{AssetUnitName, StackBytes, 2},
{AssetName, StackBytes, 2},
{AssetURL, StackBytes, 2},
{AssetMetadataHash, StackBytes, 2},
{AssetManager, StackBytes, 2},
{AssetReserve, StackBytes, 2},
{AssetFreeze, StackBytes, 2},
{AssetClawback, StackBytes, 2},
{AssetCreator, StackBytes, 5},
}
var assetParamsFieldSpecByField map[AssetParamsField]assetParamsFieldSpec
var assetParamsFieldSpecByName apfNameSpecMap
// simple interface used by doc generator for fields versioning
type apfNameSpecMap map[string]assetParamsFieldSpec
func (s apfNameSpecMap) getExtraFor(name string) (extra string) {
// Uses 2 here because asset fields were introduced in 2
if s[name].version > 2 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
// AppParamsField is an enum for `app_params_get` opcode
type AppParamsField int
const (
// AppApprovalProgram AppParams.ApprovalProgram
AppApprovalProgram AppParamsField = iota
// AppClearStateProgram AppParams.ClearStateProgram
AppClearStateProgram
// AppGlobalNumUint AppParams.StateSchemas.GlobalStateSchema.NumUint
AppGlobalNumUint
// AppGlobalNumByteSlice AppParams.StateSchemas.GlobalStateSchema.NumByteSlice
AppGlobalNumByteSlice
// AppLocalNumUint AppParams.StateSchemas.LocalStateSchema.NumUint
AppLocalNumUint
// AppLocalNumByteSlice AppParams.StateSchemas.LocalStateSchema.NumByteSlice
AppLocalNumByteSlice
// AppExtraProgramPages AppParams.ExtraProgramPages
AppExtraProgramPages
// AppCreator is not *in* the Params, but it is uniquely determined.
AppCreator
// AppAddress is also not *in* the Params, but can be derived
AppAddress
invalidAppParamsField
)
// AppParamsFieldNames are arguments to the 'app_params_get' opcode
var AppParamsFieldNames []string
// AppParamsFieldTypes is StackUint64 StackBytes in parallel with AppParamsFieldNames
var AppParamsFieldTypes []StackType
type appParamsFieldSpec struct {
field AppParamsField
ftype StackType
version uint64
}
var appParamsFieldSpecs = []appParamsFieldSpec{
{AppApprovalProgram, StackBytes, 5},
{AppClearStateProgram, StackBytes, 5},
{AppGlobalNumUint, StackUint64, 5},
{AppGlobalNumByteSlice, StackUint64, 5},
{AppLocalNumUint, StackUint64, 5},
{AppLocalNumByteSlice, StackUint64, 5},
{AppExtraProgramPages, StackUint64, 5},
{AppCreator, StackBytes, 5},
{AppAddress, StackBytes, 5},
}
var appParamsFieldSpecByField map[AppParamsField]appParamsFieldSpec
var appParamsFieldSpecByName appNameSpecMap
// simple interface used by doc generator for fields versioning
type appNameSpecMap map[string]appParamsFieldSpec
func (s appNameSpecMap) getExtraFor(name string) (extra string) {
// Uses 5 here because app fields were introduced in 5
if s[name].version > 5 {
extra = fmt.Sprintf("LogicSigVersion >= %d.", s[name].version)
}
return
}
func init() {
TxnFieldNames = make([]string, int(invalidTxnField))
for fi := Sender; fi < invalidTxnField; fi++ {
TxnFieldNames[fi] = fi.String()
}
TxnFieldTypes = make([]StackType, int(invalidTxnField))
txnFieldSpecByField = make(map[TxnField]txnFieldSpec, len(TxnFieldNames))
for i, s := range txnFieldSpecs {
if int(s.field) != i {
panic("txnFieldSpecs disjoint with TxnField enum")
}
TxnFieldTypes[i] = s.ftype
txnFieldSpecByField[s.field] = s
}
txnFieldSpecByName = make(tfNameSpecMap, len(TxnFieldNames))
for i, tfn := range TxnFieldNames {
txnFieldSpecByName[tfn] = txnFieldSpecByField[TxnField(i)]
}
GlobalFieldNames = make([]string, int(invalidGlobalField))
for i := MinTxnFee; i < invalidGlobalField; i++ {
GlobalFieldNames[int(i)] = i.String()
}
GlobalFieldTypes = make([]StackType, len(GlobalFieldNames))
globalFieldSpecByField = make(map[GlobalField]globalFieldSpec, len(GlobalFieldNames))
for i, s := range globalFieldSpecs {
if int(s.field) != i {
panic("globalFieldSpecs disjoint with GlobalField enum")
}
GlobalFieldTypes[i] = s.ftype
globalFieldSpecByField[s.field] = s
}
globalFieldSpecByName = make(gfNameSpecMap, len(GlobalFieldNames))
for i, gfn := range GlobalFieldNames {
globalFieldSpecByName[gfn] = globalFieldSpecByField[GlobalField(i)]
}
EcdsaCurveNames = make([]string, int(invalidEcdsaCurve))
for i := Secp256k1; i < invalidEcdsaCurve; i++ {
EcdsaCurveNames[int(i)] = i.String()
}
ecdsaCurveSpecByField = make(map[EcdsaCurve]ecdsaCurveSpec, len(EcdsaCurveNames))
for _, s := range ecdsaCurveSpecs {
ecdsaCurveSpecByField[s.field] = s
}
ecdsaCurveSpecByName = make(ecDsaCurveNameSpecMap, len(EcdsaCurveNames))
for i, ahfn := range EcdsaCurveNames {
ecdsaCurveSpecByName[ahfn] = ecdsaCurveSpecByField[EcdsaCurve(i)]
}
base64EncodingSpecByField = make(map[Base64Encoding]base64EncodingSpec, len(base64EncodingNames))
for _, s := range base64EncodingSpecs {
base64EncodingSpecByField[s.field] = s
}
base64EncodingSpecByName = make(base64EncodingSpecMap, len(base64EncodingNames))
for i, encoding := range base64EncodingNames {
base64EncodingSpecByName[encoding] = base64EncodingSpecByField[Base64Encoding(i)]
}
AssetHoldingFieldNames = make([]string, int(invalidAssetHoldingField))
for i := AssetBalance; i < invalidAssetHoldingField; i++ {
AssetHoldingFieldNames[int(i)] = i.String()
}
AssetHoldingFieldTypes = make([]StackType, len(AssetHoldingFieldNames))
assetHoldingFieldSpecByField = make(map[AssetHoldingField]assetHoldingFieldSpec, len(AssetHoldingFieldNames))
for _, s := range assetHoldingFieldSpecs {
AssetHoldingFieldTypes[int(s.field)] = s.ftype
assetHoldingFieldSpecByField[s.field] = s
}
assetHoldingFieldSpecByName = make(ahfNameSpecMap, len(AssetHoldingFieldNames))
for i, ahfn := range AssetHoldingFieldNames {
assetHoldingFieldSpecByName[ahfn] = assetHoldingFieldSpecByField[AssetHoldingField(i)]
}
AssetParamsFieldNames = make([]string, int(invalidAssetParamsField))
for i := AssetTotal; i < invalidAssetParamsField; i++ {
AssetParamsFieldNames[int(i)] = i.String()
}
AssetParamsFieldTypes = make([]StackType, len(AssetParamsFieldNames))
assetParamsFieldSpecByField = make(map[AssetParamsField]assetParamsFieldSpec, len(AssetParamsFieldNames))
for _, s := range assetParamsFieldSpecs {
AssetParamsFieldTypes[int(s.field)] = s.ftype
assetParamsFieldSpecByField[s.field] = s
}
assetParamsFieldSpecByName = make(apfNameSpecMap, len(AssetParamsFieldNames))
for i, apfn := range AssetParamsFieldNames {
assetParamsFieldSpecByName[apfn] = assetParamsFieldSpecByField[AssetParamsField(i)]
}
AppParamsFieldNames = make([]string, int(invalidAppParamsField))
for i := AppApprovalProgram; i < invalidAppParamsField; i++ {
AppParamsFieldNames[int(i)] = i.String()
}
AppParamsFieldTypes = make([]StackType, len(AppParamsFieldNames))
appParamsFieldSpecByField = make(map[AppParamsField]appParamsFieldSpec, len(AppParamsFieldNames))
for _, s := range appParamsFieldSpecs {
AppParamsFieldTypes[int(s.field)] = s.ftype
appParamsFieldSpecByField[s.field] = s
}
appParamsFieldSpecByName = make(appNameSpecMap, len(AppParamsFieldNames))
for i, apfn := range AppParamsFieldNames {
appParamsFieldSpecByName[apfn] = appParamsFieldSpecByField[AppParamsField(i)]
}
txnTypeIndexes = make(map[string]uint64, len(TxnTypeNames))
for i, tt := range TxnTypeNames {
txnTypeIndexes[tt] = uint64(i)
}
txnTypeConstToUint64 = make(map[string]uint64, len(TxnTypeNames))
for tt, v := range txnTypeIndexes {
symbol := TypeNameDescriptions[tt]
txnTypeConstToUint64[symbol] = v
}
OnCompletionNames = make([]string, int(invalidOnCompletionConst))
onCompletionConstToUint64 = make(map[string]uint64, len(OnCompletionNames))
for oc := NoOp; oc < invalidOnCompletionConst; oc++ {
symbol := oc.String()
OnCompletionNames[oc] = symbol
onCompletionConstToUint64[symbol] = uint64(oc)
}
}
|