query

package
v0.0.0-...-6d4bf48 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package query implements indexing and querying of annotated blockchain data.

Index

Constants

View Source
const (
	// TxPinName is used to identify the pin associated
	// with the transaction block processor.
	TxPinName = "tx"
)

Variables

View Source
var (
	ErrBadAfter               = errors.New("malformed pagination parameter after")
	ErrParameterCountMismatch = errors.New("wrong number of parameters to query")
)

Functions

func ValidateTransactionFilter

func ValidateTransactionFilter(filt string) error

Types

type AccountKey

type AccountKey struct {
	RootXPub              chainkd.XPub         `json:"root_xpub"`
	AccountXPub           chainkd.XPub         `json:"account_xpub"`
	AccountDerivationPath []chainjson.HexBytes `json:"account_derivation_path"`
}

type AnnotatedAccount

type AnnotatedAccount struct {
	ID     string           `json:"id"`
	Alias  string           `json:"alias,omitempty"`
	Keys   []*AccountKey    `json:"keys"`
	Quorum int              `json:"quorum"`
	Tags   *json.RawMessage `json:"tags"`
}

type AnnotatedAsset

type AnnotatedAsset struct {
	ID              bc.AssetID         `json:"id"`
	Alias           string             `json:"alias,omitempty"`
	IssuanceProgram chainjson.HexBytes `json:"issuance_program"`
	Keys            []*AssetKey        `json:"keys"`
	Quorum          int                `json:"quorum"`
	Definition      *json.RawMessage   `json:"definition"`
	Tags            *json.RawMessage   `json:"tags"`
	IsLocal         Bool               `json:"is_local"`
}

type AnnotatedInput

type AnnotatedInput struct {
	Type            string             `json:"type"`
	AssetID         bc.AssetID         `json:"asset_id"`
	AssetAlias      string             `json:"asset_alias,omitempty"`
	AssetDefinition *json.RawMessage   `json:"asset_definition"`
	AssetTags       *json.RawMessage   `json:"asset_tags,omitempty"`
	AssetIsLocal    Bool               `json:"asset_is_local"`
	Amount          uint64             `json:"amount"`
	IssuanceProgram chainjson.HexBytes `json:"issuance_program,omitempty"`
	ControlProgram  chainjson.HexBytes `json:"-"`
	SpentOutputID   *bc.Hash           `json:"spent_output_id,omitempty"`
	AccountID       string             `json:"account_id,omitempty"`
	AccountAlias    string             `json:"account_alias,omitempty"`
	AccountTags     *json.RawMessage   `json:"account_tags,omitempty"`
	ReferenceData   *json.RawMessage   `json:"reference_data"`
	IsLocal         Bool               `json:"is_local"`
}

type AnnotatedOutput

type AnnotatedOutput struct {
	Type            string             `json:"type"`
	Purpose         string             `json:"purpose,omitempty"`
	OutputID        bc.Hash            `json:"id"`
	TransactionID   *bc.Hash           `json:"transaction_id,omitempty"`
	Position        int                `json:"position"`
	AssetID         bc.AssetID         `json:"asset_id"`
	AssetAlias      string             `json:"asset_alias,omitempty"`
	AssetDefinition *json.RawMessage   `json:"asset_definition"`
	AssetTags       *json.RawMessage   `json:"asset_tags"`
	AssetIsLocal    Bool               `json:"asset_is_local"`
	Amount          uint64             `json:"amount"`
	AccountID       string             `json:"account_id,omitempty"`
	AccountAlias    string             `json:"account_alias,omitempty"`
	AccountTags     *json.RawMessage   `json:"account_tags,omitempty"`
	ControlProgram  chainjson.HexBytes `json:"control_program"`
	ReferenceData   *json.RawMessage   `json:"reference_data"`
	IsLocal         Bool               `json:"is_local"`
}

type AnnotatedTx

type AnnotatedTx struct {
	ID                     bc.Hash            `json:"id"`
	Timestamp              time.Time          `json:"timestamp"`
	BlockID                bc.Hash            `json:"block_id"`
	BlockHeight            uint64             `json:"block_height"`
	Position               uint32             `json:"position"`
	BlockTransactionsCount uint32             `json:"block_transactions_count,omitempty"`
	ReferenceData          *json.RawMessage   `json:"reference_data"`
	IsLocal                Bool               `json:"is_local"`
	Inputs                 []*AnnotatedInput  `json:"inputs"`
	Outputs                []*AnnotatedOutput `json:"outputs"`
}

