routes

package
v0.37.10-migration-mai... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2024 License: AGPL-3.0 Imports: 37 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ExpandableFieldPayload    = "payload"
	ExpandableExecutionResult = "execution_result"
)
View Source
const BlockQueryParam = "block_ids"
View Source
const EventTypeQuery = "type"
View Source
const MaxRequestSize = 2 << 20 // 2MB

Variables

View Source
var Routes = []route{{
	Method:  http.MethodGet,
	Pattern: "/transactions/{id}",
	Name:    "getTransactionByID",
	Handler: GetTransactionByID,
}, {
	Method:  http.MethodPost,
	Pattern: "/transactions",
	Name:    "createTransaction",
	Handler: CreateTransaction,
}, {
	Method:  http.MethodGet,
	Pattern: "/transaction_results/{id}",
	Name:    "getTransactionResultByID",
	Handler: GetTransactionResultByID,
}, {
	Method:  http.MethodGet,
	Pattern: "/blocks/{id}",
	Name:    "getBlocksByIDs",
	Handler: GetBlocksByIDs,
}, {
	Method:  http.MethodGet,
	Pattern: "/blocks",
	Name:    "getBlocksByHeight",
	Handler: GetBlocksByHeight,
}, {
	Method:  http.MethodGet,
	Pattern: "/blocks/{id}/payload",
	Name:    "getBlockPayloadByID",
	Handler: GetBlockPayloadByID,
}, {
	Method:  http.MethodGet,
	Pattern: "/execution_results/{id}",
	Name:    "getExecutionResultByID",
	Handler: GetExecutionResultByID,
}, {
	Method:  http.MethodGet,
	Pattern: "/execution_results",
	Name:    "getExecutionResultByBlockID",
	Handler: GetExecutionResultsByBlockIDs,
}, {
	Method:  http.MethodGet,
	Pattern: "/collections/{id}",
	Name:    "getCollectionByID",
	Handler: GetCollectionByID,
}, {
	Method:  http.MethodPost,
	Pattern: "/scripts",
	Name:    "executeScript",
	Handler: ExecuteScript,
}, {
	Method:  http.MethodGet,
	Pattern: "/accounts/{address}",
	Name:    "getAccount",
	Handler: GetAccount,
}, {
	Method:  http.MethodGet,
	Pattern: "/accounts/{address}/balance",
	Name:    "getAccountBalance",
	Handler: GetAccountBalance,
}, {
	Method:  http.MethodGet,
	Pattern: "/accounts/{address}/keys/{index}",
	Name:    "getAccountKeyByIndex",
	Handler: GetAccountKeyByIndex,
}, {
	Method:  http.MethodGet,
	Pattern: "/accounts/{address}/keys",
	Name:    "getAccountKeys",
	Handler: GetAccountKeys,
}, {
	Method:  http.MethodGet,
	Pattern: "/events",
	Name:    "getEvents",
	Handler: GetEvents,
}, {
	Method:  http.MethodGet,
	Pattern: "/network/parameters",
	Name:    "getNetworkParameters",
	Handler: GetNetworkParameters,
}, {
	Method:  http.MethodGet,
	Pattern: "/node_version_info",
	Name:    "getNodeVersionInfo",
	Handler: GetNodeVersionInfo,
}}
View Source
var WSRoutes = []wsroute{{
	Method:  http.MethodGet,
	Pattern: "/subscribe_events",
	Name:    "subscribeEvents",
	Handler: SubscribeEvents,
}}

Functions

func CreateTransaction

