rest

package
v0.31.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteAndBroadcastTxREST added in v0.31.0

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 tx. In addition, it will handle tx gas simulation and estimation.

NOTE: Also see CompleteAndBroadcastTxCLI.

func ParseFloat64OrReturnBadRequest added in v0.31.0

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 added in v0.31.0

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

ParseInt64OrReturnBadRequest converts s to a int64 value.

func ParseUint64OrReturnBadRequest added in v0.31.0

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

ParseUint64OrReturnBadRequest converts s to a uint64 value.

func PostProcessResponse added in v0.31.0

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

PostProcessResponse performs post processing for a REST response.

func ReadRESTReq added in v0.31.0

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

ReadRESTReq is a simple convenience wrapper that reads the body and unmarshals to the req interface. Returns false if errors occurred.

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

    req := new(SomeReq)
    if ok := ReadRESTReq(w, r, cdc, req); !ok {
        return
    }

func WriteErrorResponse added in v0.31.0

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 added in v0.31.0

func WriteGenerateStdTxResponse(
	w http.ResponseWriter, cdc *codec.Codec, cliCtx context.CLIContext, br BaseReq, msgs []sdk.Msg,
)

WriteGenerateStdTxResponse writes response for the generate only mode.

func WriteSimulationResponse added in v0.31.0

func WriteSimulationResponse(w http.ResponseWriter, cdc *codec.Codec, gas uint64)

WriteSimulationResponse prepares and writes an HTTP response for transactions simulations.

Types

type AddrSeed added in v0.31.0

type AddrSeed struct {
	Address  sdk.AccAddress
	Seed     string
	Name     string
	Password string
}

AddrSeed combines an Address with the mnemonic of the private key to that address

type BaseReq added in v0.31.0

type BaseReq struct {
	From          string       `json:"from"`
	Password      string       `json:"password"`
	Memo          string       `json:"memo"`
	ChainID       string       `json:"chain_id"`
	AccountNumber uint64       `json:"account_number"`
	Sequence      uint64       `json:"sequence"`
	Fees          sdk.Coins    `json:"fees"`
	GasPrices     sdk.DecCoins `json:"gas_prices"`
	Gas           string       `json:"gas"`
	GasAdjustment string       `json:"gas_adjustment"`
	GenerateOnly  bool         `json:"generate_only"`
	Simulate      bool         `json:"simulate"`
}

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

func NewBaseReq added in v0.31.0

func NewBaseReq(
	from, password, memo, chainID string, gas, gasAdjustment string,
	accNumber, seq uint64, fees sdk.Coins, gasPrices sdk.DecCoins, genOnly, simulate bool,
) BaseReq

NewBaseReq creates a new basic request instance and sanitizes its values

func (BaseReq) Sanitize added in v0.31.0

func (br BaseReq) Sanitize() BaseReq

Sanitize performs basic sanitization on a BaseReq object.

func (BaseReq) ValidateBasic added in v0.31.0

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.

type BroadcastReq added in v0.31.0

type BroadcastReq struct {
	Tx     auth.StdTx `json:"tx"`
	Return string     `json:"return"`
}

BroadcastReq requests broadcasting a transaction

type DepositReq added in v0.31.0

type DepositReq struct {
	BaseReq   BaseReq        `json:"base_req"`
	Depositor sdk.AccAddress `json:"depositor"` // Address of the depositor
	Amount    sdk.Coins      `json:"amount"`    // Coins to add to the proposal's deposit
}

DepositReq requests a deposit of an amount of coins

type ErrorResponse added in v0.31.0

type ErrorResponse struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message"`
}

ErrorResponse defines the attributes of a JSON error response.

func NewErrorResponse added in v0.31.0

func NewErrorResponse(code int, msg string) ErrorResponse

NewErrorResponse creates a new ErrorResponse instance.

type GasEstimateResponse added in v0.31.0

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

GasEstimateResponse defines a response definition for tx gas estimation.

type MsgBeginRedelegateInput added in v0.31.0

type MsgBeginRedelegateInput struct {
	BaseReq          BaseReq        `json:"base_req"`
	DelegatorAddr    sdk.AccAddress `json:"delegator_addr"`     // in bech32
	ValidatorSrcAddr sdk.ValAddress `json:"validator_src_addr"` // in bech32
	ValidatorDstAddr sdk.ValAddress `json:"validator_dst_addr"` // in bech32
	SharesAmount     sdk.Dec        `json:"shares"`
}

MsgBeginRedelegateInput request to begin a redelegation

type PostProposalReq added in v0.31.0

type PostProposalReq struct {
	BaseReq        BaseReq        `json:"base_req"`
	Title          string         `json:"title"`           //  Title of the proposal
	Description    string         `json:"description"`     //  Description of the proposal
	ProposalType   string         `json:"proposal_type"`   //  Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
	Proposer       sdk.AccAddress `json:"proposer"`        //  Address of the proposer
	InitialDeposit sdk.Coins      `json:"initial_deposit"` // Coins to add to the proposal's deposit
}

PostProposalReq requests a proposals

type SendReq added in v0.31.0

type SendReq struct {
	Amount  sdk.Coins `json:"amount"`
	BaseReq BaseReq   `json:"base_req"`
}

SendReq requests sending an amount of coins

type UnjailReq added in v0.31.0

type UnjailReq struct {
	BaseReq BaseReq `json:"base_req"`
}

UnjailReq request unjailing

type VoteReq added in v0.31.0

type VoteReq struct {
	BaseReq BaseReq        `json:"base_req"`
	Voter   sdk.AccAddress `json:"voter"`  //  address of the voter
	Option  string         `json:"option"` //  option from OptionSet chosen by the voter
}

VoteReq requests sending a vote

Jump to

Keyboard shortcuts

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