type Annotator

type Annotator func(ctx context.Context, txs []*AnnotatedTx) error

Annotator describes a function capable of adding annotations to transactions, inputs and outputs.

type AssetKey

type AssetKey struct {
	RootXPub            chainkd.XPub         `json:"root_xpub"`
	AssetPubkey         chainjson.HexBytes   `json:"asset_pubkey"`
	AssetDerivationPath []chainjson.HexBytes `json:"asset_derivation_path"`
}

type Bool

type Bool bool

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(raw []byte) error

type Indexer

type Indexer struct {
	// contains filtered or unexported fields
}

Indexer creates, updates and queries against indexes.

func NewIndexer

func NewIndexer(db pg.DB, c *protocol.Chain, pinStore *pin.Store) *Indexer

NewIndexer constructs a new indexer for indexing transactions.

func (*Indexer) Accounts

func (ind *Indexer) Accounts(ctx context.Context, filt string, vals []interface{}, after string, limit int) ([]*AnnotatedAccount, string, error)

Accounts queries the blockchain for accounts matching the query `q`.

func (*Indexer) Assets

func (ind *Indexer) Assets(ctx context.Context, filt string, vals []interface{}, after string, limit int) ([]*AnnotatedAsset, string, error)

Assets queries the blockchain for annotated assets matching the query.

func (*Indexer) Balances

func (ind *Indexer) Balances(ctx context.Context, filt string, vals []interface{}, sumBy []filter.Field, timestampMS uint64) ([]interface{}, error)

Balances performs a balances query against the annotated_outputs.

func (*Indexer) IndexTransactions

func (ind *Indexer) IndexTransactions(ctx context.Context, b *legacy.Block) error

IndexTransactions is registered as a block callback on the Chain. It saves all annotated transactions to the database.

func (*Indexer) LookupTxAfter

func (ind *Indexer) LookupTxAfter(ctx context.Context, begin, end uint64) (TxAfter, error)

LookupTxAfter looks up the transaction `after` for the provided time range.

func (*Indexer) Outputs

func (ind *Indexer) Outputs(ctx context.Context, filt string, vals []interface{}, timestampMS uint64, after *OutputsAfter, limit int) ([]*AnnotatedOutput, *OutputsAfter, error)

func (*Indexer) ProcessBlocks

func (ind *Indexer) ProcessBlocks(ctx context.Context)

func (*Indexer) RegisterAnnotator

func (ind *Indexer) RegisterAnnotator(annotator Annotator)

RegisterAnnotator adds an additional annotator capable of mutating the annotated transaction object.

func (*Indexer) SaveAnnotatedAccount

func (ind *Indexer) SaveAnnotatedAccount(ctx context.Context, account *AnnotatedAccount) error

SaveAnnotatedAccount saves an annotated account to the query indexes.

func (*Indexer) SaveAnnotatedAsset

func (ind *Indexer) SaveAnnotatedAsset(ctx context.Context, asset *AnnotatedAsset, sortID string) error

SaveAnnotatedAsset saves an annotated asset to the query indexes.

func (*Indexer) Transactions

func (ind *Indexer) Transactions(ctx context.Context, filt string, vals []interface{}, after TxAfter, limit int, asc bool) ([]*AnnotatedTx, *TxAfter, error)

Transactions queries the blockchain for transactions matching the filter predicate `filt`.

type OutputsAfter

type OutputsAfter struct {
	// contains filtered or unexported fields
}

func DecodeOutputsAfter

func DecodeOutputsAfter(str string) (c *OutputsAfter, err error)

func (OutputsAfter) String

func (cur OutputsAfter) String() string

type TxAfter

type TxAfter struct {
	// FromBlockHeight and FromPosition uniquely identify the last transaction returned
	// by a list-transactions query.
	//
	// If list-transactions is called with a time range instead of an `after`, these fields
	// are populated with the position of the transaction at the start of the time range.
	FromBlockHeight uint64 // exclusive
	FromPosition    uint32 // exclusive

	// StopBlockHeight identifies the last block that should be included in a transaction
	// list. It is used when list-transactions is called with a time range instead
	// of an `after`.
	StopBlockHeight uint64 // inclusive
}

func DecodeTxAfter

func DecodeTxAfter(str string) (c TxAfter, err error)

func (TxAfter) String

func (after TxAfter) String() string

Directories

Path Synopsis
Package filter parses and evaluates Chain filter expressions.
Package filter parses and evaluates Chain filter expressions.

Jump to

Keyboard shortcuts

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