rest

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RestParamsType     = "type"
	RestProposalID     = "proposal-id"
	RestDepositor      = "depositor"
	RestVoter          = "voter"
	RestProposalStatus = "status"
)

REST Variable names

View Source
const (
	DeprecationURL = "https://docs.cosmos.network/master/migrations/rest.html"

	DefaultPage    = 1
	DefaultLimit   = 30             // should be consistent with tendermint/tendermint/rpc/core/pipe.go:19
	TxMinHeightKey = "tx.minheight" // Inclusive minimum height filter
	TxMaxHeightKey = "tx.maxheight" // Inclusive maximum height filter

	MethodGet = "GET"
)

DeprecationURL is the URL for migrating deprecated REST endpoints to newer ones. TODO Switch to `/` (not `/master`) once v0.40 docs are deployed. https://github.com/cosmos/cosmos-sdk/issues/8019

View Source
const RestParamEvidenceHash = "evidence-hash"

Variables

This section is empty.

Functions

func BlockRequestHandlerFn

func BlockRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

BlockRequestHandlerFn REST handler to get a block

func CheckBadRequestError

func CheckBadRequestError(w http.ResponseWriter, err error) bool

CheckBadRequestError attaches an error message to an HTTP 400 BAD REQUEST response. Returns false when err is nil; it returns true otherwise.

func CheckError

func CheckError(w http.ResponseWriter, status int, err error) bool

CheckError takes care of writing an error response if err is not nil. Returns false when err is nil; it returns true otherwise.

func CheckInternalServerError

func CheckInternalServerError(w http.ResponseWriter, err error) bool

CheckInternalServerError attaches an error message to an HTTP 500 INTERNAL SERVER ERROR response. Returns false when err is nil; it returns true otherwise.

func CheckNotFoundError

func CheckNotFoundError(w http.ResponseWriter, err error) bool

CheckNotFoundError attaches an error message to an HTTP 404 NOT FOUND response. Returns false when err is nil; it returns true otherwise.

func ConvertTxToStdTx

func ConvertTxToStdTx(codec *codec.LegacyAmino, tx signing.Tx) (legacytx.StdTx, error)

ConvertTxToStdTx converts a transaction to the legacy StdTx format

func CopyTx

func CopyTx(tx signing.Tx, builder client.TxBuilder, ignoreSignatureError bool) error

CopyTx copies a Tx to a new TxBuilder, allowing conversion between different transaction formats. If ignoreSignatureError is true, copying will continue tx even if the signature cannot be set in the target builder resulting in an unsigned tx.

func DecodeTxRequestHandlerFn

func DecodeTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

DecodeTxRequestHandlerFn returns the decode tx REST handler. In particular, it takes base64-decoded bytes, decodes it from the Amino wire protocol, and responds with a json-formatted transaction.

func GetChainHeight

func GetChainHeight(clientCtx client.Context) (int64, error)

GetChainHeight get the current blockchain height

func LatestBlockRequestHandlerFn

func LatestBlockRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

LatestBlockRequestHandlerFn REST handler to get the latest block

func LatestValidatorSetRequestHandlerFn

func LatestValidatorSetRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

LatestValidatorSetRequestHandlerFn Latest Validator Set REST handler

func NodeInfoRequestHandlerFn

func NodeInfoRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

NodeInfoRequestHandlerFn REST handler for node info

func NodeSyncingRequestHandlerFn

func NodeSyncingRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

NodeSyncingRequestHandlerFn REST handler for node syncing

func ParseHTTPArgs

func ParseHTTPArgs(r *http.Request) (tags []string, page, limit int, err error)

ParseHTTPArgs parses the request's URL and returns a slice containing all arguments pairs. It separates page and limit used for pagination.

func ParseHTTPArgsWithLimit

func ParseHTTPArgsWithLimit(r *http.Request, defaultLimit int) (tags []string, page, limit int, err error)

ParseHTTPArgsWithLimit parses the request's URL and returns a slice containing all arguments pairs. It separates page and limit used for pagination where a default limit can be provided.

func ParseQueryHeightOrReturnBadRequest

func ParseQueryHeightOrReturnBadRequest(w http.ResponseWriter, clientCtx client.Context, r *http.Request) (client.Context, bool)

