handler.go


Overview

The [handler.go](/projects/291/69233) file defines the `Handler` struct and related methods for interacting with the Cosmos-based Thorchain blockchain within the API layer of the application. This file acts as a bridge between the underlying Cosmos SDK handler logic and Thorchain-specific transaction parsing and fee calculation. It exposes functionality to:

This modular handler extends the generic Cosmos handler, specializing it with Thorchain-specific logic and integrations, enabling the API to serve Thorchain blockchain data and operations efficiently.


Detailed Documentation

Type: Handler

type Handler struct {
	*cosmos.Handler
}

Method: StartWebsocket() error

func (h *Handler) StartWebsocket() error

Type: Info

type Info struct {
	// swagger:allOf
	cosmos.Info
}

Method: GetInfo() (api.Info, error)

func (h *Handler) GetInfo() (api.Info, error)

Method: GetTxHistory(pubkey string, cursor string, pageSize int) (api.TxHistory, error)

func (h *Handler) GetTxHistory(pubkey string, cursor string, pageSize int) (api.TxHistory, error)

Method: ParseMessages(msgs []sdk.Msg, events cosmos.EventsByMsgIndex) []cosmos.Message

func (h *Handler) ParseMessages(msgs []sdk.Msg, events cosmos.EventsByMsgIndex) []cosmos.Message

Method: ParseFee(tx cosmos.SigningTx, txid string) cosmos.Value

func (h *Handler) ParseFee(tx cosmos.SigningTx, txid string) cosmos.Value

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class Handler {
        +StartWebsocket() error
        +GetInfo() (api.Info, error)
        +GetTxHistory(pubkey string, cursor string, pageSize int) (api.TxHistory, error)
        +ParseMessages(msgs []sdk.Msg, events cosmos.EventsByMsgIndex) []cosmos.Message
        +ParseFee(tx cosmos.SigningTx, txid string) cosmos.Value
    }

    class cosmos.Handler {
        +WSClient
        +GetInfo() (cosmos.Info, error)
        +StartWebsocket() error
    }

    class thorchain {
        +GetTxHistory(h cosmos.Handler, pubkey string, cursor string, pageSize int) (api.TxHistory, error)
        +ParseMessages(msgs []sdk.Msg, events cosmos.EventsByMsgIndex) []cosmos.Message
        +ParseFee(tx cosmos.SigningTx, txid string, denom string, nativeFee bool) cosmos.Value
    }

    Handler --> cosmos.Handler : embeds
    Handler ..> thorchain : delegates calls
    Handler --> "WSClient" : uses to start websocket

Summary

The [handler.go](/projects/291/69233) file encapsulates Thorchain-specific blockchain handler logic by extending a generic Cosmos SDK handler. It provides API-ready methods for starting websocket connections, fetching chain info, retrieving transaction histories, parsing messages, and computing fees. By delegating protocol-specific parsing and history retrieval to the Thorchain package and embedding a robust Cosmos handler, this file ensures modularity, maintainability, and clear separation of concerns within the blockchain API service.