summaryrefslogtreecommitdiff
path: root/data/transactions/logic/fields.go
blob: a1c944ffb64006694328dc2c590a24b954ab6a37 (plain)
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
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
// 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 (
	"github.com/algorand/go-algorand/data/transactions"
	"github.com/algorand/go-algorand/protocol"
)

//go:generate stringer -type=TxnField,GlobalField,AssetParamsField,AppParamsField,AcctParamsField,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
)

// FieldSpec unifies the various specs for presentation
type FieldSpec interface {
	Type() StackType
	OpVersion() uint64
	Note() string
	Version() uint64
}

// TxnFieldNames are arguments to the 'txn' and 'txnById' opcodes
var TxnFieldNames []string

var txnFieldSpecByField map[TxnField]txnFieldSpec

// TxnFieldSpecByName gives access to the field specs by field name
var TxnFieldSpecByName tfNameSpecMap

// simple interface used by doc generator for fields versioning
type tfNameSpecMap map[string]txnFieldSpec

func (s tfNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

type txnFieldSpec struct {
	field      TxnField
	ftype      StackType
	array      bool   // Is this an array field?
	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
}

func (fs *txnFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *txnFieldSpec) OpVersion() uint64 {
	return 0
}

func (fs *txnFieldSpec) Version() uint64 {
	return fs.version
}

func (fs *txnFieldSpec) Note() string {
	note := txnFieldDocs[fs.field.String()]
	if fs.effects {
		note = addExtra(note, "Application mode only")
	}
	return note
}

var txnFieldSpecs = []txnFieldSpec{
	{Sender, StackBytes, false, 0, 5, false},
	{Fee, StackUint64, false, 0, 5, false},
	{FirstValid, StackUint64, false, 0, 0, false},
	{FirstValidTime, StackUint64, false, 0, 0, false},
	{LastValid, StackUint64, false, 0, 0, false},
	{Note, StackBytes, false, 0, 6, false},
	{Lease, StackBytes, false, 0, 0, false},
	{Receiver, StackBytes, false, 0, 5, false},
	{Amount, StackUint64, false, 0, 5, false},
	{CloseRemainderTo, StackBytes, false, 0, 5, false},
	{VotePK, StackBytes, false, 0, 6, false},
	{SelectionPK, StackBytes, false, 0, 6, false},
	{VoteFirst, StackUint64, false, 0, 6, false},
	{VoteLast, StackUint64, false, 0, 6, false},
	{VoteKeyDilution, StackUint64, false, 0, 6, false},
	{Type, StackBytes, false, 0, 5, false},
	{TypeEnum, StackUint64, false, 0, 5, false},
	{XferAsset, StackUint64, false, 0, 5, false},
	{AssetAmount, StackUint64, false, 0, 5, false},
	{AssetSender, StackBytes, false, 0, 5, false},
	{AssetReceiver, StackBytes, false, 0, 5, false},
	{AssetCloseTo, StackBytes, false, 0, 5, false},
	{GroupIndex, StackUint64, false, 0, 0, false},
	{TxID, StackBytes, false, 0, 0, false},
	{ApplicationID, StackUint64, false, 2, 6, false},
	{OnCompletion, StackUint64, false, 2, 6, false},
	{ApplicationArgs, StackBytes, true, 2, 6, false},
	{NumAppArgs, StackUint64, false, 2, 0, false},
	{Accounts, StackBytes, true, 2, 6, false},
	{NumAccounts, StackUint64, false, 2, 0, false},
	{ApprovalProgram, StackBytes, false, 2, 6, false},
	{ClearStateProgram, StackBytes, false, 2, 6, false},
	{RekeyTo, StackBytes, false, 2, 6, false},
	{ConfigAsset, StackUint64, false, 2, 5, false},
	{ConfigAssetTotal, StackUint64, false, 2, 5, false},
	{ConfigAssetDecimals, StackUint64, false, 2, 5, false},
	{ConfigAssetDefaultFrozen, StackUint64, false, 2, 5, false},
	{ConfigAssetUnitName, StackBytes, false, 2, 5, false},
	{ConfigAssetName, StackBytes, false, 2, 5, false},
	{ConfigAssetURL, StackBytes, false, 2, 5, false},
	{ConfigAssetMetadataHash, StackBytes, false, 2, 5, false},
	{ConfigAssetManager, StackBytes, false, 2, 5, false},
	{ConfigAssetReserve, StackBytes, false, 2, 5, false},
	{ConfigAssetFreeze, StackBytes, false, 2, 5, false},
	{ConfigAssetClawback, StackBytes, false, 2, 5, false},
	{FreezeAsset, StackUint64, false, 2, 5, false},
	{FreezeAssetAccount, StackBytes, false, 2, 5, false},
	{FreezeAssetFrozen, StackUint64, false, 2, 5, false},
	{Assets, StackUint64, true, 3, 6, false},
	{NumAssets, StackUint64, false, 3, 0, false},
	{Applications, StackUint64, true, 3, 6, false},
	{NumApplications, StackUint64, false, 3, 0, false},
	{GlobalNumUint, StackUint64, false, 3, 6, false},
	{GlobalNumByteSlice, StackUint64, false, 3, 6, false},
	{LocalNumUint, StackUint64, false, 3, 6, false},
	{LocalNumByteSlice, StackUint64, false, 3, 6, false},
	{ExtraProgramPages, StackUint64, false, 4, 6, false},
	{Nonparticipation, StackUint64, false, 5, 6, false},

	{Logs, StackBytes, true, 5, 5, true},
	{NumLogs, StackUint64, false, 5, 5, true},
	{CreatedAssetID, StackUint64, false, 5, 5, true},
	{CreatedApplicationID, StackUint64, false, 5, 5, true},
}

// TxnaFieldNames are arguments to the 'txna' opcode
// It need not be fast, as it's only used for doc generation.
func TxnaFieldNames() []string {
	var names []string
	for _, fs := range txnFieldSpecs {
		if fs.array {
			names = append(names, fs.field.String())
		}
	}
	return names
}

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,
	string(protocol.ApplicationCallTx): 6,
}