ParseQueryHeightOrReturnBadRequest sets the height to execute a query if set by the http request. It returns false if there was an error parsing the height.

func ParseUint64OrReturnBadRequest

func ParseUint64OrReturnBadRequest(w http.ResponseWriter, s string) (n uint64, ok bool)

ParseUint64OrReturnBadRequest converts s to a uint64 value.

func PostProcessResponse

func PostProcessResponse(w http.ResponseWriter, ctx client.Context, resp interface{})

PostProcessResponse performs post processing for a REST response. The result returned to clients will contain two fields, the height at which the resource was queried at and the original result.

func PostProcessResponseBare

func PostProcessResponseBare(w http.ResponseWriter, ctx client.Context, body interface{})

PostProcessResponseBare post processes a body similar to PostProcessResponse except it does not wrap the body and inject the height.

func QueryAccountRequestHandlerFn

func QueryAccountRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

QueryAccountRequestHandlerFn is the query accountREST Handler.

func QueryBalancesRequestHandlerFn

func QueryBalancesRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

QueryBalancesRequestHandlerFn returns a REST handler that queries for all account balances or a specific balance by denomination.

func QueryDepositByTxQuery

func QueryDepositByTxQuery(clientCtx client.Context, params govv1beta1.QueryDepositParams) ([]byte, error)

QueryDepositByTxQuery will query for a single deposit via a direct txs tags query.

func QueryDepositsByTxQuery

func QueryDepositsByTxQuery(clientCtx client.Context, params govv1beta1.QueryProposalParams) ([]byte, error)

QueryDepositsByTxQuery will query for deposits via a direct txs tags query. It will fetch and build deposits directly from the returned txs and return a JSON marshalled result or any error that occurred.

NOTE: SearchTxs is used to facilitate the txs query which does not currently support configurable pagination.

func QueryGenesisTxs

func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter)

QueryGenesisTxs writes the genesis transactions to the response if no error occurs.

func QueryTxRequestHandlerFn

func QueryTxRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

QueryTxRequestHandlerFn implements a REST handler that queries a transaction by hash in a committed block.

func QueryTxsRequestHandlerFn

func QueryTxsRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

QueryTxsRequestHandlerFn implements a REST handler that searches for transactions. Genesis transactions are returned if the height parameter is set to zero, otherwise the transactions are searched for by events.

func QueryVoteByTxQuery

func QueryVoteByTxQuery(clientCtx client.Context, params govv1beta1.QueryVoteParams) ([]byte, error)

QueryVoteByTxQuery will query for a single vote via a direct txs tags query.

func QueryVotesByTxQuery

func QueryVotesByTxQuery(clientCtx client.Context, params govv1beta1.QueryProposalVotesParams) ([]byte, error)

QueryVotesByTxQuery will query for votes via a direct txs tags query. It will fetch and build votes directly from the returned txs and return a JSON marshalled result or any error that occurred.

func RegisterAuthRESTRoutes

func RegisterAuthRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterAuthRESTRoutes registers the auth module REST routes. Deprecated

func RegisterBankRESTRoutes

func RegisterBankRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterBankRESTRoutes registers all x/bank transaction and query HTTP REST handlers on the provided mux router. Deprecated

func RegisterDistributeRESTRoutes

func RegisterDistributeRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterDistributeRESTRoutes Deprecated

func RegisterEvidenceRESTRoutes

func RegisterEvidenceRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterEvidenceRESTRoutes registers all Evidence submission handlers for the evidence module's REST service handler. Deprecated

func RegisterGovRESTRoutes

func RegisterGovRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterGovRESTRoutes Deprecated

func RegisterMintRESTRoutes

func RegisterMintRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterMintRESTRoutes registers minting module REST handlers on the provided router. Deprecated

func RegisterRPCRoutes

func RegisterRPCRoutes(clientCtx client.Context, r *mux.Router)

RegisterRPCRoutes Register REST endpoints. Deprecated

func RegisterSlashingRESTRoutes

func RegisterSlashingRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterSlashingRESTRoutes Deprecated

func RegisterStakingRESTRoutes

func RegisterStakingRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterStakingRESTRoutes Deprecated

func RegisterTxRESTRoutes

func RegisterTxRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterTxRESTRoutes registers all transaction routes on the provided router. Deprecated

