avm_index

package
v0.0.0-...-abd5428 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: BSD-3-Clause Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaginationMaxLimit      = 500
	PaginationDefaultLimit  = 500
	PaginationDefaultOffset = 0

	TransactionSortDefault       TransactionSort = TransactionSortTimestampAsc
	TransactionSortTimestampAsc                  = "timestamp-asc"
	TransactionSortTimestampDesc                 = "timestamp-desc"
)
View Source
const (
	MaxAggregateIntervalCount = 20000
)
View Source
const (
	// MaxSerializationLen is the maximum number of bytes a canonically
	// serialized tx can be stored as in the database.
	MaxSerializationLen = 16_384
)

Variables

View Source
var (
	ErrAggregateIntervalCountTooLarge = errors.New("requesting too many intervals")
	ErrFailedToParseStringAsBigInt    = errors.New("failed to parse string to big.Int")
)
View Source
var (
	VMName = "avm"

	OutputTypesSECP2556K1Transfer OutputType = 0x000000ff

	TXTypeBase        TransactionType = "base"
	TXTypeCreateAsset TransactionType = "create_asset"
	TXTypeImport      TransactionType = "import"
	TXTypeExport      TransactionType = "export"

	ResultTypeTransaction SearchResultType = "transaction"
	ResultTypeAsset       SearchResultType = "asset"
	ResultTypeAddress     SearchResultType = "address"
	ResultTypeOutput      SearchResultType = "output"

	IntervalMinute = 1 * time.Minute
	IntervalHour   = 60 * time.Minute
	IntervalDay    = 1440 * time.Minute
	IntervalWeek   = 7 * IntervalDay
	IntervalMonth  = 30 * IntervalDay
	IntervalYear   = 365 * IntervalDay
	IntervalAll    = time.Duration(0)

	IntervalNames = map[string]time.Duration{
		"minute": IntervalMinute,
		"hour":   IntervalHour,
		"day":    IntervalDay,
		"week":   IntervalWeek,
		"month":  IntervalMonth,
		"year":   IntervalYear,
		"all":    IntervalAll,
	}
)
View Source
var (
	// ErrSerializationTooLong is returned when trying to ingest data with a
	// serialization larger than our max
	ErrSerializationTooLong = errors.New("serialization is too long")
)
View Source
var (
	ErrUndefinedSort = errors.New("undefined sort")
)

Functions

func NewAPIRouter

func NewAPIRouter(params api.RouterFactoryParams) error

Types

type APIContext

type APIContext struct {
	*api.RootRequestContext
	// contains filtered or unexported fields
}

func (*APIContext) Aggregate

func (c *APIContext) Aggregate(w web.ResponseWriter, r *web.Request)

func (*APIContext) GetAddress

func (c *APIContext) GetAddress(w web.ResponseWriter, r *web.Request)

func (*APIContext) GetAsset

func (c *APIContext) GetAsset(w web.ResponseWriter, r *web.Request)

func (*APIContext) GetOutput

func (c *APIContext) GetOutput(w web.ResponseWriter, r *web.Request)

func (*APIContext) GetTransaction

func (c *APIContext) GetTransaction(w web.ResponseWriter, r *web.Request)

func (*APIContext) ListAddresses

func (c *APIContext) ListAddresses(w web.ResponseWriter, r *web.Request)

func (*APIContext) ListAssets

func (c *APIContext) ListAssets(w web.ResponseWriter, r *web.Request)

func (*APIContext) ListOutputs

func (c *APIContext) ListOutputs(w web.ResponseWriter, r *web.Request)

func (*APIContext) ListTransactions

func (c *APIContext) ListTransactions(w web.ResponseWriter, r *web.Request)

func (*APIContext) Overview

func (c *APIContext) Overview(w web.ResponseWriter, _ *web.Request)

func (*APIContext) Search

func (c *APIContext) Search(w web.ResponseWriter, r *web.Request)

