actions

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package actions provides the infrastructure for defining and executing actions (code that is triggered in response to an client request) on horizon. At present it allows for defining actions that can respond using JSON or SSE.

Index

Constants

View Source
const (
	// ParamCursor is a query string param name
	ParamCursor = "cursor"
	// ParamOrder is a query string param name
	ParamOrder = "order"
	// ParamLimit is a query string param name
	ParamLimit = "limit"
	// LastLedgerHeaderName is the header which is set on all endpoints
	LastLedgerHeaderName = "Latest-Ledger"
)

TODO: move these constants to urlparam.go as we should parse the params with http handlers in the upper level package.

Variables

View Source
var DestinationAssetsOrDestinationAccountProblem = problem.P{
	Type:   "bad_request",
	Title:  "Bad Request",
	Status: http.StatusBadRequest,
	Detail: "The request requires either a list of destination assets or a destination account. " +
		"Both fields cannot be present.",
}

DestinationAssetsOrDestinationAccountProblem custom error where destination asserts or accounts are required

View Source
var SourceAssetsOrSourceAccountProblem = problem.P{
	Type:   "bad_request",
	Title:  "Bad Request",
	Status: http.StatusBadRequest,
	Detail: "The request requires either a list of source assets or a source account. " +
		"Both fields cannot be present.",
}

SourceAssetsOrSourceAccountProblem custom error where source assets or account is required

Functions

func AccountInfo

func AccountInfo(ctx context.Context, hq *history.Q, addr string) (*protocol.Account, error)

AccountInfo returns the information about an account identified by addr.

func FullURL

func FullURL(ctx context.Context) *url.URL

FullURL returns a URL containing the information regarding the original request stored in the context.

func GetPageQuery

func GetPageQuery(ledgerState *ledger.State, r *http.Request, opts ...Opt) (db2.PageQuery, error)

GetPageQuery is a helper that returns a new db.PageQuery struct initialized using the results from a call to GetPagingParams()

func GetTransactionID

func GetTransactionID(r *http.Request, name string) (string, error)

GetTransactionID retireves a transaction identifier by attempting to decode an hex-encoded, 64-digit lowercase string at the provided name.

func SetLastLedgerHeader

func SetLastLedgerHeader(w HeaderWriter, lastLedger uint32)

SetLastLedgerHeader sets the Latest-Ledger header

Types

type Account

type Account protocol.Account

func (Account) Equals

func (a Account) Equals(other StreamableObjectResponse) bool

type AccountByIDQuery

type AccountByIDQuery struct {
	AccountID string `schema:"account_id" valid:"accountID,optional"`
}

AccountByIDQuery query struct for accounts/{account_id} end-point

type AccountDataQuery

type AccountDataQuery struct {
	AccountID string `schema:"account_id" valid:"accountID"`
	Key       string `schema:"key" valid:"length(1|64)"`
}

AccountDataQuery query struct for account data end-point

type AccountOffersQuery

type AccountOffersQuery struct {
	AccountID string `schema:"account_id" valid:"accountID,required"`
}

AccountOffersQuery query struct for offers end-point

type AccountsQuery

type AccountsQuery struct {
	Signer      string `schema:"signer" valid:"accountID,optional"`
	Sponsor     string `schema:"sponsor" valid:"accountID,optional"`
	AssetFilter string `schema:"asset" valid:"asset,optional"`
}

AccountsQuery query struct for accounts end-point

func (AccountsQuery) Asset

func (q AccountsQuery) Asset() *xdr.Asset

Asset returns an xdr.Asset representing the Asset we want to find the trustees by.

func (AccountsQuery) URITemplate

func (q AccountsQuery) URITemplate() string

URITemplate returns a rfc6570 URI template the query struct

func (AccountsQuery) Validate

func (q AccountsQuery) Validate() error

Validate runs custom validations.

type AssetStatsHandler

type AssetStatsHandler struct {
	LedgerState *ledger.State
}

AssetStatsHandler is the action handler for the /asset endpoint

