github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/sdk/types.go (about)

     1  package sdk
     2  
     3  import (
     4  	abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
     5  	"github.com/gnolang/gno/tm2/pkg/std"
     6  )
     7  
     8  // Router provides handlers for each transaction type.
     9  type Router interface {
    10  	AddRoute(r string, h Handler) Router
    11  	Route(path string) Handler
    12  }
    13  
    14  // A Handler handles processing messages and answering queries
    15  // for a particular application concern.
    16  type Handler interface {
    17  	// Process defines the core of the state transition function of an application.
    18  	Process(ctx Context, msg Msg) Result
    19  	// Query allows the state to be queried.
    20  	Query(ctx Context, req abci.RequestQuery) abci.ResponseQuery
    21  }
    22  
    23  // Result is the union of ResponseDeliverTx and ResponseCheckTx plus events.
    24  type Result struct {
    25  	abci.ResponseBase
    26  	GasWanted int64
    27  	GasUsed   int64
    28  }
    29  
    30  // AnteHandler authenticates transactions, before their internal messages are handled.
    31  type AnteHandler func(ctx Context, tx Tx, simulate bool) (newCtx Context, result Result, abort bool)
    32  
    33  // Exports from std.
    34  type Msg = std.Msg
    35  
    36  type (
    37  	Tx       = std.Tx
    38  	Coin     = std.Coin
    39  	Coins    = std.Coins
    40  	GasPrice = std.GasPrice
    41  )
    42  
    43  var (
    44  	ParseGasPrice  = std.ParseGasPrice
    45  	ParseGasPrices = std.ParseGasPrices
    46  )
    47  
    48  //----------------------------------------
    49  
    50  // Enum mode for app.runTx
    51  type RunTxMode uint8
    52  
    53  const (
    54  	// Check a transaction
    55  	RunTxModeCheck RunTxMode = iota
    56  	// Simulate a transaction
    57  	RunTxModeSimulate RunTxMode = iota
    58  	// Deliver a transaction
    59  	RunTxModeDeliver RunTxMode = iota
    60  )