insight

package
v0.0.0-...-ae3472c Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: ISC Imports: 35 Imported by: 0

Documentation

Overview

Package insight implements the Insight API.

Index

Constants

View Source
const APIVersion = 0

APIVersion is an integer value, incremented for breaking changes

Variables

This section is empty.

Functions

func AddressCommandCtx

func AddressCommandCtx(next http.Handler) http.Handler

AddressCommandCtx returns a http.HandlerFunc that embeds the value at the url part {command} into the request context.

func BlockDateLimitQueryCtx

func BlockDateLimitQueryCtx(next http.Handler) http.Handler

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

func FromToPaginationCtx(next http.Handler) http.Handler

FromToPaginationCtx will parse the query parameters for from/to values.

func GetAddressCommandCtx

func GetAddressCommandCtx(r *http.Request) (string, bool)

GetAddressCommandCtx retrieves the ctxAddrCmd data from the request context. If not set the return value is "" and false.

func GetFromCtx

func GetFromCtx(r *http.Request) int64

GetFromCtx retrieves the ctxFrom data ("from") from the request context. If not set, the return value is 0

func GetLimitCtx

func GetLimitCtx(r *http.Request) int

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

func GetNbBlocksCtx(r *http.Request) int

GetNbBlocksCtx retrieves the ctxNbBlocks data from the request context. If not set, the return value is 0.

func GetNoAsmCtx

func GetNoAsmCtx(r *http.Request) bool

GetNoAsmCtx retrieves the ctxNoAsm data ("noAsm") from the request context. If not set, the return value is false.

func GetNoScriptSigCtx

func GetNoScriptSigCtx(r *http.Request) bool

GetNoScriptSigCtx retrieves the ctxNoScriptSig data ("noScriptSig") from the request context. If not set, the return value is false.

func GetNoSpentCtx

func GetNoSpentCtx(r *http.Request) bool

GetNoSpentCtx retrieves the ctxNoSpent data ("noSpent") from the request context. If not set, the return value is false.

func GetNoTxListCtx

func GetNoTxListCtx(r *http.Request) int

GetNoTxListCtx retrieves the ctxNoTxList data ("noTxList") from the request context. If not set, the return value is false.

func GetToCtx

func GetToCtx(r *http.Request) (int64, bool)

GetToCtx retrieves the ctxTo data ("to") from the request context. If not set, the return value ok is false.

func NbBlocksCtx

func NbBlocksCtx(next http.Handler) http.Handler

NbBlocksCtx will parse the query parameters for nbBlocks.

func NoTxListCtx

func NoTxListCtx(next http.Handler) http.Handler

NoTxListCtx returns a http.Handlerfunc that embeds the {noTxList} value in the request into the request context.

func PostAddrsTxsCtxN

func PostAddrsTxsCtxN(n int) func(next http.Handler) http.Handler

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

func PostAddrsUtxoCtxN(n int) func(next http.Handler) http.Handler

PostAddrsUtxoCtxN middleware processes parameters given in the POST request body for an addrs utxo endpoint, limiting to N addresses.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

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

type InsightSocketVout struct {
	Address string
	Value   int64
}

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

type SocketServer struct {
	*socketio.Server
	// contains filtered or unexported fields
}

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.

func (*SocketServer) Store

func (soc *SocketServer) Store(blockData *blockdata.BlockData, msgBlock *wire.MsgBlock) error

Store broadcasts the lastest block hash to the the inv room. The coinbase transaction is also relayed to the new Tx channel where it is included in tx and address broadcasts.

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.

Jump to

Keyboard shortcuts

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