github.com/algorand/go-algorand-sdk@v1.24.0/types/applications.go (about)

     1  package types
     2  
     3  // This file has the applications specific structures
     4  
     5  type ApplicationFields struct {
     6  	ApplicationCallTxnFields
     7  }
     8  
     9  // AppIndex is the unique integer index of an application that can be used to
    10  // look up the creator of the application, whose balance record contains the
    11  // AppParams
    12  type AppIndex uint64
    13  
    14  type AppBoxReference struct {
    15  	// The ID of the app that owns the box. Must be converted to BoxReference during transaction submission.
    16  	AppID uint64
    17  
    18  	// The Name of the box unique to the app it belongs to
    19  	Name []byte
    20  }
    21  
    22  type BoxReference struct {
    23  	_struct struct{} `codec:",omitempty,omitemptyarray"`
    24  
    25  	// The index of the app in the foreign app array.
    26  	ForeignAppIdx uint64 `codec:"i"`
    27  
    28  	// The name of the box unique to the app it belongs to
    29  	Name []byte `codec:"n"`
    30  }
    31  
    32  const (
    33  	// encodedMaxApplicationArgs sets the allocation bound for the maximum
    34  	// number of ApplicationArgs that a transaction decoded off of the wire
    35  	// can contain. Its value is verified against consensus parameters in
    36  	// TestEncodedAppTxnAllocationBounds
    37  	encodedMaxApplicationArgs = 32
    38  
    39  	// encodedMaxAccounts sets the allocation bound for the maximum number
    40  	// of Accounts that a transaction decoded off of the wire can contain.
    41  	// Its value is verified against consensus parameters in
    42  	// TestEncodedAppTxnAllocationBounds
    43  	encodedMaxAccounts = 32
    44  
    45  	// encodedMaxForeignApps sets the allocation bound for the maximum
    46  	// number of ForeignApps that a transaction decoded off of the wire can
    47  	// contain. Its value is verified against consensus parameters in
    48  	// TestEncodedAppTxnAllocationBounds
    49  	encodedMaxForeignApps = 32
    50  
    51  	// encodedMaxForeignAssets sets the allocation bound for the maximum
    52  	// number of ForeignAssets that a transaction decoded off of the wire
    53  	// can contain. Its value is verified against consensus parameters in
    54  	// TestEncodedAppTxnAllocationBounds
    55  	encodedMaxForeignAssets = 32
    56  
    57  	// encodedMaxBoxReferences sets the allocation bound for the maximum
    58  	// number of BoxReferences that a transaction decoded off of the wire
    59  	// can contain. Its value is verified against consensus parameters in
    60  	// TestEncodedAppTxnAllocationBounds
    61  	encodedMaxBoxReferences = 32
    62  )
    63  
    64  // OnCompletion is an enum representing some layer 1 side effect that an
    65  // ApplicationCall transaction will have if it is included in a block.
    66  //go:generate stringer -type=OnCompletion -output=application_string.go
    67  type OnCompletion uint64
    68  
    69  const (
    70  	// NoOpOC indicates that an application transaction will simply call its
    71  	// ApprovalProgram
    72  	NoOpOC OnCompletion = 0
    73  
    74  	// OptInOC indicates that an application transaction will allocate some
    75  	// LocalState for the application in the sender's account
    76  	OptInOC OnCompletion = 1
    77  
    78  	// CloseOutOC indicates that an application transaction will deallocate
    79  	// some LocalState for the application from the user's account
    80  	CloseOutOC OnCompletion = 2
    81  
    82  	// ClearStateOC is similar to CloseOutOC, but may never fail. This
    83  	// allows users to reclaim their minimum balance from an application
    84  	// they no longer wish to opt in to.
    85  	ClearStateOC OnCompletion = 3
    86  
    87  	// UpdateApplicationOC indicates that an application transaction will
    88  	// update the ApprovalProgram and ClearStateProgram for the application
    89  	UpdateApplicationOC OnCompletion = 4
    90  
    91  	// DeleteApplicationOC indicates that an application transaction will
    92  	// delete the AppParams for the application from the creator's balance
    93  	// record
    94  	DeleteApplicationOC OnCompletion = 5
    95  )
    96  
    97  // ApplicationCallTxnFields captures the transaction fields used for all
    98  // interactions with applications
    99  type ApplicationCallTxnFields struct {
   100  	_struct struct{} `codec:",omitempty,omitemptyarray"`
   101  
   102  	ApplicationID   AppIndex       `codec:"apid"`
   103  	OnCompletion    OnCompletion   `codec:"apan"`
   104  	ApplicationArgs [][]byte       `codec:"apaa,allocbound=encodedMaxApplicationArgs"`
   105  	Accounts        []Address      `codec:"apat,allocbound=encodedMaxAccounts"`
   106  	ForeignApps     []AppIndex     `codec:"apfa,allocbound=encodedMaxForeignApps"`
   107  	ForeignAssets   []AssetIndex   `codec:"apas,allocbound=encodedMaxForeignAssets"`
   108  	BoxReferences   []BoxReference `codec:"apbx,allocbound=encodedMaxBoxReferences"`
   109  
   110  	LocalStateSchema  StateSchema `codec:"apls"`
   111  	GlobalStateSchema StateSchema `codec:"apgs"`
   112  	ApprovalProgram   []byte      `codec:"apap"`
   113  	ClearStateProgram []byte      `codec:"apsu"`
   114  	ExtraProgramPages uint32      `codec:"apep"`
   115  
   116  	// If you add any fields here, remember you MUST modify the Empty
   117  	// method below!
   118  }
   119  
   120  // StateSchema sets maximums on the number of each type that may be stored
   121  type StateSchema struct {
   122  	_struct struct{} `codec:",omitempty,omitemptyarray"`
   123  
   124  	NumUint      uint64 `codec:"nui"`
   125  	NumByteSlice uint64 `codec:"nbs"`
   126  }
   127  
   128  // Empty indicates whether or not all the fields in the
   129  // ApplicationCallTxnFields are zeroed out
   130  func (ac *ApplicationCallTxnFields) Empty() bool {
   131  	if ac.ApplicationID != 0 {
   132  		return false
   133  	}
   134  	if ac.OnCompletion != 0 {
   135  		return false
   136  	}
   137  	if ac.ApplicationArgs != nil {
   138  		return false
   139  	}
   140  	if ac.Accounts != nil {
   141  		return false
   142  	}
   143  	if ac.ForeignApps != nil {
   144  		return false
   145  	}
   146  	if ac.ForeignAssets != nil {
   147  		return false
   148  	}
   149  	if ac.BoxReferences != nil {
   150  		return false
   151  	}
   152  	if ac.LocalStateSchema != (StateSchema{}) {
   153  		return false
   154  	}
   155  	if ac.GlobalStateSchema != (StateSchema{}) {
   156  		return false
   157  	}
   158  	if ac.ApprovalProgram != nil {
   159  		return false
   160  	}
   161  	if ac.ClearStateProgram != nil {
   162  		return false
   163  	}
   164  	if ac.ExtraProgramPages != 0 {
   165  		return false
   166  	}
   167  	return true
   168  }