type Address

type Address struct {
	Address stringShortID `json:"address"`
	ChainID stringID      `json:"chainID"`

	PublicKey        []byte `json:"publicKey"`
	TransactionCount uint64 `json:"transactionCount"`

	Balance       tokenAmount `json:"balance"`
	TotalReceived tokenAmount `json:"totalReceived"`
	TotalSent     tokenAmount `json:"totalSent"`
	UTXOCount     uint64      `json:"utxoCount"`

	Score uint64 `json:"-"`
}

type AddressList

type AddressList struct {
	ListMetadata
	Addresses []*Address `json:"addresses"`
}

type AggregateParams

type AggregateParams struct {
	AssetID      *ids.ID
	StartTime    time.Time
	EndTime      time.Time
	IntervalSize time.Duration
}

func GetAggregateTransactionsParamsForHTTPRequest

func GetAggregateTransactionsParamsForHTTPRequest(r *http.Request) (*AggregateParams, error)

type Aggregates

type Aggregates struct {
	// Idx is used internally when creating a histogram of Aggregates.
	// It is exported only so it can be written to by dbr.
	Idx int `json:"-"`

	StartTime time.Time `json:"startTime"`
	EndTime   time.Time `json:"endTime"`

	TransactionVolume tokenAmount `json:"transactionVolume"`

	TransactionCount uint64 `json:"transactionCount"`
	AddressCount     uint64 `json:"addressCount"`
	OutputCount      uint64 `json:"outputCount"`
	AssetCount       uint64 `json:"assetCount"`
}

type AggregatesHistogram

type AggregatesHistogram struct {
	Aggregates   Aggregates    `json:"aggregates"`
	IntervalSize time.Duration `json:"intervalSize,omitempty"`
	Intervals    []Aggregates  `json:"intervals,omitempty"`
}

type Asset

type Asset struct {
	ID      stringID `json:"id"`
	ChainID stringID `json:"chainID"`

	Name         string `json:"name"`
	Symbol       string `json:"symbol"`
	Alias        string `json:"alias"`
	Denomination uint8  `json:"denomination"`

	CurrentSupply tokenAmount `json:"currentSupply"`
	CreatedAt     time.Time   `json:"timestamp"`

	Score uint64 `json:"-"`
}

type AssetList

type AssetList struct {
	ListMetadata
	Assets []*Asset `json:"assets"`
}

type AssetTokenCounts

type AssetTokenCounts map[stringID]tokenAmount

AssetTokenCounts maps asset IDs to a tokenAmount for that asset

type ChainInfo

type ChainInfo struct {
	ID        ids.ID `json:"chainID"`
	Alias     string `json:"chainAlias"`
	VM        string `json:"vm"`
	NetworkID uint32 `json:"networkID"`
}

type DB

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

DB is a services.Accumulator backed by redis

func NewDB

func NewDB(stream *health.Stream, db *dbr.Connection, chainID ids.ID, codec codec.Codec) *DB

NewDB creates a new DB for the given config

func (*DB) AddTx

func (r *DB) AddTx(tx *avm.UniqueTx, ts uint64, canonicalSerialization []byte) error

AddTx ingests a Transaction and adds it to the services

func (*DB) Aggregate

func (r *DB) Aggregate(params AggregateParams) (*AggregatesHistogram, error)

func (*DB) ListAddresses

func (r *DB) ListAddresses(params *ListAddressesParams) (*AddressList, error)

func (*DB) ListAssets

func (r *DB) ListAssets(params *ListAssetsParams) (*AssetList, error)

func (*DB) ListOutputs

func (r *DB) ListOutputs(params *ListOutputsParams) (*OutputList, error)

func (*DB) ListTransactions

func (r *DB) ListTransactions(params *ListTransactionsParams) (*TransactionList, error)

func (*DB) Search

func (r *DB) Search(params SearchParams) (*SearchResults, error)

type Index

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