func RegisterUpgradeRESTRoutes

func RegisterUpgradeRESTRoutes(clientCtx client.Context, rtr *mux.Router)

RegisterUpgradeRESTRoutes registers REST routes for the upgrade module under the path specified by routeName. Deprecated

func ValidatorSetRequestHandlerFn

func ValidatorSetRequestHandlerFn(clientCtx client.Context) http.HandlerFunc

ValidatorSetRequestHandlerFn Validator Set at a height REST handler

func WithHTTPDeprecationHeaders

func WithHTTPDeprecationHeaders(r *mux.Router) *mux.Router

WithHTTPDeprecationHeaders returns a new *mux.Router, identical to its input but with the addition of HTTP Deprecation headers. This is used to mark legacy amino REST endpoints as deprecated in the REST API.

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, status int, err string)

WriteErrorResponse prepares and writes a HTTP error given a status code and an error message.

Types

type DecodeReq

type DecodeReq struct {
	Tx string `json:"tx"`
}

DecodeReq defines a tx decoding request.

type DecodeResp

type DecodeResp legacytx.StdTx

DecodeResp defines a tx decoding response.

type ErrorResponse

type ErrorResponse struct {
	Code  int    `json:"code,omitempty"`
	Error string `json:"error"`
}

ErrorResponse defines the attributes of a JSON error response.

func NewErrorResponse

func NewErrorResponse(code int, err string) ErrorResponse

NewErrorResponse creates a new ErrorResponse instance.

type GasEstimateResponse

type GasEstimateResponse struct {
	GasEstimate uint64 `json:"gas_estimate"`
}

GasEstimateResponse defines a response definition for tx gas estimation.

type NodeInfoResponse

type NodeInfoResponse struct {
	p2p.DefaultNodeInfo `json:"node_info"`

	ApplicationVersion version.Info `json:"application_version"`
}

NodeInfoResponse defines a response type that contains node status and version information.

type ResponseWithHeight

type ResponseWithHeight struct {
	Height int64           `json:"height"`
	Result json.RawMessage `json:"result"`
}

ResponseWithHeight defines a response object type that wraps an original response with a height.

func NewResponseWithHeight

func NewResponseWithHeight(height int64, result json.RawMessage) ResponseWithHeight

NewResponseWithHeight creates a new ResponseWithHeight instance

type ResultValidatorsOutput

type ResultValidatorsOutput struct {
	BlockHeight int64             `json:"block_height"`
	Validators  []ValidatorOutput `json:"validators"`
	Total       uint64            `json:"total"`
}

ResultValidatorsOutput Validators at a certain height output in bech32 format

func GetValidators

func GetValidators(ctx context.Context, clientCtx client.Context, height *int64, page, limit *int) (ResultValidatorsOutput, error)

GetValidators from client

func (ResultValidatorsOutput) String

func (rvo ResultValidatorsOutput) String() string

type SyncingResponse

type SyncingResponse struct {
	Syncing bool `json:"syncing"`
}

SyncingResponse defines a response type that contains node syncing information.

type ValidatorDistInfo

type ValidatorDistInfo struct {
	OperatorAddress     sdk.AccAddress                       `json:"operator_address" yaml:"operator_address"`
	SelfBondRewards     sdk.DecCoins                         `json:"self_bond_rewards" yaml:"self_bond_rewards"`
	ValidatorCommission types.ValidatorAccumulatedCommission `json:"val_commission" yaml:"val_commission"`
}

ValidatorDistInfo defines the properties of validator distribution information response.

func NewValidatorDistInfo

func NewValidatorDistInfo(operatorAddr sdk.AccAddress, rewards sdk.DecCoins,
	commission types.ValidatorAccumulatedCommission,
) ValidatorDistInfo

NewValidatorDistInfo creates a new instance of ValidatorDistInfo.

type ValidatorOutput

type ValidatorOutput struct {
	Address          sdk.ConsAddress    `json:"address"`
	PubKey           cryptotypes.PubKey `json:"pub_key"`
	ProposerPriority int64              `json:"proposer_priority"`
	VotingPower      int64              `json:"voting_power"`
}

ValidatorOutput Validator output

Jump to

Keyboard shortcuts

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