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 PostAddrsTxsCtxN(n int) func(next http.Handler) http.Handler
- func PostAddrsUtxoCtxN(n int) func(next http.Handler) http.Handler
- func UseLogger(logger slog.Logger)
- type ApiMux
- type BlockDataSource
- 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 MempoolAddressChecker
- 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 PostAddrsTxsCtxN ¶
PostAddrsTxsCtxN middleware processes parameters given in the POST request body for an addrs endpoint, limiting to N addresses. 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 PostAddrsUtxoCtxN ¶
PostAddrsUtxoCtxN middleware processes parameters given in the POST request body for an addrs utxo endpoint, limiting to N addresses.
Types ¶
type ApiMux ¶
type ApiMux struct {
*chi.Mux
}
ApiMux contains the struct mux
func NewInsightAPIRouter ¶
func NewInsightAPIRouter(app *InsightApi, useRealIP, compression bool, maxAddrs int) ApiMux
NewInsightAPIRouter returns a new HTTP path router, ApiMux, for the Insight API, app.
type BlockDataSource ¶
type BlockDataSource interface { AddressBalance(address string) (bal *dbtypes.AddressBalance, cacheUpdated bool, err error) AddressIDsByOutpoint(txHash string, voutIndex uint32) ([]uint64, []string, int64, error) AddressUTXO(address string) ([]*dbtypes.AddressTxnOutput, bool, error) BlockSummaryTimeRange(min, max int64, limit int) ([]dbtypes.BlockDataBasic, error) GetBlockHash(idx int64) (string, error) GetBlockHeight(hash string) (int64, error) GetBlockVerboseByHash(hash string, verboseTx bool) *chainjson.GetBlockVerboseResult GetHeight() (int64, error) GetRawTransactionVerbose(txid *chainhash.Hash) (*chainjson.TxRawResult, error) GetTransactionHex(txid *chainhash.Hash) string Height() int64 DCP0010ActivationHeight() int64 InsightAddressTransactions(addr []string, recentBlockHeight int64) (txs, recentTxs []chainhash.Hash, err error) SendRawTransaction(txhex string) (string, error) SpendDetailsForFundingTx(fundHash string) ([]*apitypes.SpendByFundingHash, error) }
type InsightApi ¶
type InsightApi struct { BlockData BlockDataSource 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 BlockDataSource, params *chaincfg.Params, memPoolData MempoolAddressChecker, JSONIndent string, 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 MempoolAddressChecker ¶
type MempoolAddressChecker interface {
UnconfirmedTxnsForAddress(address string) (*txhelpers.AddressOutpoints, int64, error)
}
MempoolAddressChecker is an interface implementing UnconfirmedTxnsForAddress
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.