insight

package
v0.0.0-...-c9ddbe3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: ISC Imports: 36 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 PostAddrsTxsCtx

func PostAddrsTxsCtx(next http.Handler) http.Handler

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

func PostAddrsUtxoCtx(next http.Handler) http.Handler

PostAddrsUtxoCtx middleware processes parameters given in the POST request body for an addrs utxo endpoint.

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) ApiMux

NewInsightApiRouter returns a new HTTP path router, ApiMux, for the Insight API, app.

type InsightApi

type InsightApi struct {
	BlockData *dcrpg.ChainDB

	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.ChainDB, 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 ecrd-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 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 ecrd 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