// 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

	// v6

	// OpcodeBudget The remaining budget available for execution
	OpcodeBudget

	// CallerApplicationID The ID of the caller app, else 0
	CallerApplicationID

	// CallerApplicationAddress The Address of the caller app, else ZeroAddress
	CallerApplicationAddress

	invalidGlobalField
)

// GlobalFieldNames are arguments to the 'global' opcode
var GlobalFieldNames []string

type globalFieldSpec struct {
	field   GlobalField
	ftype   StackType
	mode    runMode
	version uint64
}

func (fs *globalFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *globalFieldSpec) OpVersion() uint64 {
	return 0
}

func (fs *globalFieldSpec) Version() uint64 {
	return fs.version
}
func (fs *globalFieldSpec) Note() string {
	note := globalFieldDocs[fs.field.String()]
	if fs.mode == runModeApplication {
		note = addExtra(note, "Application mode only.")
	}
	// There are no Signature mode only globals
	return note
}

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},
	{OpcodeBudget, StackUint64, modeAny, 6},
	{CallerApplicationID, StackUint64, runModeApplication, 6},
	{CallerApplicationAddress, StackBytes, runModeApplication, 6},
}

var globalFieldSpecByField map[GlobalField]globalFieldSpec

// GlobalFieldSpecByName gives access to the field specs by field name
var GlobalFieldSpecByName gfNameSpecMap

type gfNameSpecMap map[string]globalFieldSpec

func (s gfNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

// 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
}

func (fs *ecdsaCurveSpec) Type() StackType {
	return StackNone // Will not show, since all are the same
}

func (fs *ecdsaCurveSpec) OpVersion() uint64 {
	return 5
}

func (fs *ecdsaCurveSpec) Version() uint64 {
	return fs.version
}

func (fs *ecdsaCurveSpec) Note() string {
	note := EcdsaCurveDocs[fs.field.String()]
	return note
}

