utils

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MPL-2.0 Imports: 20 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteAndBroadcastTxCli

func CompleteAndBroadcastTxCli(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error

CompleteAndBroadcastTxCli implements a utility function that facilitates sending a series of messages in a signed transaction given a TxBuilder and a QueryContext. It ensures that the account exists, has a proper number and sequence set. In addition, it builds and signs a transaction with the supplied messages. Finally, it broadcasts the signed transaction to a node. NOTE: Also see CompleteAndBroadcastTxREST.

func CompleteAndBroadcastTxREST

func CompleteAndBroadcastTxREST(w http.ResponseWriter, r *http.Request, cliCtx context.CLIContext, baseReq BaseReq, msgs []sdk.Msg, cdc *codec.Codec)

CompleteAndBroadcastTxREST implements a utility function that facilitates sending a series of messages in a signed transaction given a TxBuilder and a QueryContext. It ensures that the account exists, has a proper number and sequence set. In addition, it builds and signs a transaction with the supplied messages. Finally, it broadcasts the signed transaction to a node.

NOTE: Also see CompleteAndBroadcastTxCli. NOTE: Also see x/stake/client/rest/tx.go delegationsRequestHandlerFn.

func GenerateOrBroadcastMsgs

func GenerateOrBroadcastMsgs(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) error

func HasDryRunArg

func HasDryRunArg(r *http.Request) bool

HasDryRunArg returns true if the request's URL query contains the dry run argument and its value is set to "true".

func HasGenerateOnlyArg

func HasGenerateOnlyArg(r *http.Request) bool

HasGenerateOnlyArg returns whether a URL's query "generate-only" parameter is set to "true".

func ParseFloat64OrReturnBadRequest

func ParseFloat64OrReturnBadRequest(w http.ResponseWriter, s string, defaultIfEmpty float64) (n float64, ok bool)

ParseFloat64OrReturnBadRequest converts s to a float64 value. It returns a default value, defaultIfEmpty, if the string is empty.

func ParseInt64OrReturnBadRequest

func ParseInt64OrReturnBadRequest(w http.ResponseWriter, s string) (n int64, ok bool)

ParseInt64OrReturnBadRequest converts s to a int64 value.

func PostProcessResponse

func PostProcessResponse(w http.ResponseWriter, cdc *codec.Codec, response interface{}, indent bool)

PostProcessResponse performs post process for rest response

func PrintUnsignedStdTx

func PrintUnsignedStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, msgs []sdk.Msg) (err error)

PrintUnsignedStdTx builds an unsigned StdTx and prints it to os.Stdout. Don't perform online validation or lookups if offline is true.

func ReadRESTReq

func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.Codec, req interface{}) error

ReadRESTReq is a simple convenience wrapper that reads the body and unmarshals to the req interface.

  Usage:
    type SomeReq struct {
      BaseReq            `json:"base_req"`
      CustomField string `json:"custom_field"`
		}

    req := new(SomeReq)
    err := ReadRESTReq(w, r, cdc, req)

func SignStdTx

func SignStdTx(txBldr authtxb.TxBuilder, cliCtx context.CLIContext, name string, stdTx auth.StdTx, appendSig bool, offline bool) (auth.StdTx, error)

SignStdTx appends a signature to a StdTx and returns a copy of a it. If appendSig is false, it replaces the signatures already attached with the new signature. Don't perform online validation or lookups if offline is true.

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.

func WriteGenerateStdTxResponse

func WriteGenerateStdTxResponse(w http.ResponseWriter, txBldr authtxb.TxBuilder, msgs []sdk.Msg)

WriteGenerateStdTxResponse writes response for the generate_only mode.

func WriteSimulationResponse

func WriteSimulationResponse(w http.ResponseWriter)

Types

type BaseReq

type BaseReq struct {
	Name          string `json:"name"`
	Password      string `json:"password"`
	ChainID       string `json:"chain_id"`
	AccountNumber int64  `json:"account_number"`
	Sequence      int64  `json:"sequence"`
}

BaseReq defines a structure that can be embedded in other request structures that all share common "base" fields.

func (BaseReq) Sanitize

func (br BaseReq) Sanitize() BaseReq

Sanitize performs basic sanitization on a BaseReq object.

func (BaseReq) ValidateBasic

func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool

ValidateBasic performs basic validation of a BaseReq. If custom validation logic is needed, the implementing request handler should perform those checks manually.

Jump to

Keyboard shortcuts

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