func (AssetStatsHandler) GetResourcePage

func (handler AssetStatsHandler) GetResourcePage(
	w HeaderWriter,
	r *http.Request,
) ([]hal.Pageable, error)

GetResourcePage returns a page of offers.

type ClaimableBalanceQuery

type ClaimableBalanceQuery struct {
	ID string `schema:"id" valid:"-"`
}

ClaimableBalanceQuery query struct for claimables_balances/id end-point

func (ClaimableBalanceQuery) Validate

func (q ClaimableBalanceQuery) Validate() error

Validate validates the balance id

type ClaimableBalancesQuery

type ClaimableBalancesQuery struct {
	AssetFilter    string `schema:"asset" valid:"asset,optional"`
	SponsorFilter  string `schema:"sponsor" valid:"accountID,optional"`
	ClaimantFilter string `schema:"claimant" valid:"accountID,optional"`
}

ClaimableBalancesQuery query struct for claimable_balances end-point

func (ClaimableBalancesQuery) URITemplate

func (q ClaimableBalancesQuery) URITemplate() string

URITemplate returns a rfc6570 URI template the query struct

type CoreStateGetter

type CoreStateGetter interface {
	GetCoreState() corestate.State
}

type EffectsQuery

type EffectsQuery struct {
	AccountID   string `schema:"account_id" valid:"accountID,optional"`
	OperationID uint64 `schema:"op_id" valid:"-"`
	TxHash      string `schema:"tx_id" valid:"transactionHash,optional"`
	LedgerID    uint32 `schema:"ledger_id" valid:"-"`
}

EffectsQuery query struct for effects end-points

func (EffectsQuery) Validate

func (qp EffectsQuery) Validate() error

Validate runs extra validations on query parameters

type FeeStatsHandler

type FeeStatsHandler struct {
}

FeeStatsHandler is the action handler for the /fee_stats endpoint

func (FeeStatsHandler) GetResource