var ecdsaCurveSpecs = []ecdsaCurveSpec{
	{Secp256k1, 5},
}

var ecdsaCurveSpecByField map[EcdsaCurve]ecdsaCurveSpec

// EcdsaCurveSpecByName gives access to the field specs by field name
var EcdsaCurveSpecByName ecDsaCurveNameSpecMap

// simple interface used by doc generator for fields versioning
type ecDsaCurveNameSpecMap map[string]ecdsaCurveSpec

func (s ecDsaCurveNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

// 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 (fs *base64EncodingSpec) Type() StackType {
	return fs.ftype
}

func (fs *base64EncodingSpec) OpVersion() uint64 {
	return 6
}

func (fs *base64EncodingSpec) Version() uint64 {
	return fs.version
}

func (fs *base64EncodingSpec) Note() string {
	note := "" // no doc list?
	return note
}
func (s base64EncodingSpecMap) getExtraFor(name string) (extra string) {
	// Uses 6 here because base64_decode fields were introduced in 6
	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

type assetHoldingFieldSpec struct {
	field   AssetHoldingField
	ftype   StackType
	version uint64
}

func (fs *assetHoldingFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *assetHoldingFieldSpec) OpVersion() uint64 {
	return 2
}

func (fs *assetHoldingFieldSpec) Version() uint64 {
	return fs.version
}

func (fs *assetHoldingFieldSpec) Note() string {
	note := assetHoldingFieldDocs[fs.field.String()]
	return note
}

var assetHoldingFieldSpecs = []assetHoldingFieldSpec{
	{AssetBalance, StackUint64, 2},
	{AssetFrozen, StackUint64, 2},
}

var assetHoldingFieldSpecByField map[AssetHoldingField]assetHoldingFieldSpec

// AssetHoldingFieldSpecByName gives access to the field specs by field name
var AssetHoldingFieldSpecByName ahfNameSpecMap

type ahfNameSpecMap map[string]assetHoldingFieldSpec

func (s ahfNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

// 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

type assetParamsFieldSpec struct {
	field   AssetParamsField
	ftype   StackType
	version uint64
}

func (fs *assetParamsFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *assetParamsFieldSpec) OpVersion() uint64 {
	return 2
}

func (fs *assetParamsFieldSpec) Version() uint64 {
	return fs.version
}

func (fs *assetParamsFieldSpec) Note() string {
	note := assetParamsFieldDocs[fs.field.String()]
	return note
}

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

// AssetParamsFieldSpecByName gives access to the field specs by field name
var AssetParamsFieldSpecByName apfNameSpecMap

type apfNameSpecMap map[string]assetParamsFieldSpec

func (s apfNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

// 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

type appParamsFieldSpec struct {
	field   AppParamsField
	ftype   StackType
	version uint64
}

func (fs *appParamsFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *appParamsFieldSpec) OpVersion() uint64 {
	return 5
}

func (fs *appParamsFieldSpec) Version() uint64 {
	return fs.version
}

func (fs *appParamsFieldSpec) Note() string {
	note := appParamsFieldDocs[fs.field.String()]
	return note
}

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

// AppParamsFieldSpecByName gives access to the field specs by field name
var AppParamsFieldSpecByName appNameSpecMap

// simple interface used by doc generator for fields versioning
type appNameSpecMap map[string]appParamsFieldSpec

func (s appNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

// AcctParamsField is an enum for `acct_params_get` opcode
type AcctParamsField int

const (
	// AcctBalance is the blance, with pending rewards
	AcctBalance AcctParamsField = iota
	// AcctMinBalance is algos needed for this accounts apps and assets
	AcctMinBalance
	//AcctAuthAddr is the rekeyed address if any, else ZeroAddress
	AcctAuthAddr

	invalidAcctParamsField
)

// AcctParamsFieldNames are arguments to the 'acct_params_get' opcode
var AcctParamsFieldNames []string

type acctParamsFieldSpec struct {
	field   AcctParamsField
	ftype   StackType
	version uint64
}

func (fs *acctParamsFieldSpec) Type() StackType {
	return fs.ftype
}

func (fs *acctParamsFieldSpec) OpVersion() uint64 {
	return 6
}

func (fs *acctParamsFieldSpec) Version() uint64 {
	return fs.version
}

func (fs *acctParamsFieldSpec) Note() string {
	note := acctParamsFieldDocs[fs.field.String()]
	return note
}

var acctParamsFieldSpecs = []acctParamsFieldSpec{
	{AcctBalance, StackUint64, 6},
	{AcctMinBalance, StackUint64, 6},
	{AcctAuthAddr, StackBytes, 6},
}

var acctParamsFieldSpecByField map[AcctParamsField]acctParamsFieldSpec

// AcctParamsFieldSpecByName gives access to the field specs by field name
var AcctParamsFieldSpecByName acctNameSpecMap

// simple interface used by doc generator for fields versioning
type acctNameSpecMap map[string]acctParamsFieldSpec

func (s acctNameSpecMap) SpecByName(name string) FieldSpec {
	fs := s[name]
	return &fs
}

func init() {
	TxnFieldNames = make([]string, int(invalidTxnField))
	for fi := Sender; fi < invalidTxnField; fi++ {
		TxnFieldNames[fi] = fi.String()
	}
	txnFieldSpecByField = make(map[TxnField]txnFieldSpec, len(TxnFieldNames))
	for i, s := range txnFieldSpecs {
		if int(s.field) != i {
			panic("txnFieldSpecs disjoint with TxnField enum")
		}
		txnFieldSpecByField[s.field] = s
	}
	TxnFieldSpecByName = make(map[string]txnFieldSpec, len(TxnFieldNames))
	for i, tfn := range TxnFieldNames {
		TxnFieldSpecByName[tfn] = txnFieldSpecByField[TxnField(i)]
	}

	GlobalFieldNames = make([]string, int(invalidGlobalField))
	for i := MinTxnFee; i < invalidGlobalField; i++ {
		GlobalFieldNames[i] = i.String()
	}
	globalFieldSpecByField = make(map[GlobalField]globalFieldSpec, len(GlobalFieldNames))
	for i, s := range globalFieldSpecs {
		if int(s.field) != i {
			panic("globalFieldSpecs disjoint with GlobalField enum")
		}
		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[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)]
	}

	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[i] = i.String()
	}
	assetHoldingFieldSpecByField = make(map[AssetHoldingField]assetHoldingFieldSpec, len(AssetHoldingFieldNames))
	for _, s := range assetHoldingFieldSpecs {
		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[i] = i.String()
	}
	assetParamsFieldSpecByField = make(map[AssetParamsField]assetParamsFieldSpec, len(AssetParamsFieldNames))
	for _, s := range assetParamsFieldSpecs {
		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[i] = i.String()
	}
	appParamsFieldSpecByField = make(map[AppParamsField]appParamsFieldSpec, len(AppParamsFieldNames))
	for _, s := range appParamsFieldSpecs {
		appParamsFieldSpecByField[s.field] = s
	}
	AppParamsFieldSpecByName = make(appNameSpecMap, len(AppParamsFieldNames))
	for i, apfn := range AppParamsFieldNames {
		AppParamsFieldSpecByName[apfn] = appParamsFieldSpecByField[AppParamsField(i)]
	}

	AcctParamsFieldNames = make([]string, int(invalidAcctParamsField))
	for i := AcctBalance; i < invalidAcctParamsField; i++ {
		AcctParamsFieldNames[i] = i.String()
	}
	acctParamsFieldSpecByField = make(map[AcctParamsField]acctParamsFieldSpec, len(AcctParamsFieldNames))
	for _, s := range acctParamsFieldSpecs {
		acctParamsFieldSpecByField[s.field] = s
	}
	AcctParamsFieldSpecByName = make(acctNameSpecMap, len(AcctParamsFieldNames))
	for i, apfn := range AcctParamsFieldNames {
		AcctParamsFieldSpecByName[apfn] = acctParamsFieldSpecByField[AcctParamsField(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)
	}
}