Documentation ¶
Overview ¶
Package insight implements the Insight API.
Index ¶
- Constants
- func AddressCommandCtx(next http.Handler) http.Handler
- func BlockDateLimitQueryCtx(next http.Handler) http.Handler
- func DisableLog()
- func FromToPaginationCtx(next http.Handler) http.Handler
- func GetAddressCommandCtx(r *http.Request) (string, bool)
- func GetFromCtx(r *http.Request) int64
- func GetLimitCtx(r *http.Request) int
- func GetNbBlocksCtx(r *http.Request) int
- func GetNoAsmCtx(r *http.Request) bool
- func GetNoScriptSigCtx(r *http.Request) bool
- func GetNoSpentCtx(r *http.Request) bool
- func GetNoTxListCtx(r *http.Request) int
- func GetToCtx(r *http.Request) (int64, bool)
- func NbBlocksCtx(next http.Handler) http.Handler
- func NoTxListCtx(next http.Handler) http.Handler
- func PostAddrsTxsCtx(next http.Handler) http.Handler
- func PostAddrsUtxoCtx(next http.Handler) http.Handler
- func UseLogger(logger slog.Logger)
- type ApiMux
- type InsightApi
- func (iapi *InsightApi) BlockHashPathAndIndexCtx(next http.Handler) http.Handler
- func (iapi *InsightApi) DcrToInsightBlock(inBlocks []*chainjson.GetBlockVerboseResult) ([]*apitypes.InsightBlockResult, error)
- func (iapi *InsightApi) DcrToInsightTxns(txs []*chainjson.TxRawResult, noAsm, noScriptSig, noSpent bool) ([]apitypes.InsightTx, error)
- func (iapi *InsightApi) GetPeerStatus(w http.ResponseWriter, r *http.Request)
- func (iapi *InsightApi) SetReqRateLimit(reqPerSecLimit float64)
- func (iapi *InsightApi) StatusInfoCtx(next http.Handler) http.Handler
- func (iapi *InsightApi) TxConverter(txs []*chainjson.TxRawResult) ([]apitypes.InsightTx, error)
- func (iapi *InsightApi) ValidatePostCtx(next http.Handler) http.Handler
- type InsightSocketVin
- type InsightSocketVout
- type SocketServer
- type WebSocketTx
Constants ¶
const APIVersion = 0
APIVersion is an integer value, incremented for breaking changes
Variables ¶
This section is empty.
Functions ¶
func AddressCommandCtx ¶
AddressCommandCtx returns a http.HandlerFunc that embeds the value at the url part {command} into the request context.
func BlockDateLimitQueryCtx ¶
BlockDateLimitQueryCtx returns a http.Handlerfunc that embeds the {blockdate,limit} value in the request into the request context.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func FromToPaginationCtx ¶
FromToPaginationCtx will parse the query parameters for from/to values.
func GetAddressCommandCtx ¶
GetAddressCommandCtx retrieves the ctxAddrCmd data from the request context. If not set the return value is "" and false.
func GetFromCtx ¶
GetFromCtx retrieves the ctxFrom data ("from") from the request context. If not set, the return value is 0
func GetLimitCtx ¶
GetLimitCtx retrieves the ctxLimit data from the request context. If not set, the return value is 0 which is interpreted as no limit.
func GetNbBlocksCtx ¶
GetNbBlocksCtx retrieves the ctxNbBlocks data from the request context. If not set, the return value is 0.
func GetNoAsmCtx ¶
GetNoAsmCtx retrieves the ctxNoAsm data ("noAsm") from the request context. If not set, the return value is false.
func GetNoScriptSigCtx ¶
GetNoScriptSigCtx retrieves the ctxNoScriptSig data ("noScriptSig") from the request context. If not set, the return value is false.
func GetNoSpentCtx ¶
GetNoSpentCtx retrieves the ctxNoSpent data ("noSpent") from the request context. If not set, the return value is false.
func GetNoTxListCtx ¶
GetNoTxListCtx retrieves the ctxNoTxList data ("noTxList") from the request context. If not set, the return value is false.
func GetToCtx ¶
GetToCtx retrieves the ctxTo data ("to") from the request context. If not set, the return value ok is false.
func NbBlocksCtx ¶
NbBlocksCtx will parse the query parameters for nbBlocks.
func NoTxListCtx ¶
NoTxListCtx returns a http.Handlerfunc that embeds the {noTxList} value in the request into the request context.
func PostAddrsTxsCtx ¶
PostAddrsTxsCtx middleware processes parameters given in the POST request body for an addrs endpoint. While the addresses list, "addrs", must be in the POST body JSON, the other parameters may be specified as URL queries. POST body values take priority.
func PostAddrsUtxoCtx ¶
PostAddrsUtxoCtx middleware processes parameters given in the POST request body for an addrs utxo endpoint.
Types ¶
type ApiMux ¶
ApiMux contains the struct mux
func NewInsightApiRouter ¶
func NewInsightApiRouter(app *InsightApi, useRealIP, compression bool) ApiMux
NewInsightApiRouter returns a new HTTP path router, ApiMux, for the Insight API, app.
type InsightApi ¶
type InsightApi struct { BlockData *dcrpg.ChainDBRPC JSONIndent string ReqPerSecLimit float64 // contains filtered or unexported fields }
InsightApi contains the resources for the Insight HTTP API. InsightApi's methods include the http.Handlers for the URL path routes.
func NewInsightApi ¶
func NewInsightApi(client *rpcclient.Client, blockData *dcrpg.ChainDBRPC, params *chaincfg.Params, memPoolData rpcutils.MempoolAddressChecker, JSONIndent string, maxAddrs int, status *apitypes.Status) *InsightApi
NewInsightApi is the constructor for InsightApi.
func (*InsightApi) BlockHashPathAndIndexCtx ¶
func (iapi *InsightApi) BlockHashPathAndIndexCtx(next http.Handler) http.Handler
BlockHashPathAndIndexCtx is a middleware that embeds the value at the url part {blockhash}, and the corresponding block index, into a request context.
func (*InsightApi) DcrToInsightBlock ¶
func (iapi *InsightApi) DcrToInsightBlock(inBlocks []*chainjson.GetBlockVerboseResult) ([]*apitypes.InsightBlockResult, error)
DcrToInsightBlock converts a chainjson.GetBlockVerboseResult to Insight block.
func (*InsightApi) DcrToInsightTxns ¶
func (iapi *InsightApi) DcrToInsightTxns(txs []*chainjson.TxRawResult, noAsm, noScriptSig, noSpent bool) ([]apitypes.InsightTx, error)
DcrToInsightTxns converts a chainjson TxRawResult to a InsightTx. The asm, scriptSig, and spending status may be skipped by setting the appropriate input arguments.
func (*InsightApi) GetPeerStatus ¶
func (iapi *InsightApi) GetPeerStatus(w http.ResponseWriter, r *http.Request)
GetPeerStatus handles requests for node peer info (i.e. getpeerinfo RPC).
func (*InsightApi) SetReqRateLimit ¶
func (iapi *InsightApi) SetReqRateLimit(reqPerSecLimit float64)
SetReqRateLimit is used to set the requests/second/IP for the Insight API's rate limiter.
func (*InsightApi) StatusInfoCtx ¶
func (iapi *InsightApi) StatusInfoCtx(next http.Handler) http.Handler
StatusInfoCtx is a middleware that embeds into the request context the data for the "?q=x" URL query, where x is "getInfo" or "getDifficulty" or "getBestBlockHash" or "getLastBlockHash".
func (*InsightApi) TxConverter ¶
func (iapi *InsightApi) TxConverter(txs []*chainjson.TxRawResult) ([]apitypes.InsightTx, error)
TxConverter converts dcrd-tx to insight tx
func (*InsightApi) ValidatePostCtx ¶
func (iapi *InsightApi) ValidatePostCtx(next http.Handler) http.Handler
ValidatePostCtx will confirm Post content length is valid.
type InsightSocketVin ¶
type InsightSocketVin struct { TxID string `json:"txid,omitempty"` Vout *uint32 `json:"vout,omitempty"` Addresses []string `json:"addresses,omitempty"` Value *int64 `json:"value,omitempty"` }
InsightSocketVin represents a single vin for the Insight "vin" JSON object that appears in a "tx" message from the "inv" room.
type InsightSocketVout ¶
InsightSocketVout represents a single vout for the Insight "vout" JSON object that appears in a "tx" message from the "inv" room.
func (*InsightSocketVout) MarshalJSON ¶
func (v *InsightSocketVout) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler so that an InsightSocketVout will marshal to JSON like:
{ "DsZQaCQES5vh3JmcyyFokJYz3aSw8Sm1dsQ": 13741789 }
type SocketServer ¶
SocketServer wraps the socket.io server with the watched address list.
func NewSocketServer ¶
func NewSocketServer(params *chaincfg.Params, txGetter txhelpers.RawTransactionGetter) (*SocketServer, error)
NewSocketServer constructs a new SocketServer, registering handlers for the "connection", "disconnection", and "subscribe" events.
func (*SocketServer) SendNewTx ¶
func (soc *SocketServer) SendNewTx(rawTx *chainjson.TxRawResult) error
SendNewTx prepares a dcrd mempool tx for broadcast. This method satisfies notification.TxHandler and is registered as a handler in main.go.
type WebSocketTx ¶
type WebSocketTx struct { Hash string `json:"txid"` Size int `json:"size"` TotalOut int64 `json:"valueOut"` Vins []InsightSocketVin `json:"vins,omitempty"` Vouts []InsightSocketVout `json:"vout,omitempty"` }
WebSocketTx models the JSON data sent as the tx event in the inv room.