func New

func New(conf cfg.ServiceConfig, networkID uint32, chainID ids.ID) (*Index, error)

func (*Index) Add

func (i *Index) Add(ingestable services.Ingestable) error

func (*Index) Aggregate

func (i *Index) Aggregate(params AggregateParams) (*AggregatesHistogram, error)

func (*Index) Bootstrap

func (i *Index) Bootstrap() error

func (*Index) GetAddress

func (i *Index) GetAddress(id ids.ShortID) (*Address, error)

func (*Index) GetAsset

func (i *Index) GetAsset(idStrOrAlias string) (*Asset, error)

func (*Index) GetChainInfo

func (i *Index) GetChainInfo(alias string, networkID uint32) (*ChainInfo, error)

func (*Index) GetOutput

func (i *Index) GetOutput(id ids.ID) (*Output, error)

func (*Index) GetTransaction

func (i *Index) GetTransaction(id ids.ID) (*Transaction, error)

func (*Index) ListAddresses

func (i *Index) ListAddresses(params *ListAddressesParams) (*AddressList, error)

func (*Index) ListAssets

func (i *Index) ListAssets(params *ListAssetsParams) (*AssetList, error)

func (*Index) ListOutputs

func (i *Index) ListOutputs(params *ListOutputsParams) (*OutputList, error)

func (*Index) ListTransactions

func (i *Index) ListTransactions(params *ListTransactionsParams) (*TransactionList, error)

func (*Index) Search

func (i *Index) Search(params SearchParams) (*SearchResults, error)

type Input

type Input struct {
	Output *Output            `json:"output"`
	Creds  []InputCredentials `json:"credentials"`
}

type InputCredentials

type InputCredentials struct {
	Address   stringShortID `json:"address"`
	PublicKey []byte        `json:"public_key"`
	Signature []byte        `json:"signature"`
}

type ListAddressesParams

type ListAddressesParams struct {
	ListParams
	Address *ids.ShortID
	Query   string
}

func ListAddressesParamsForHTTPRequest

func ListAddressesParamsForHTTPRequest(r *http.Request) (*ListAddressesParams, error)

func (*ListAddressesParams) Apply

type ListAssetsParams

type ListAssetsParams struct {
	ListParams
	ID    *ids.ID
	Query string
	Alias string
}

func ListAssetsParamsForHTTPRequest

func ListAssetsParamsForHTTPRequest(r *http.Request) (*ListAssetsParams, error)

func (*ListAssetsParams) Apply

type ListMetadata

type ListMetadata struct {
	Count uint64 `json:"count"`
}

type ListOutputsParams

type ListOutputsParams struct {
	ListParams
	ID    *ids.ID
	Query string

	Addresses []ids.ShortID
	Spent     *bool
}

func ListOutputsParamsForHTTPRequest

func ListOutputsParamsForHTTPRequest(r *http.Request) (*ListOutputsParams, error)

func (*ListOutputsParams) Apply

type ListParams

type ListParams struct {
	Limit  int
	Offset int
}

func ListParamForHTTPRequest

func ListParamForHTTPRequest(r *http.Request) (params ListParams, err error)

func (ListParams) Apply

type ListTransactionsParams

type ListTransactionsParams struct {
	ListParams

	ID *ids.ID

	Query string

	Addresses []ids.ShortID
	AssetID   *ids.ID

	StartTime time.Time
	EndTime   time.Time

	Sort TransactionSort
}

func ListTransactionsParamsForHTTPRequest

func ListTransactionsParamsForHTTPRequest(r *http.Request) (*ListTransactionsParams, error)

func (*ListTransactionsParams) Apply

type Output

