github.com/mavryk-network/mvgo@v1.19.9/mavryk/op.go (about)

     1  // Copyright (c) 2020-2023 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package mavryk
     5  
     6  import (
     7  	"fmt"
     8  )
     9  
    10  type OpStatus byte
    11  
    12  const (
    13  	OpStatusInvalid OpStatus = iota // 0
    14  	OpStatusApplied                 // 1 (success)
    15  	OpStatusFailed
    16  	OpStatusSkipped
    17  	OpStatusBacktracked
    18  )
    19  
    20  func (t OpStatus) IsValid() bool {
    21  	return t != OpStatusInvalid
    22  }
    23  
    24  func (t OpStatus) IsSuccess() bool {
    25  	return t == OpStatusApplied
    26  }
    27  
    28  func (t *OpStatus) UnmarshalText(data []byte) error {
    29  	v := ParseOpStatus(string(data))
    30  	if !v.IsValid() {
    31  		return fmt.Errorf("tezos: invalid operation status '%s'", string(data))
    32  	}
    33  	*t = v
    34  	return nil
    35  }
    36  
    37  func (t OpStatus) MarshalText() ([]byte, error) {
    38  	return []byte(t.String()), nil
    39  }
    40  
    41  func ParseOpStatus(s string) OpStatus {
    42  	switch s {
    43  	case "applied":
    44  		return OpStatusApplied
    45  	case "failed":
    46  		return OpStatusFailed
    47  	case "skipped":
    48  		return OpStatusSkipped
    49  	case "backtracked":
    50  		return OpStatusBacktracked
    51  	default:
    52  		return OpStatusInvalid
    53  	}
    54  }
    55  
    56  func (t OpStatus) String() string {
    57  	switch t {
    58  	case OpStatusApplied:
    59  		return "applied"
    60  	case OpStatusFailed:
    61  		return "failed"
    62  	case OpStatusSkipped:
    63  		return "skipped"
    64  	case OpStatusBacktracked:
    65  		return "backtracked"
    66  	default:
    67  		return ""
    68  	}
    69  }
    70  
    71  type OpType byte
    72  
    73  // enums are allocated in chronological order
    74  const (
    75  	OpTypeInvalid                         OpType = iota
    76  	OpTypeActivateAccount                        // 1
    77  	OpTypeDoubleBakingEvidence                   // 2
    78  	OpTypeDoubleEndorsementEvidence              // 3
    79  	OpTypeSeedNonceRevelation                    // 4
    80  	OpTypeTransaction                            // 5
    81  	OpTypeOrigination                            // 6
    82  	OpTypeDelegation                             // 7
    83  	OpTypeReveal                                 // 8
    84  	OpTypeEndorsement                            // 9
    85  	OpTypeProposals                              // 10
    86  	OpTypeBallot                                 // 11
    87  	OpTypeFailingNoop                            // 12 v009
    88  	OpTypeEndorsementWithSlot                    // 13 v009
    89  	OpTypeRegisterConstant                       // 14 v011
    90  	OpTypePreendorsement                         // 15 v012
    91  	OpTypeDoublePreendorsementEvidence           // 16 v012
    92  	OpTypeSetDepositsLimit                       // 17 v012 DEPRECATED in v019 (AI)
    93  	OpTypeTxRollupOrigination                    // 18 v013 DEPRECATED in v016
    94  	OpTypeTxRollupSubmitBatch                    // 19 v013 DEPRECATED in v016
    95  	OpTypeTxRollupCommit                         // 20 v013 DEPRECATED in v016
    96  	OpTypeTxRollupReturnBond                     // 21 v013 DEPRECATED in v016
    97  	OpTypeTxRollupFinalizeCommitment             // 22 v013 DEPRECATED in v016
    98  	OpTypeTxRollupRemoveCommitment               // 23 v013 DEPRECATED in v016
    99  	OpTypeTxRollupRejection                      // 24 v013 DEPRECATED in v016
   100  	OpTypeTxRollupDispatchTickets                // 25 v013 DEPRECATED in v016
   101  	OpTypeTransferTicket                         // 26 v013
   102  	OpTypeVdfRevelation                          // 27 v014
   103  	OpTypeIncreasePaidStorage                    // 28 v014
   104  	OpTypeEvent                                  // 29 v014 (only in internal_operation_results)
   105  	OpTypeDrainDelegate                          // 30 v015
   106  	OpTypeUpdateConsensusKey                     // 31 v015
   107  	OpTypeSmartRollupOriginate                   // 32 v016
   108  	OpTypeSmartRollupAddMessages                 // 33 v016
   109  	OpTypeSmartRollupCement                      // 34 v016
   110  	OpTypeSmartRollupPublish                     // 35 v016
   111  	OpTypeSmartRollupRefute                      // 36 v016
   112  	OpTypeSmartRollupTimeout                     // 37 v016
   113  	OpTypeSmartRollupExecuteOutboxMessage        // 38 v016
   114  	OpTypeSmartRollupRecoverBond                 // 39 v016
   115  	OpTypeDalPublishCommitment                   // 40 v019
   116  	OpTypeAttestation                            // 41 v019 ??
   117  	OpTypePreattestation                         // 42 v019
   118  	OpTypeDoublePreattestationEvidence           // 43 v019
   119  	OpTypeDoubleAttestationEvidence              // 44 v019
   120  	OpTypeAttestationWithDal                     // 45 v019 ??
   121  )
   122  
   123  var (
   124  	opTypeStrings = map[OpType]string{
   125  		OpTypeInvalid:                         "",
   126  		OpTypeActivateAccount:                 "activate_account",
   127  		OpTypeDoubleBakingEvidence:            "double_baking_evidence",
   128  		OpTypeDoubleEndorsementEvidence:       "double_endorsement_evidence",
   129  		OpTypeSeedNonceRevelation:             "seed_nonce_revelation",
   130  		OpTypeTransaction:                     "transaction",
   131  		OpTypeOrigination:                     "origination",
   132  		OpTypeDelegation:                      "delegation",
   133  		OpTypeReveal:                          "reveal",
   134  		OpTypeEndorsement:                     "endorsement",
   135  		OpTypeProposals:                       "proposals",
   136  		OpTypeBallot:                          "ballot",
   137  		OpTypeFailingNoop:                     "failing_noop",
   138  		OpTypeEndorsementWithSlot:             "endorsement_with_slot",
   139  		OpTypeRegisterConstant:                "register_global_constant",
   140  		OpTypePreendorsement:                  "preendorsement",
   141  		OpTypeDoublePreendorsementEvidence:    "double_preendorsement_evidence",
   142  		OpTypeSetDepositsLimit:                "set_deposits_limit",
   143  		OpTypeTxRollupOrigination:             "tx_rollup_origination",
   144  		OpTypeTxRollupSubmitBatch:             "tx_rollup_submit_batch",
   145  		OpTypeTxRollupCommit:                  "tx_rollup_commit",
   146  		OpTypeTxRollupReturnBond:              "tx_rollup_return_bond",
   147  		OpTypeTxRollupFinalizeCommitment:      "tx_rollup_finalize_commitment",
   148  		OpTypeTxRollupRemoveCommitment:        "tx_rollup_remove_commitment",
   149  		OpTypeTxRollupRejection:               "tx_rollup_rejection",
   150  		OpTypeTxRollupDispatchTickets:         "tx_rollup_dispatch_tickets",
   151  		OpTypeTransferTicket:                  "transfer_ticket",
   152  		OpTypeVdfRevelation:                   "vdf_revelation",
   153  		OpTypeIncreasePaidStorage:             "increase_paid_storage",
   154  		OpTypeEvent:                           "event",
   155  		OpTypeDrainDelegate:                   "drain_delegate",
   156  		OpTypeUpdateConsensusKey:              "update_consensus_key",
   157  		OpTypeSmartRollupOriginate:            "smart_rollup_originate",
   158  		OpTypeSmartRollupAddMessages:          "smart_rollup_add_messages",
   159  		OpTypeSmartRollupCement:               "smart_rollup_cement",
   160  		OpTypeSmartRollupPublish:              "smart_rollup_publish",
   161  		OpTypeSmartRollupRefute:               "smart_rollup_refute",
   162  		OpTypeSmartRollupTimeout:              "smart_rollup_timeout",
   163  		OpTypeSmartRollupExecuteOutboxMessage: "smart_rollup_execute_outbox_message",
   164  		OpTypeSmartRollupRecoverBond:          "smart_rollup_recover_bond",
   165  		OpTypeDalPublishCommitment:            "dal_publish_commitment",
   166  		OpTypeAttestation:                     "attestation",
   167  		OpTypeAttestationWithDal:              "attestation_with_dal",
   168  		OpTypePreattestation:                  "preattestation",
   169  		OpTypeDoublePreattestationEvidence:    "double_preattestation_evidence",
   170  		OpTypeDoubleAttestationEvidence:       "double_attestation_evidence",
   171  	}
   172  	opTypeReverseStrings = make(map[string]OpType)
   173  )
   174  
   175  func init() {
   176  	for n, v := range opTypeStrings {
   177  		opTypeReverseStrings[v] = n
   178  	}
   179  }
   180  
   181  func (t OpType) IsValid() bool {
   182  	return t != OpTypeInvalid
   183  }
   184  
   185  func (t *OpType) UnmarshalText(data []byte) error {
   186  	v := ParseOpType(string(data))
   187  	if !v.IsValid() {
   188  		return fmt.Errorf("tezos: invalid operation type '%s'", string(data))
   189  	}
   190  	*t = v
   191  	return nil
   192  }
   193  
   194  func (t OpType) MarshalText() ([]byte, error) {
   195  	return []byte(t.String()), nil
   196  }
   197  
   198  func ParseOpType(s string) OpType {
   199  	t, ok := opTypeReverseStrings[s]
   200  	if !ok {
   201  		t = OpTypeInvalid
   202  	}
   203  	return t
   204  }
   205  
   206  func (t OpType) String() string {
   207  	return opTypeStrings[t]
   208  }
   209  
   210  var (
   211  	// before Babylon v005
   212  	opTagV0 = map[OpType]byte{
   213  		OpTypeEndorsement:               0,
   214  		OpTypeSeedNonceRevelation:       1,
   215  		OpTypeDoubleEndorsementEvidence: 2,
   216  		OpTypeDoubleBakingEvidence:      3,
   217  		OpTypeActivateAccount:           4,
   218  		OpTypeProposals:                 5,
   219  		OpTypeBallot:                    6,
   220  		OpTypeReveal:                    7,
   221  		OpTypeTransaction:               8,
   222  		OpTypeOrigination:               9,
   223  		OpTypeDelegation:                10,
   224  	}
   225  	// Babylon v005 until Hangzhou v011
   226  	opTagV1 = map[OpType]byte{
   227  		OpTypeEndorsement:               0,
   228  		OpTypeSeedNonceRevelation:       1,
   229  		OpTypeDoubleEndorsementEvidence: 2,
   230  		OpTypeDoubleBakingEvidence:      3,
   231  		OpTypeActivateAccount:           4,
   232  		OpTypeProposals:                 5,
   233  		OpTypeBallot:                    6,
   234  		OpTypeReveal:                    107, // v005
   235  		OpTypeTransaction:               108, // v005
   236  		OpTypeOrigination:               109, // v005
   237  		OpTypeDelegation:                110, // v005
   238  		OpTypeEndorsementWithSlot:       10,  // v009
   239  		OpTypeFailingNoop:               17,  // v009
   240  		OpTypeRegisterConstant:          111, // v011
   241  	}
   242  	// Ithaca v012 and up
   243  	opTagV2 = map[OpType]byte{
   244  		OpTypeSeedNonceRevelation:             1,
   245  		OpTypeDoubleEndorsementEvidence:       2,
   246  		OpTypeDoubleBakingEvidence:            3,
   247  		OpTypeActivateAccount:                 4,
   248  		OpTypeProposals:                       5,
   249  		OpTypeBallot:                          6,
   250  		OpTypeReveal:                          107, // v005
   251  		OpTypeTransaction:                     108, // v005
   252  		OpTypeOrigination:                     109, // v005
   253  		OpTypeDelegation:                      110, // v005
   254  		OpTypeFailingNoop:                     17,  // v009
   255  		OpTypeRegisterConstant:                111, // v011
   256  		OpTypePreendorsement:                  20,  // v012
   257  		OpTypeEndorsement:                     21,  // v012
   258  		OpTypeAttestationWithDal:              23,  // v019
   259  		OpTypeDoublePreendorsementEvidence:    7,   // v012
   260  		OpTypeSetDepositsLimit:                112, // v012
   261  		OpTypeTxRollupOrigination:             150, // v013
   262  		OpTypeTxRollupSubmitBatch:             151, // v013
   263  		OpTypeTxRollupCommit:                  152, // v013
   264  		OpTypeTxRollupReturnBond:              153, // v013
   265  		OpTypeTxRollupFinalizeCommitment:      154, // v013
   266  		OpTypeTxRollupRemoveCommitment:        155, // v013
   267  		OpTypeTxRollupRejection:               156, // v013
   268  		OpTypeTxRollupDispatchTickets:         157, // v013
   269  		OpTypeTransferTicket:                  158, // v013
   270  		OpTypeVdfRevelation:                   8,   // v014
   271  		OpTypeIncreasePaidStorage:             113, // v014
   272  		OpTypeDrainDelegate:                   9,   // v015
   273  		OpTypeUpdateConsensusKey:              114, // v015
   274  		OpTypeSmartRollupOriginate:            200, // v016
   275  		OpTypeSmartRollupAddMessages:          201, // v016
   276  		OpTypeSmartRollupCement:               202, // v016
   277  		OpTypeSmartRollupPublish:              203, // v016
   278  		OpTypeSmartRollupRefute:               204, // v016
   279  		OpTypeSmartRollupTimeout:              205, // v016
   280  		OpTypeSmartRollupExecuteOutboxMessage: 206, // v016
   281  		OpTypeSmartRollupRecoverBond:          207, // v016
   282  	}
   283  	// Paris v019 and up
   284  	opTagV3 = map[OpType]byte{
   285  		OpTypeSeedNonceRevelation:             1,
   286  		OpTypeDoubleAttestationEvidence:       2, // v019
   287  		OpTypeDoubleBakingEvidence:            3,
   288  		OpTypeActivateAccount:                 4,
   289  		OpTypeProposals:                       5,
   290  		OpTypeBallot:                          6,
   291  		OpTypeReveal:                          107, // v005
   292  		OpTypeTransaction:                     108, // v005
   293  		OpTypeOrigination:                     109, // v005
   294  		OpTypeDelegation:                      110, // v005
   295  		OpTypeFailingNoop:                     17,  // v009
   296  		OpTypeRegisterConstant:                111, // v011
   297  		OpTypePreattestation:                  20,  // v019
   298  		OpTypeAttestation:                     21,  // v019
   299  		OpTypeAttestationWithDal:              23,  // v019
   300  		OpTypeDoublePreattestationEvidence:    7,   // v019
   301  		OpTypeSetDepositsLimit:                112, // v012
   302  		OpTypeTxRollupOrigination:             150, // v013
   303  		OpTypeTxRollupSubmitBatch:             151, // v013
   304  		OpTypeTxRollupCommit:                  152, // v013
   305  		OpTypeTxRollupReturnBond:              153, // v013
   306  		OpTypeTxRollupFinalizeCommitment:      154, // v013
   307  		OpTypeTxRollupRemoveCommitment:        155, // v013
   308  		OpTypeTxRollupRejection:               156, // v013
   309  		OpTypeTxRollupDispatchTickets:         157, // v013
   310  		OpTypeTransferTicket:                  158, // v013
   311  		OpTypeVdfRevelation:                   8,   // v014
   312  		OpTypeIncreasePaidStorage:             113, // v014
   313  		OpTypeDrainDelegate:                   9,   // v015
   314  		OpTypeUpdateConsensusKey:              114, // v015
   315  		OpTypeSmartRollupOriginate:            200, // v016
   316  		OpTypeSmartRollupAddMessages:          201, // v016
   317  		OpTypeSmartRollupCement:               202, // v016
   318  		OpTypeSmartRollupPublish:              203, // v016
   319  		OpTypeSmartRollupRefute:               204, // v016
   320  		OpTypeSmartRollupTimeout:              205, // v016
   321  		OpTypeSmartRollupExecuteOutboxMessage: 206, // v016
   322  		OpTypeSmartRollupRecoverBond:          207, // v016
   323  		OpTypeDalPublishCommitment:            230, // v019 FIXME: is this correct?
   324  	}
   325  )
   326  
   327  func (t OpType) TagVersion(ver int) byte {
   328  	var (
   329  		tag byte
   330  		ok  bool
   331  	)
   332  	switch ver {
   333  	case 0:
   334  		tag, ok = opTagV0[t]
   335  	case 1:
   336  		tag, ok = opTagV1[t]
   337  	default:
   338  		tag, ok = opTagV2[t]
   339  	}
   340  	if !ok {
   341  		return 255
   342  	}
   343  	return tag
   344  }
   345  
   346  func (t OpType) Tag() byte {
   347  	tag, ok := opTagV2[t]
   348  	if !ok {
   349  		tag = 255
   350  	}
   351  	return tag
   352  }
   353  
   354  var (
   355  	// before Babylon v005
   356  	opMinSizeV0 = map[byte]int{
   357  		0:  5,         // OpTypeEndorsement
   358  		1:  37,        // OpTypeSeedNonceRevelation
   359  		2:  9 + 2*101, // OpTypeDoubleEndorsementEvidence
   360  		3:  9 + 2*189, // OpTypeDoubleBakingEvidence (w/o seed_nonce_hash)
   361  		4:  41,        // OpTypeActivateAccount
   362  		5:  30,        // OpTypeProposals
   363  		6:  59,        // OpTypeBallot
   364  		7:  26 + 32,   // OpTypeReveal (assuming shortest pk)
   365  		8:  49,        // OpTypeTransaction
   366  		9:  53,        // OpTypeOrigination
   367  		10: 26,        // OpTypeDelegation
   368  	}
   369  	// Babylon v005 until Hangzhou v011
   370  	opMinSizeV1 = map[byte]int{
   371  		0:   5,          // OpTypeEndorsement // <v009
   372  		1:   37,         // OpTypeSeedNonceRevelation
   373  		2:   11 + 2*101, // OpTypeDoubleEndorsementEvidence
   374  		3:   9 + 2*189,  // OpTypeDoubleBakingEvidence (w/o seed_nonce_hash, lb_escape_vote)
   375  		4:   41,         // OpTypeActivateAccount
   376  		5:   30,         // OpTypeProposals
   377  		6:   59,         // OpTypeBallot
   378  		107: 26 + 32,    // OpTypeReveal // v005 (assuming shortest pk)
   379  		108: 50,         // OpTypeTransaction // v005
   380  		109: 28,         // OpTypeOrigination // v005
   381  		110: 27,         // OpTypeDelegation // v005
   382  		10:  108,        // OpTypeEndorsementWithSlot // v009
   383  		17:  5,          // OpTypeFailingNoop  // v009
   384  		111: 30,         // OpTypeRegisterConstant // v011
   385  	}
   386  	// Ithaca v012 and up
   387  	opMinSizeV2 = map[byte]int{
   388  		1:   37,                       // OpTypeSeedNonceRevelation
   389  		2:   9 + 2*(32+43+64),         // OpTypeDoubleEndorsementEvidence
   390  		3:   9 + 2*237,                // OpTypeDoubleBakingEvidence (w/o seed_nonce_hash, min fitness size)
   391  		4:   41,                       // OpTypeActivateAccount
   392  		5:   30,                       // OpTypeProposals
   393  		6:   59,                       // OpTypeBallot
   394  		107: 26 + 32,                  // OpTypeReveal // v005 (assuming shortest pk)
   395  		108: 50,                       // OpTypeTransaction // v005
   396  		109: 28,                       // OpTypeOrigination // v005
   397  		110: 27,                       // OpTypeDelegation // v005
   398  		17:  5,                        // OpTypeFailingNoop  // v009
   399  		111: 30,                       // OpTypeRegisterConstant // v011
   400  		7:   9 + 2*(32+43+64),         // OpTypeDoublePreendorsementEvidence // v012
   401  		20:  43,                       // OpTypePreendorsement // v012
   402  		21:  43,                       // OpTypeEndorsement // v012
   403  		112: 27,                       // OpTypeSetDepositsLimit // v012
   404  		8:   201,                      // OpTypeVdfRevelation // v014
   405  		113: 27 + 22,                  // OpTypeIncreasePaidStorage // v014
   406  		9:   1 + 3*21,                 // OpTypeDrainDelegate // v015
   407  		114: 26 + 32,                  // OpTypeUpdateConsensusKey // v015
   408  		158: 26 + 8 + 22 + 1 + 22 + 4, // OpTypeTransferTicket // v013
   409  		200: 26 + 13,                  // OpTypeSmartRollupOriginate // v016
   410  		201: 26 + 4,                   // OpTypeSmartRollupAddMessages // v016
   411  		202: 26 + 52,                  // OpTypeSmartRollupCement // v016
   412  		203: 26 + 96,                  // OpTypeSmartRollupPublish // v016
   413  		204: 26 + 41,                  // OpTypeSmartRollupRefute // v016
   414  		205: 26 + 62,                  // OpTypeSmartRollupTimeout // v016
   415  		206: 26 + 56,                  // OpTypeSmartRollupExecuteOutboxMessage // v016
   416  		207: 26 + 41,                  // OpTypeSmartRollupRecoverBond // v016
   417  
   418  		// FIXME:
   419  		230: 26 + 101, // OpTypeDalPublishCommitment // v019
   420  		23:  43 + 1,   // OpTypeAttestationWithDal // v019 (assuming smallest slot number)
   421  	}
   422  	// Paris v019 and up
   423  	opMinSizeV3 = map[byte]int{
   424  		1:   37,                       // OpTypeSeedNonceRevelation
   425  		2:   9 + 2*(32+43+64),         // OpTypeDoubleAttestationEvidence
   426  		3:   9 + 2*237,                // OpTypeDoubleBakingEvidence (w/o seed_nonce_hash, min fitness size)
   427  		4:   41,                       // OpTypeActivateAccount
   428  		5:   30,                       // OpTypeProposals
   429  		6:   59,                       // OpTypeBallot
   430  		107: 26 + 32,                  // OpTypeReveal // v005 (assuming shortest pk)
   431  		108: 50,                       // OpTypeTransaction // v005
   432  		109: 28,                       // OpTypeOrigination // v005
   433  		110: 27,                       // OpTypeDelegation // v005
   434  		17:  5,                        // OpTypeFailingNoop  // v009
   435  		111: 30,                       // OpTypeRegisterConstant // v011
   436  		7:   9 + 2*(32+43+64),         // OpTypeDoublePreattestationEvidence // v019
   437  		20:  43,                       // OpTypePreattestation // v019
   438  		21:  43,                       // OpTypeAttestation // v019
   439  		23:  43 + 1,                   // OpTypeAttestationWithDal // v019 (assuming smallest slot number)
   440  		112: 27,                       // OpTypeSetDepositsLimit // v012
   441  		8:   201,                      // OpTypeVdfRevelation // v014
   442  		113: 27 + 22,                  // OpTypeIncreasePaidStorage // v014
   443  		9:   1 + 3*21,                 // OpTypeDrainDelegate // v015
   444  		114: 26 + 32,                  // OpTypeUpdateConsensusKey // v015
   445  		158: 26 + 8 + 22 + 1 + 22 + 4, // OpTypeTransferTicket // v013
   446  		200: 26 + 13,                  // OpTypeSmartRollupOriginate // v016
   447  		201: 26 + 4,                   // OpTypeSmartRollupAddMessages // v016
   448  		202: 26 + 52,                  // OpTypeSmartRollupCement // v016
   449  		203: 26 + 96,                  // OpTypeSmartRollupPublish // v016
   450  		204: 26 + 41,                  // OpTypeSmartRollupRefute // v016
   451  		205: 26 + 62,                  // OpTypeSmartRollupTimeout // v016
   452  		206: 26 + 56,                  // OpTypeSmartRollupExecuteOutboxMessage // v016
   453  		207: 26 + 41,                  // OpTypeSmartRollupRecoverBond // v016
   454  		230: 26 + 101,                 // OpTypeDalPublishCommitment // v019
   455  	}
   456  )
   457  
   458  func (t OpType) MinSizeVersion(ver int) int {
   459  	switch ver {
   460  	case 0:
   461  		return opMinSizeV0[t.TagVersion(ver)]
   462  	case 1:
   463  		return opMinSizeV1[t.TagVersion(ver)]
   464  	case 2:
   465  		return opMinSizeV2[t.TagVersion(ver)]
   466  	default:
   467  		return opMinSizeV3[t.TagVersion(ver)]
   468  	}
   469  }
   470  
   471  func (t OpType) MinSize() int {
   472  	return opMinSizeV3[t.Tag()]
   473  }
   474  
   475  func (t OpType) ListId() int {
   476  	switch t {
   477  	case OpTypeEndorsement, OpTypeEndorsementWithSlot, OpTypePreendorsement,
   478  		OpTypeAttestation, OpTypePreattestation, OpTypeAttestationWithDal:
   479  		return 0
   480  	case OpTypeProposals, OpTypeBallot:
   481  		return 1
   482  	case OpTypeActivateAccount,
   483  		OpTypeDoubleBakingEvidence,
   484  		OpTypeDoubleEndorsementEvidence,
   485  		OpTypeSeedNonceRevelation,
   486  		OpTypeDoublePreendorsementEvidence,
   487  		OpTypeVdfRevelation,
   488  		OpTypeDrainDelegate,
   489  		OpTypeDoubleAttestationEvidence,
   490  		OpTypeDoublePreattestationEvidence:
   491  		return 2
   492  	case OpTypeTransaction, // generic user operations
   493  		OpTypeOrigination,
   494  		OpTypeDelegation,
   495  		OpTypeReveal,
   496  		OpTypeRegisterConstant,
   497  		OpTypeSetDepositsLimit,
   498  		OpTypeTxRollupOrigination,
   499  		OpTypeTxRollupSubmitBatch,
   500  		OpTypeTxRollupCommit,
   501  		OpTypeTxRollupReturnBond,
   502  		OpTypeTxRollupFinalizeCommitment,
   503  		OpTypeTxRollupRemoveCommitment,
   504  		OpTypeTxRollupRejection,
   505  		OpTypeTxRollupDispatchTickets,
   506  		OpTypeTransferTicket,
   507  		OpTypeUpdateConsensusKey,
   508  		OpTypeSmartRollupOriginate,
   509  		OpTypeSmartRollupAddMessages,
   510  		OpTypeSmartRollupCement,
   511  		OpTypeSmartRollupPublish,
   512  		OpTypeSmartRollupRefute,
   513  		OpTypeSmartRollupTimeout,
   514  		OpTypeSmartRollupExecuteOutboxMessage,
   515  		OpTypeSmartRollupRecoverBond,
   516  		OpTypeDalPublishCommitment:
   517  		return 3
   518  	default:
   519  		return -1 // invalid
   520  	}
   521  }
   522  
   523  func ParseOpTag(t byte) OpType {
   524  	switch t {
   525  	case 0:
   526  		return OpTypeAttestation
   527  	case 1:
   528  		return OpTypeSeedNonceRevelation
   529  	case 2:
   530  		return OpTypeDoubleAttestationEvidence
   531  	case 3:
   532  		return OpTypeDoubleBakingEvidence
   533  	case 4:
   534  		return OpTypeActivateAccount
   535  	case 5:
   536  		return OpTypeProposals
   537  	case 6:
   538  		return OpTypeBallot
   539  	case 7:
   540  		return OpTypeDoublePreattestationEvidence
   541  	case 8:
   542  		return OpTypeVdfRevelation
   543  	case 9:
   544  		return OpTypeDrainDelegate
   545  	case 10:
   546  		return OpTypeEndorsementWithSlot
   547  	case 17:
   548  		return OpTypeFailingNoop
   549  	case 20:
   550  		return OpTypePreattestation
   551  	case 21:
   552  		return OpTypeEndorsement
   553  	case 23:
   554  		return OpTypeAttestationWithDal
   555  	case 107:
   556  		return OpTypeReveal
   557  	case 108:
   558  		return OpTypeTransaction
   559  	case 109:
   560  		return OpTypeOrigination
   561  	case 110:
   562  		return OpTypeDelegation
   563  	case 111:
   564  		return OpTypeRegisterConstant
   565  	case 112:
   566  		return OpTypeSetDepositsLimit
   567  	case 113:
   568  		return OpTypeIncreasePaidStorage
   569  	case 114:
   570  		return OpTypeUpdateConsensusKey
   571  	case 150:
   572  		return OpTypeTxRollupOrigination
   573  	case 151:
   574  		return OpTypeTxRollupSubmitBatch
   575  	case 152:
   576  		return OpTypeTxRollupCommit
   577  	case 153:
   578  		return OpTypeTxRollupReturnBond
   579  	case 154:
   580  		return OpTypeTxRollupFinalizeCommitment
   581  	case 155:
   582  		return OpTypeTxRollupRemoveCommitment
   583  	case 156:
   584  		return OpTypeTxRollupRejection
   585  	case 157:
   586  		return OpTypeTxRollupDispatchTickets
   587  	case 158:
   588  		return OpTypeTransferTicket
   589  	case 200:
   590  		return OpTypeSmartRollupOriginate
   591  	case 201:
   592  		return OpTypeSmartRollupAddMessages
   593  	case 202:
   594  		return OpTypeSmartRollupCement
   595  	case 203:
   596  		return OpTypeSmartRollupPublish
   597  	case 204:
   598  		return OpTypeSmartRollupRefute
   599  	case 205:
   600  		return OpTypeSmartRollupTimeout
   601  	case 206:
   602  		return OpTypeSmartRollupExecuteOutboxMessage
   603  	case 207:
   604  		return OpTypeSmartRollupRecoverBond
   605  	case 230:
   606  		return OpTypeDalPublishCommitment
   607  	default:
   608  		return OpTypeInvalid
   609  	}
   610  }
   611  
   612  func ParseOpTagVersion(t byte, ver int) OpType {
   613  	tags := opTagV0
   614  	switch ver {
   615  	case 1:
   616  		tags = opTagV1
   617  	case 2:
   618  		tags = opTagV2
   619  	case 3:
   620  		tags = opTagV3
   621  	}
   622  	for typ, tag := range tags {
   623  		if tag == t {
   624  			return typ
   625  		}
   626  	}
   627  	return OpTypeInvalid
   628  }