api

package
v1.1.19-beta Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BadRequestErrorHandler = func(c *gin.Context, err error) {
		writeError(c.Writer, err.Error(), http.StatusBadRequest)
	}
	InternalErrorHandler = func(c *gin.Context) {
		writeError(c.Writer, "An unexpected error occurred.", http.StatusInternalServerError)
	}
	UnauthorizedErrorHandler = func(c *gin.Context, err error) {
		writeError(c.Writer, err.Error(), http.StatusUnauthorized)
	}
)
View Source
var EntityColumns = map[string][]string{
	"blocks": {
		"chain_id", "block_number", "block_timestamp", "hash", "parent_hash", "sha3_uncles",
		"nonce", "mix_hash", "miner", "state_root", "transactions_root", "receipts_root",
		"logs_bloom", "size", "extra_data", "difficulty", "total_difficulty", "transaction_count",
		"gas_limit", "gas_used", "withdrawals_root", "base_fee_per_gas", "insert_timestamp", "sign",
	},
	"transactions": {
		"chain_id", "hash", "nonce", "block_hash", "block_number", "block_timestamp",
		"transaction_index", "from_address", "to_address", "value", "gas", "gas_price",
		"data", "function_selector", "max_fee_per_gas", "max_priority_fee_per_gas",
		"max_fee_per_blob_gas", "blob_versioned_hashes", "transaction_type", "r", "s", "v",
		"access_list", "authorization_list", "contract_address", "gas_used", "cumulative_gas_used",
		"effective_gas_price", "blob_gas_used", "blob_gas_price", "logs_bloom", "status",
		"insert_timestamp", "sign",
	},
	"logs": {
		"chain_id", "block_number", "block_hash", "block_timestamp", "transaction_hash",
		"transaction_index", "log_index", "address", "data", "topic_0", "topic_1", "topic_2", "topic_3",
		"insert_timestamp", "sign",
	},
	"transfers": {
		"token_type", "chain_id", "token_address", "from_address", "to_address", "block_number",
		"block_timestamp", "transaction_hash", "token_id", "amount", "log_index", "insert_timestamp", "sign",
	},
	"balances": {
		"token_type", "chain_id", "owner", "address", "token_id", "balance",
	},
	"traces": {
		"chain_id", "block_number", "block_hash", "block_timestamp", "transaction_hash",
		"transaction_index", "subtraces", "trace_address", "type", "call_type", "error",
		"from_address", "to_address", "gas", "gas_used", "input", "output", "value",
		"author", "reward_type", "refund_address", "insert_timestamp", "sign",
	},
}

EntityColumns defines the valid columns for each entity type

Functions

func GetChainId

func GetChainId(c *gin.Context) (*big.Int, error)

func ParseIntQueryParam

func ParseIntQueryParam(value string, defaultValue int) int

func ValidateGroupByAndSortBy

func ValidateGroupByAndSortBy(entity string, groupBy []string, sortBy string, aggregates []string) error

ValidateGroupByAndSortBy validates that GroupBy and SortBy fields are valid for the given entity It checks that fields are either: 1. Valid entity columns 2. Valid aggregate function aliases (e.g., "count", "total_amount")

Types

type Error

type Error struct {
	// @Description HTTP status code
	Code int `json:"code"`
	// @Description Error message
	Message string `json:"message"`
	// @Description Support ID for tracking the error
	SupportId string `json:"support_id"`
}

Error represents an API error response @Description Error represents an API error response

type Meta

type Meta struct {
	// @Description Chain ID of the blockchain
	ChainId uint64 `json:"chain_id"`
	// @Description Contract address
	ContractAddress string `json:"address,omitempty"`
	// @Description Function or event signature
	Signature string `json:"signature,omitempty"`
	// @Description Current page number
	Page int `json:"page"`
	// @Description Number of items per page
	Limit int `json:"limit,omitempty"`
	// @Description Total number of items
	TotalItems int `json:"total_items,omitempty"`
	// @Description Total number of pages
	TotalPages int `json:"total_pages,omitempty"`
}

Meta represents metadata for a query response @Description Meta represents metadata for a query response

type QueryParams

type QueryParams struct {
	// @Description Map of filter parameters
	FilterParams map[string]string `schema:"-"`
	// @Description Field to group results by
	GroupBy []string `schema:"group_by"`
	// @Description Field to sort results by
	SortBy string `schema:"sort_by"`
	// @Description Sort order (asc or desc)
	SortOrder string `schema:"sort_order"`
	// @Description Page number for pagination
	Page int `schema:"page"`
	// @Description Number of items per page
	Limit int `schema:"limit"`
	// @Description List of aggregate functions to apply
	Aggregates []string `schema:"aggregate"`

	// @Description Flag to enable abi decoding of tx data
	Decode bool `schema:"decode"`
	// @Description Flag to force consistent data at the expense of query speed
	ForceConsistentData bool `schema:"force_consistent_data"`
}

QueryParams represents the parameters for querying data @Description QueryParams represents the parameters for querying data

func ParseQueryParams

func ParseQueryParams(r *http.Request) (QueryParams, error)

type QueryResponse

type QueryResponse struct {
	// @Description Metadata for the query response
	Meta Meta `json:"meta"`
	// @Description Query result data
	Data *interface{} `json:"data,omitempty"`
	// @Description Aggregation results
	Aggregations *[]map[string]interface{} `json:"aggregations,omitempty"`
}

QueryResponse represents the response structure for a query @Description QueryResponse represents the response structure for a query

Jump to

Keyboard shortcuts

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