type Output struct {
	ID            stringID        `json:"id"`
	TransactionID stringID        `json:"transactionID"`
	OutputIndex   uint64          `json:"outputIndex"`
	AssetID       stringID        `json:"assetID"`
	OutputType    OutputType      `json:"outputType"`
	Amount        tokenAmount     `json:"amount"`
	Locktime      uint64          `json:"locktime"`
	Threshold     uint64          `json:"threshold"`
	Addresses     []stringShortID `json:"addresses"`
	CreatedAt     time.Time       `json:"timestamp"`

	RedeemingTransactionID stringID `json:"redeemingTransactionID"`

	Score uint64 `json:"-"`
}

type OutputAddress

type OutputAddress struct {
	OutputID  stringID      `json:"output_id"`
	Address   stringShortID `json:"address"`
	Signature []byte        `json:"signature"`
	CreatedAt time.Time     `json:"timestamp"`
	PublicKey []byte        `json:"-"`
}

type OutputList

type OutputList struct {
	ListMetadata
	Outputs []*Output `json:"outputs"`
}

type OutputType

type OutputType uint32

OutputType represents a sub class of Output

type Redis

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

Redis is an Accumulator and Index backed by redis

func NewRedisIndex

func NewRedisIndex(client *redis.Client, chainID ids.ID) *Redis

NewRedisIndex creates a new Redis for the given config

func (*Redis) AddTx

func (r *Redis) AddTx(txID ids.ID, body []byte) error

AddTx ingests a Transaction and adds it to the services

func (*Redis) GetRecentTransactions

func (r *Redis) GetRecentTransactions(n int64) ([]ids.ID, error)

GetRecentTransactions returns a list of the N most recent transactions

func (*Redis) GetTx

func (r *Redis) GetTx(txID ids.ID) ([]byte, error)

GetTransaction returns the bytes for the Transaction with the given ID

func (*Redis) GetTxCount

func (r *Redis) GetTxCount() (uint64, error)

GetTransactionCount returns the number of transactions this Server as seen

type SearchParams

type SearchParams struct {
	ListParams
	Query string
}

func SearchParamsForHTTPRequest

func SearchParamsForHTTPRequest(r *http.Request) (*SearchParams, error)

type SearchResult

type SearchResult struct {
	// SearchResultType is the type of object found
	SearchResultType `json:"type"`

	// Data is the object itself
	Data interface{} `json:"data"`

	// Score is a rank of how well this result matches the query
	Score uint64 `json:"score"`
}

SearchResult represents a single item matching a search query.

type SearchResultSet

type SearchResultSet []SearchResult

func (SearchResultSet) Len

func (srs SearchResultSet) Len() int

func (SearchResultSet) Less

func (s SearchResultSet) Less(i, j int) bool

func (SearchResultSet) Swap

func (s SearchResultSet) Swap(i, j int)

type SearchResultType

type SearchResultType string

SearchResultType is the type for an object found from a search query.

type SearchResults

type SearchResults struct {
	// Count is the total number of matching results
	Count uint64 `json:"count"`

	// Results is a list of SearchResult
	Results SearchResultSet `json:"results"`
}

SearchResults represents a set of items returned for a search query.

type Transaction

type Transaction struct {
	ID      stringID `json:"id"`
	ChainID stringID `json:"chainID"`
	Type    string   `json:"type"`

	Inputs  []*Input  `json:"inputs"`
	Outputs []*Output `json:"outputs"`

	InputTotals         AssetTokenCounts `json:"inputTotals"`
	OutputTotals        AssetTokenCounts `json:"outputTotals"`
	ReusedAddressTotals AssetTokenCounts `json:"reusedAddressTotals"`

	CanonicalSerialization []byte    `json:"canonicalSerialization,omitempty"`
	CreatedAt              time.Time `json:"timestamp"`

	Score uint64 `json:"-"`
}

type TransactionList

type TransactionList struct {
	ListMetadata
	Transactions []*Transaction `json:"transactions"`
}

type TransactionSort

type TransactionSort string

Sorting

type TransactionType

type TransactionType string

TransactionType represents a sub class of Transaction

Jump to

Keyboard shortcuts

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