func (handler FeeStatsHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource fee stats resource

type FindFixedPathsHandler

type FindFixedPathsHandler struct {
	MaxPathLength        uint
	MaxAssetsParamLength int
	SetLastLedgerHeader  bool
	PathFinder           paths.Finder
}

FindFixedPathsHandler is the http handler for the find fixed payment paths endpoint Fixed payment paths are payment paths where both the source and destination asset are fixed

func (FindFixedPathsHandler) GetResource

func (handler FindFixedPathsHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource returns a list of strict send paths

type FindFixedPathsQuery

type FindFixedPathsQuery struct {
	DestinationAccount string `schema:"destination_account" valid:"accountID,optional"`
	DestinationAssets  string `schema:"destination_assets" valid:"-"`
	SourceAssetType    string `schema:"source_asset_type" valid:"assetType"`
	SourceAssetIssuer  string `schema:"source_asset_issuer" valid:"accountID,optional"`
	SourceAssetCode    string `schema:"source_asset_code" valid:"-"`
	SourceAmount       string `schema:"source_amount" valid:"amount"`
}

FindFixedPathsQuery query struct for paths/strict-send end-point

func (FindFixedPathsQuery) Amount

func (q FindFixedPathsQuery) Amount() xdr.Int64

Amount returns source amount

func (FindFixedPathsQuery) Assets

func (q FindFixedPathsQuery) Assets() ([]xdr.Asset, error)

Assets returns a list of xdr.Asset

func (FindFixedPathsQuery) SourceAsset

func (q FindFixedPathsQuery) SourceAsset() xdr.Asset

SourceAsset returns an xdr.Asset

func (FindFixedPathsQuery) URITemplate

func (q FindFixedPathsQuery) URITemplate() string

URITemplate returns a rfc6570 URI template for the query struct

func (FindFixedPathsQuery) Validate

func (q FindFixedPathsQuery) Validate() error

Validate runs custom validations.

type FindPathsHandler

type FindPathsHandler struct {
	StaleThreshold       uint
	MaxPathLength        uint
	SetLastLedgerHeader  bool
	MaxAssetsParamLength int
	PathFinder           paths.Finder
}

FindPathsHandler is the http handler for the find payment paths endpoint

func (FindPathsHandler) GetResource

func (handler FindPathsHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource finds a list of strict receive paths

type GetAccountByIDHandler

type GetAccountByIDHandler struct{}

GetAccountByIDHandler is the action handler for the /accounts/{account_id} endpoint

func (GetAccountByIDHandler) GetResource

type GetAccountDataHandler

type GetAccountDataHandler struct{}

func (GetAccountDataHandler) GetResource

func (GetAccountDataHandler) WriteRawResponse

func (handler GetAccountDataHandler) WriteRawResponse(w io.Writer, r *http.Request) error

type GetAccountOffersHandler

type GetAccountOffersHandler struct {
	LedgerState *ledger.State
}

GetAccountOffersHandler is the action handler for the `/accounts/{account_id}/offers` endpoint when using experimental ingestion.

func (GetAccountOffersHandler) GetResourcePage

func (handler GetAccountOffersHandler) GetResourcePage(
	w HeaderWriter,
	r *http.Request,
) ([]hal.Pageable, error)

GetResourcePage returns a page of offers for a given account.

type GetAccountsHandler

type GetAccountsHandler struct {
	LedgerState *ledger.State
}

GetAccountsHandler is the action handler for the /accounts endpoint

func (GetAccountsHandler) GetResourcePage

func (handler GetAccountsHandler) GetResourcePage(
	w HeaderWriter,
	r *http.Request,
) ([]hal.Pageable, error)

GetResourcePage returns a page containing the account records that have `signer` as a signer or have a trustline to the given asset.

type GetClaimableBalanceByIDHandler

type GetClaimableBalanceByIDHandler struct{}

GetClaimableBalanceByIDHandler is the action handler for all end-points returning a claimable balance.

func (GetClaimableBalanceByIDHandler) GetResource

func (handler GetClaimableBalanceByIDHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource returns an claimable balance page.

type GetClaimableBalancesHandler

type GetClaimableBalancesHandler struct {
	LedgerState *ledger.State
}

func (GetClaimableBalancesHandler) GetResourcePage

func (handler GetClaimableBalancesHandler) GetResourcePage(
	w HeaderWriter,
	r *http.Request,
) ([]hal.Pageable, error)

GetResourcePage returns a page of claimable balances.

type GetEffectsHandler

type GetEffectsHandler struct {
	LedgerState *ledger.State
}

func (GetEffectsHandler) GetResourcePage

func (handler GetEffectsHandler) GetResourcePage(w HeaderWriter, r *http.Request) ([]hal.Pageable, error)

type GetLedgerByIDHandler

type GetLedgerByIDHandler struct {
	LedgerState *ledger.State
}

func (GetLedgerByIDHandler) GetResource

func (handler GetLedgerByIDHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

type GetLedgersHandler

type GetLedgersHandler struct {
	LedgerState *ledger.State
}

func (GetLedgersHandler) GetResourcePage

func (handler GetLedgersHandler) GetResourcePage(w HeaderWriter, r *http.Request) ([]hal.Pageable, error)

type GetOfferByID

type GetOfferByID struct{}

GetOfferByID is the action handler for the /offers/{id} endpoint

func (GetOfferByID) GetResource

func (handler GetOfferByID) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource returns an offer by id.

type GetOffersHandler

type GetOffersHandler struct {
	LedgerState *ledger.State
}

GetOffersHandler is the action handler for the /offers endpoint

func (GetOffersHandler) GetResourcePage

func (handler GetOffersHandler) GetResourcePage(
	w HeaderWriter,
	r *http.Request,
) ([]hal.Pageable, error)

GetResourcePage returns a page of offers.

type GetOperationByIDHandler

type GetOperationByIDHandler struct {
	LedgerState *ledger.State
}

GetOperationByIDHandler is the action handler for all end-points returning a list of operations.

func (GetOperationByIDHandler) GetResource

func (handler GetOperationByIDHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource returns an operation page.

type GetOperationsHandler

type GetOperationsHandler struct {
	LedgerState  *ledger.State
	OnlyPayments bool
}

GetOperationsHandler is the action handler for all end-points returning a list of operations.

func (GetOperationsHandler) GetResourcePage

func (handler GetOperationsHandler) GetResourcePage(w HeaderWriter, r *http.Request) ([]hal.Pageable, error)

GetResourcePage returns a page of operations.

type GetOrderbookHandler

type GetOrderbookHandler struct {
}

GetOrderbookHandler is the action handler for the /order_book endpoint

func (GetOrderbookHandler) GetResource

GetResource implements the /order_book endpoint

type GetRootHandler

type GetRootHandler struct {
	LedgerState *ledger.State
	CoreStateGetter
	NetworkPassphrase string
	FriendbotURL      *url.URL
	HorizonVersion    string
}

func (GetRootHandler) GetResource

func (handler GetRootHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

type GetTradeAggregationsHandler

type GetTradeAggregationsHandler struct {
	LedgerState *ledger.State
}

GetTradeAggregationsHandler is the action handler for trade_aggregations

func (GetTradeAggregationsHandler) GetResource

func (handler GetTradeAggregationsHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResourcePage returns a page of trade aggregations

type GetTradesHandler

type GetTradesHandler struct {
	LedgerState *ledger.State
}

GetTradesHandler is the action handler for all end-points returning a list of trades.

func (GetTradesHandler) GetResourcePage

func (handler GetTradesHandler) GetResourcePage(w HeaderWriter, r *http.Request) ([]hal.Pageable, error)

GetResourcePage returns a page of trades.

type GetTransactionByHashHandler

type GetTransactionByHashHandler struct {
}

GetTransactionByHashHandler is the action handler for the end-point returning a transaction.

func (GetTransactionByHashHandler) GetResource

func (handler GetTransactionByHashHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

GetResource returns a transaction page.

type GetTransactionsHandler

type GetTransactionsHandler struct {
	LedgerState *ledger.State
}

GetTransactionsHandler is the action handler for all end-points returning a list of transactions.

func (GetTransactionsHandler) GetResourcePage

func (handler GetTransactionsHandler) GetResourcePage(w HeaderWriter, r *http.Request) ([]hal.Pageable, error)

GetResourcePage returns a page of transactions.

type HeaderWriter

type HeaderWriter interface {
	Header() http.Header
}

HeaderWriter is an interface for setting HTTP response headers

type Joinable

type Joinable struct {
	Join string `schema:"join" valid:"in(transactions)~Accepted values: transactions,optional"`
}

Joinable query struct for join query parameter

func (Joinable) IncludeTransactions

func (qp Joinable) IncludeTransactions() bool

IncludeTransactions returns extra fields to include in the response

type LedgerByIDQuery

type LedgerByIDQuery struct {
	LedgerID uint32 `schema:"ledger_id" valid:"-"`
}

LedgerByIDQuery query struct for the ledger/{id} endpoint

type OfferByIDQuery

type OfferByIDQuery struct {
	OfferID uint64 `schema:"offer_id" valid:"-"`
}

AccountOffersQuery query struct for offers end-point

type OffersQuery

type OffersQuery struct {
	SellingBuyingAssetQueryParams `valid:"-"`
	Seller                        string `schema:"seller" valid:"accountID,optional"`
	Sponsor                       string `schema:"sponsor" valid:"accountID,optional"`
}

OffersQuery query struct for offers end-point

func (OffersQuery) URITemplate

func (q OffersQuery) URITemplate() string

URITemplate returns a rfc6570 URI template the query struct

func (OffersQuery) Validate

func (q OffersQuery) Validate() error

Validate runs custom validations.

type OperationQuery

type OperationQuery struct {
	LedgerState *ledger.State `valid:"-"`
	Joinable    `valid:"optional"`
	ID          uint64 `schema:"id" valid:"-"`
}

OperationQuery query struct for operation/id end-point

func (OperationQuery) Validate

func (qp OperationQuery) Validate() error

Validate runs extra validations on query parameters

type OperationsQuery

type OperationsQuery struct {
	Joinable                  `valid:"optional"`
	AccountID                 string `schema:"account_id" valid:"accountID,optional"`
	ClaimableBalanceID        string `schema:"claimable_balance_id" valid:"claimableBalanceID,optional"`
	TransactionHash           string `schema:"tx_id" valid:"transactionHash,optional"`
	IncludeFailedTransactions bool   `schema:"include_failed" valid:"-"`
	LedgerID                  uint32 `schema:"ledger_id" valid:"-"`
}

OperationsQuery query struct for operations end-points

func (OperationsQuery) Validate

func (qp OperationsQuery) Validate() error

Validate runs extra validations on query parameters

type Opt

type Opt int
const (
	// DisableCursorValidation disables cursor validation in GetPageQuery
	DisableCursorValidation Opt = iota
)

type OrderBookResponse

type OrderBookResponse struct {
	protocol.OrderBookSummary
}

OrderBookResponse is the response for the /order_book endpoint OrderBookResponse implements StreamableObjectResponse

func (OrderBookResponse) Equals

Equals returns true if the OrderBookResponse is equal to `other`

type SellingBuyingAssetQueryParams

type SellingBuyingAssetQueryParams struct {
	SellingAssetType   string `schema:"selling_asset_type" valid:"assetType,optional"`
	SellingAssetIssuer string `schema:"selling_asset_issuer" valid:"accountID,optional"`
	SellingAssetCode   string `schema:"selling_asset_code" valid:"-"`
	BuyingAssetType    string `schema:"buying_asset_type" valid:"assetType,optional"`
	BuyingAssetIssuer  string `schema:"buying_asset_issuer" valid:"accountID,optional"`
	BuyingAssetCode    string `schema:"buying_asset_code" valid:"-"`

	// allow selling and buying using an asset's canonical representation. We
	// are keeping the former selling_* and buying_* for backwards compatibility
	// but it should not be documented.
	SellingAsset string `schema:"selling" valid:"asset,optional"`
	BuyingAsset  string `schema:"buying" valid:"asset,optional"`
}

SellingBuyingAssetQueryParams query struct for end-points requiring a selling and buying asset

func (SellingBuyingAssetQueryParams) Buying

Buying returns an *xdr.Asset representing the buying side of the offer.

func (SellingBuyingAssetQueryParams) Selling

func (q SellingBuyingAssetQueryParams) Selling() (*xdr.Asset, error)

Selling returns an xdr.Asset representing the selling side of the offer.

func (SellingBuyingAssetQueryParams) Validate

func (q SellingBuyingAssetQueryParams) Validate() error

Validate runs custom validations buying and selling

type StreamableObjectResponse

type StreamableObjectResponse interface {
	Equals(other StreamableObjectResponse) bool
}

StreamableObjectResponse is an interface for objects returned by streamable object endpoints A streamable object endpoint is an SSE endpoint which returns a single JSON object response instead of a page of items.

type StrictReceivePathsQuery

type StrictReceivePathsQuery struct {
	SourceAssets           string `schema:"source_assets" valid:"-"`
	SourceAccount          string `schema:"source_account" valid:"accountID,optional"`
	DestinationAccount     string `schema:"destination_account" valid:"accountID,optional"`
	DestinationAssetType   string `schema:"destination_asset_type" valid:"assetType"`
	DestinationAssetIssuer string `schema:"destination_asset_issuer" valid:"accountID,optional"`
	DestinationAssetCode   string `schema:"destination_asset_code" valid:"-"`
	DestinationAmount      string `schema:"destination_amount" valid:"amount"`
}

StrictReceivePathsQuery query struct for paths/strict-send end-point

func (StrictReceivePathsQuery) Amount

func (q StrictReceivePathsQuery) Amount() xdr.Int64

Amount returns source amount

func (StrictReceivePathsQuery) Assets

func (q StrictReceivePathsQuery) Assets() ([]xdr.Asset, error)

Assets returns a list of xdr.Asset

func (StrictReceivePathsQuery) DestinationAsset

func (q StrictReceivePathsQuery) DestinationAsset() xdr.Asset

DestinationAsset returns an xdr.Asset

func (StrictReceivePathsQuery) URITemplate

func (q StrictReceivePathsQuery) URITemplate() string

URITemplate returns a rfc6570 URI template for the query struct

func (StrictReceivePathsQuery) Validate

func (q StrictReceivePathsQuery) Validate() error

Validate runs custom validations.

type SubmitTransactionHandler

type SubmitTransactionHandler struct {
	Submitter         *txsub.System
	NetworkPassphrase string
	CoreStateGetter
}

func (SubmitTransactionHandler) GetResource

func (handler SubmitTransactionHandler) GetResource(w HeaderWriter, r *http.Request) (interface{}, error)

type TradeAggregationsQuery

type TradeAggregationsQuery struct {
	OffsetFilter           uint64      `schema:"offset" valid:"-"`
	StartTimeFilter        time.Millis `schema:"start_time" valid:"-"`
	EndTimeFilter          time.Millis `schema:"end_time" valid:"-"`
	ResolutionFilter       uint64      `schema:"resolution" valid:"-"`
	TradeAssetsQueryParams `valid:"optional"`
}

TradeAggregationsQuery query struct for trade_aggregations end-point

func (TradeAggregationsQuery) Validate

func (q TradeAggregationsQuery) Validate() error

Validate runs validations on tradeAggregationsQuery

type TradeAssetsQueryParams

type TradeAssetsQueryParams struct {
	BaseAssetType      string `schema:"base_asset_type" valid:"assetType,optional"`
	BaseAssetIssuer    string `schema:"base_asset_issuer" valid:"accountID,optional"`
	BaseAssetCode      string `schema:"base_asset_code" valid:"-"`
	CounterAssetType   string `schema:"counter_asset_type" valid:"assetType,optional"`
	CounterAssetIssuer string `schema:"counter_asset_issuer" valid:"accountID,optional"`
	CounterAssetCode   string `schema:"counter_asset_code" valid:"-"`
}

TradeAssetsQueryParams represents the base and counter assets on trade related end-points.

func (TradeAssetsQueryParams) Base

func (q TradeAssetsQueryParams) Base() (*xdr.Asset, error)

Base returns an xdr.Asset representing the base side of the trade.

func (TradeAssetsQueryParams) Counter

func (q TradeAssetsQueryParams) Counter() (*xdr.Asset, error)

Counter returns an *xdr.Asset representing the counter asset side of the trade.

type TradesQuery

type TradesQuery struct {
	AccountID              string `schema:"account_id" valid:"accountID,optional"`
	OfferID                uint64 `schema:"offer_id" valid:"-"`
	TradeAssetsQueryParams `valid:"optional"`
}

TradesQuery query struct for trades end-points

func (TradesQuery) Validate

func (q TradesQuery) Validate() error

Validate runs custom validations base and counter

type TransactionQuery

type TransactionQuery struct {
	TransactionHash string `schema:"tx_id" valid:"transactionHash,optional"`
}

TransactionQuery query struct for transactions/id end-point

type TransactionsQuery

type TransactionsQuery struct {
	AccountID                 string `schema:"account_id" valid:"accountID,optional"`
	ClaimableBalanceID        string `schema:"claimable_balance_id" valid:"claimableBalanceID,optional"`
	IncludeFailedTransactions bool   `schema:"include_failed" valid:"-"`
	LedgerID                  uint32 `schema:"ledger_id" valid:"-"`
}

TransactionsQuery query struct for transactions end-points

func (TransactionsQuery) Validate

func (qp TransactionsQuery) Validate() error

Validate runs extra validations on query parameters

type Validateable

type Validateable interface {
	Validate() error
}

Validateable allow structs to define their own custom validations.

Jump to

Keyboard shortcuts

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