func CreateTransaction(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

CreateTransaction creates a new transaction from provided payload.

func ExecuteScript

func ExecuteScript(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

ExecuteScript handler sends the script from the request to be executed.

func GetAccount

func GetAccount(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetAccount handler retrieves account by address and returns the response

func GetAccountBalance added in v0.37.1

func GetAccountBalance(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetAccountBalance handler retrieves an account balance by address and block height and returns the response

func GetAccountKeyByIndex

func GetAccountKeyByIndex(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetAccountKeyByIndex handler retrieves an account key by address and index and returns the response

func GetAccountKeys added in v0.37.1

func GetAccountKeys(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetAccountKeys handler retrieves an account keys by address and returns the response

func GetBlockPayloadByID

func GetBlockPayloadByID(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetBlockPayloadByID gets block payload by ID

func GetBlocksByHeight

func GetBlocksByHeight(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetBlocksByHeight gets blocks by height.

func GetBlocksByIDs

func GetBlocksByIDs(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetBlocksByIDs gets blocks by provided ID or list of IDs.

func GetCollectionByID

func GetCollectionByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetCollectionByID retrieves a collection by ID and builds a response

func GetEvents

func GetEvents(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetEvents for the provided block range or list of block IDs filtered by type.

func GetExecutionResultByID

func GetExecutionResultByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetExecutionResultByID gets execution result by the ID.

func GetExecutionResultsByBlockIDs

func GetExecutionResultsByBlockIDs(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetExecutionResultsByBlockIDs gets Execution Result payload by block IDs.

func GetNetworkParameters

func GetNetworkParameters(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetNetworkParameters returns network-wide parameters of the blockchain

func GetNodeVersionInfo

func GetNodeVersionInfo(r *request.Request, backend access.API, _ models.LinkGenerator) (interface{}, error)

GetNodeVersionInfo returns node version information

func GetTransactionByID

func GetTransactionByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetTransactionByID gets a transaction by requested ID.

func GetTransactionResultByID

func GetTransactionResultByID(r *request.Request, backend access.API, link models.LinkGenerator) (interface{}, error)

GetTransactionResultByID retrieves transaction result by the transaction ID.

func NewBlockProvider

func NewBlockProvider(backend access.API, options ...blockProviderOption) *blockProvider

func SubscribeEvents

func SubscribeEvents(
	ctx context.Context,
	request *request.Request,
	wsController *WebsocketController,
) (subscription.Subscription, error)

SubscribeEvents create websocket connection and write to it requested events.

func URLToRoute

func URLToRoute(url string) (string, error)

Types

type ApiHandlerFunc

type ApiHandlerFunc func(
	r *request.Request,
	backend access.API,
	generator models.LinkGenerator,
) (interface{}, error)

ApiHandlerFunc is a function that contains endpoint handling logic, it fetches necessary resources and returns an error or response model.

type Handler

type Handler struct {
	*HttpHandler
	// contains filtered or unexported fields
}

Handler is custom http handler implementing custom handler function. Handler function allows easier handling of errors and responses as it wraps functionality for handling error and responses outside of endpoint handling.

func NewHandler

func NewHandler(
	logger zerolog.Logger,
	backend access.API,
	handlerFunc ApiHandlerFunc,
	generator models.LinkGenerator,
	chain flow.Chain,
) *Handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServerHTTP function acts as a wrapper to each request providing common handling functionality such as logging, error handling, request decorators

type HttpHandler

type HttpHandler struct {
	Logger zerolog.Logger
	Chain  flow.Chain
}

HttpHandler is custom http handler implementing custom handler function. HttpHandler function allows easier handling of errors and responses as it wraps functionality for handling error and responses outside of endpoint handling.

func NewHttpHandler

func NewHttpHandler(
	logger zerolog.Logger,
	chain flow.Chain,
) *HttpHandler

func (*HttpHandler) VerifyRequest

func (h *HttpHandler) VerifyRequest(w http.ResponseWriter, r *http.Request) error

VerifyRequest function acts as a wrapper to each request providing common handling functionality such as logging, error handling

type RouterBuilder

type RouterBuilder struct {
	// contains filtered or unexported fields
}

RouterBuilder is a utility for building HTTP routers with common middleware and routes.

func NewRouterBuilder

func NewRouterBuilder(
	logger zerolog.Logger,
	restCollector module.RestMetrics) *RouterBuilder

NewRouterBuilder creates a new RouterBuilder instance with common middleware and a v1 sub-router.

func (*RouterBuilder) AddRestRoutes

func (b *RouterBuilder) AddRestRoutes(backend access.API, chain flow.Chain) *RouterBuilder

AddRestRoutes adds rest routes to the router.

func (*RouterBuilder) AddWsRoutes

func (b *RouterBuilder) AddWsRoutes(
	stateStreamApi state_stream.API,
	chain flow.Chain,
	stateStreamConfig backend.Config,
) *RouterBuilder

AddWsRoutes adds WebSocket routes to the router.

func (*RouterBuilder) Build

func (b *RouterBuilder) Build() *mux.Router

type SubscribeHandlerFunc

type SubscribeHandlerFunc func(
	ctx context.Context,
	request *request.Request,
	wsController *WebsocketController,
) (subscription.Subscription, error)

SubscribeHandlerFunc is a function that contains endpoint handling logic for subscribes, fetches necessary resources

type WSHandler

type WSHandler struct {
	*HttpHandler
	// contains filtered or unexported fields
}

WSHandler is websocket handler implementing custom websocket handler function and allows easier handling of errors and responses as it wraps functionality for handling error and responses outside of endpoint handling.

func NewWSHandler

func NewWSHandler(
	logger zerolog.Logger,
	api state_stream.API,
	subscribeFunc SubscribeHandlerFunc,
	chain flow.Chain,
	stateStreamConfig backend.Config,
) *WSHandler

func (*WSHandler) ServeHTTP

func (h *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP function acts as a wrapper to each request providing common handling functionality such as logging, error handling, request decorators

type WebsocketController

type WebsocketController struct {
	// contains filtered or unexported fields
}

WebsocketController holds the necessary components and parameters for handling a WebSocket subscription. It manages the communication between the server and the WebSocket client for subscribing.

func (*WebsocketController) SetWebsocketConf

func (wsController *WebsocketController) SetWebsocketConf() error

SetWebsocketConf used to set read and write deadlines for WebSocket connections and establishes a Pong handler to manage incoming Pong messages. These methods allow to specify a time limit for reading from or writing to a WebSocket connection. If the operation (reading or writing) takes longer than the specified deadline, the connection will be closed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL