idb

package
v0.0.0-...-3979f71 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorBlockNotFound = errors.New("block not found")

ErrorBlockNotFound is used when requesting a block that isn't in the DB.

View Source
var ErrorNotInitialized error = errors.New("accounting not initialized")

ErrorNotInitialized is used when requesting something that can't be returned because initialization has not been completed.

View Source
var SigTypeEnumString = makeSigTypeEnumString()

SigTypeEnumString is a comma-separated list of possible signature types.

View Source
var TxnTypeEnumString = makeTypeEnumString()

TxnTypeEnumString is a comma-separated list of possible transaction types.

Functions

func DecodeTxnRowNext

func DecodeTxnRowNext(s string) (uint64, uint32, error)

DecodeTxnRowNext unpacks opaque string returned from TxnRow.Next()

func IsSigTypeValid

func IsSigTypeValid(sigtype SigType) bool

IsSigTypeValid returns true if and only if `sigtype` is one of the possible signature types.

func RegisterFactory

func RegisterFactory(name string, factory IndexerDbFactory)

RegisterFactory is used by IndexerDb implementations to register their implementations. This mechanism allows for loose coupling between the configuration and the implementation. It is extremely similar to the way sql.DB driver's are configured and used.

Types

type AccountQueryOptions

type AccountQueryOptions struct {
	GreaterThanAddress []byte // for paging results
	EqualToAddress     []byte // return exactly this one account

	// return any accounts with this auth addr
	EqualToAuthAddr []byte

	// Filter on accounts with current balance greater than x
	AlgosGreaterThan *uint64
	// Filter on accounts with current balance less than x.
	AlgosLessThan *uint64

	// HasAssetID, AssetGT, and AssetLT are implemented in Go code
	// after data has returned from Postgres and thus are slightly
	// less efficient. They will turn on IncludeAssetHoldings.
	HasAssetID uint64
	AssetGT    *uint64
	AssetLT    *uint64

	HasAppID uint64

	IncludeAssetHoldings bool
	IncludeAssetParams   bool
	IncludeAppLocalState bool
	IncludeAppParams     bool

	// MaxResources is the maximum combined number of AppParam, AppLocalState, AssetParam, and AssetHolding objects allowed.
	MaxResources uint64

	// IncludeDeleted indicated whether to include deleted Assets, Applications, etc within the account.
	IncludeDeleted bool

	Limit uint64
}

AccountQueryOptions is a parameter object with all of the account filter options.

type AccountRow

type AccountRow struct {
	Account models.Account
	Error   error // could be MaxAPIResourcesPerAccountError
}

AccountRow is metadata relating to one account in a account query.

type AddressRole

type AddressRole uint64

AddressRole is a dedicated type for the address role.

const (
	AddressRoleSender           AddressRole = 0x01
	AddressRoleReceiver         AddressRole = 0x02
	AddressRoleCloseRemainderTo AddressRole = 0x04
	AddressRoleAssetSender      AddressRole = 0x08
	AddressRoleAssetReceiver    AddressRole = 0x10
	AddressRoleAssetCloseTo     AddressRole = 0x20
	AddressRoleFreeze           AddressRole = 0x40
)

All possible address roles.

type AppLocalStateRow

type AppLocalStateRow struct {
	AppLocalState models.ApplicationLocalState
	Error         error
}

AppLocalStateRow is metadata and local state (AppLocalState) relating to one application in an application query.

type ApplicationBoxQuery

type ApplicationBoxQuery struct {
	ApplicationID uint64
	BoxName       []byte
	OmitValues    bool
	Limit         uint64
	PrevFinalBox  []byte
}

ApplicationBoxQuery is a parameter object used to query application boxes.

type ApplicationBoxRow

type ApplicationBoxRow struct {
	App   uint64
	Box   models.Box
	Error error
}

ApplicationBoxRow provides a response wrapping box information.

type ApplicationQuery

type ApplicationQuery struct {
	Address                  []byte
	ApplicationID            uint64
	ApplicationIDGreaterThan uint64
	IncludeDeleted           bool
	Limit                    uint64
}

ApplicationQuery is a parameter object used for query local and global application state.

type ApplicationRow

type ApplicationRow struct {
	Application models.Application
	Error       error
}

ApplicationRow is metadata and global state (AppParams) relating to one application in an application query.

type AssetBalanceQuery

type AssetBalanceQuery struct {
	AssetID   uint64
	AssetIDGT uint64
	AmountGT  *uint64 // only rows > this
	AmountLT  *uint64 // only rows < this

	Address []byte

	// IncludeDeleted indicated whether to include deleted AssetHoldingss in the results.
	IncludeDeleted bool

	Limit uint64 // max rows to return

	// PrevAddress for paging, the last item from the previous
	// query (items returned in address order)
	PrevAddress []byte
}

AssetBalanceQuery is a parameter object with all of the asset balance filter options.

type AssetBalanceRow

type AssetBalanceRow struct {
	Address      []byte
	AssetID      uint64
	Amount       uint64
	Frozen       bool
	Error        error
	CreatedRound *uint64
	ClosedRound  *uint64
	Deleted      *bool
}

AssetBalanceRow is metadata relating to one asset balance in an asset balance query.

type AssetRow

type AssetRow struct {
	AssetID      uint64
	Creator      []byte
	Params       sdk.AssetParams
	Error        error
	CreatedRound *uint64
	ClosedRound  *uint64
	Deleted      *bool
}

AssetRow is metadata relating to one asset in a asset query.

type AssetsQuery

type AssetsQuery struct {
	AssetID            uint64
	AssetIDGreaterThan uint64

	Creator []byte

	// Name is a case insensitive substring comparison of the asset name
	Name string
	// Unit is a case insensitive substring comparison of the asset unit
	Unit string
	// Query checks for fuzzy match against either asset name or unit name
	// (assetname ILIKE '%?%' OR unitname ILIKE '%?%')
	Query string

	// IncludeDeleted indicated whether to include deleted Assets in the results.
	IncludeDeleted bool

	Limit uint64
}

AssetsQuery is a parameter object with all of the asset filter options.

type GetBlockOptions

type GetBlockOptions struct {
	// setting Transactions to true suggests requesting to receive the transactions themselves from the GetBlock query
	Transactions bool
	// if len of the results from buildTransactionQuery is greater than MaxTransactionsLimit, return an error
	// indicating that the header-only flag should be enabled
	MaxTransactionsLimit uint64
}

GetBlockOptions contains the options when requesting to load a block from the database.

type Health

type Health struct {
	Data        *map[string]interface{} `json:"data,omitempty"`
	Round       uint64                  `json:"round"`
	IsMigrating bool                    `json:"is-migrating"`
	DBAvailable bool                    `json:"db-available"`
	Error       string                  `json:"error"`
}

Health is the response object that IndexerDb objects need to return from the Health method.

type IndexerDb

type IndexerDb interface {
	// Close all connections to the database. Should be called when IndexerDb is
	// no longer needed.
	Close()

	// Import a block and do the accounting.
	AddBlock(block *types.ValidatedBlock) error

	LoadGenesis(genesis sdk.Genesis) (err error)

	// GetNextRoundToAccount returns ErrorNotInitialized if genesis is not loaded.
	GetNextRoundToAccount() (uint64, error)
	GetSpecialAccounts(ctx context.Context) (types.SpecialAddresses, error)
	GetNetworkState() (NetworkState, error)
	SetNetworkState(genesis sdk.Digest) error

	GetBlock(ctx context.Context, round uint64, options GetBlockOptions) (blockHeader sdk.BlockHeader, transactions []TxnRow, err error)

	// The next multiple functions return a channel with results as well as the latest round
	// accounted.
	Transactions(ctx context.Context, tf TransactionFilter) (<-chan TxnRow, uint64)
	GetAccounts(ctx context.Context, opts AccountQueryOptions) (<-chan AccountRow, uint64)
	Assets(ctx context.Context, filter AssetsQuery) (<-chan AssetRow, uint64)
	AssetBalances(ctx context.Context, abq AssetBalanceQuery) (<-chan AssetBalanceRow, uint64)
	Applications(ctx context.Context, filter ApplicationQuery) (<-chan ApplicationRow, uint64)
	AppLocalState(ctx context.Context, filter ApplicationQuery) (<-chan AppLocalStateRow, uint64)
	ApplicationBoxes(ctx context.Context, filter ApplicationBoxQuery) (<-chan ApplicationBoxRow, uint64)

	Health(ctx context.Context) (status Health, err error)

	DeleteTransactions(ctx context.Context, keep uint64) error
}

IndexerDb is the interface used to define alternative Indexer backends. TODO: sqlite3 impl TODO: cockroachdb impl

func IndexerDbByName

func IndexerDbByName(name, arg string, opts IndexerDbOptions, log *log.Logger) (IndexerDb, chan struct{}, error)

IndexerDbByName is used to construct an IndexerDb object by name. Returns an IndexerDb object, an availability channel that closes when the database becomes available, and an error object.

type IndexerDbFactory

type IndexerDbFactory interface {
	Name() string
	Build(arg string, opts IndexerDbOptions, log *log.Logger) (IndexerDb, chan struct{}, error)
}

IndexerDbFactory is used to install an IndexerDb implementation.

type IndexerDbOptions

type IndexerDbOptions struct {
	ReadOnly bool
	// Maximum connection number for connection pool
	// This means the total number of active queries that can be running
	// concurrently can never be more than this
	MaxConn uint32

	IndexerDatadir string
	AlgodDataDir   string
	AlgodToken     string
	AlgodAddr      string
}

IndexerDbOptions are the options common to all indexer backends.

type MaxAPIResourcesPerAccountError

type MaxAPIResourcesPerAccountError struct {
	Address sdk.Address

	TotalAppLocalStates, TotalAppParams, TotalAssets, TotalAssetParams uint64
}

MaxAPIResourcesPerAccountError records the offending address and resource count that exceeded the limit.

func (MaxAPIResourcesPerAccountError) Error

type MaxTransactionsError

type MaxTransactionsError struct {
}

MaxTransactionsError records the error when transaction counts exceeds MaxTransactionsLimit.

func (MaxTransactionsError) Error

func (e MaxTransactionsError) Error() string

type NetworkState

type NetworkState struct {
	GenesisHash sdk.Digest `codec:"genesis-hash"`
}

NetworkState encodes network metastate.

type OptionalUint

type OptionalUint struct {
	Present bool
	Value   uint
}

OptionalUint wraps bool and uint. It has a custom marshaller below.

func (OptionalUint) MarshalText

func (ou OptionalUint) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler interface.

func (*OptionalUint) UnmarshalText

func (ou *OptionalUint) UnmarshalText(text []byte) error

UnmarshalText implements TextUnmarshaler interface.

type SigType

type SigType string

SigType is signature type.

const (
	Sig  SigType = "sig"
	Msig SigType = "msig"
	Lsig SigType = "lsig"
)

Possible signature types.

func SignatureType

func SignatureType(stxn *sdk.SignedTxn) (SigType, error)

SignatureType returns the signature type of the given signed transaction.

type TransactionFilter

type TransactionFilter struct {
	// SkipOptimization is used for testing to ensure the parameters are not modified.
	SkipOptimization bool

	// Address filtering transactions for one Address will
	// return transactions newest-first proceding into the
	// past. Paging through such results can be achieved by
	// setting a MaxRound to get results before.
	Address []byte

	AddressRole AddressRole // 0=Any, otherwise bitfields as defined in address_role.go

	MinRound   uint64
	MaxRound   uint64
	AfterTime  time.Time
	BeforeTime time.Time
	TypeEnum   TxnTypeEnum // ["","pay","keyreg","acfg","axfer","afrz"]
	Txid       string
	Round      *uint64 // nil for no filter
	Offset     *uint64 // nil for no filter
	OffsetLT   *uint64 // nil for no filter
	OffsetGT   *uint64 // nil for no filter
	SigType    SigType // ["", "sig", "msig", "lsig"]
	NotePrefix []byte
	AlgosGT    *uint64 // implictly filters on "pay" txns for Algos > this. This will be a slightly faster query than EffectiveAmountGT.
	AlgosLT    *uint64
	RekeyTo    *bool // nil for no filter

	AssetID       uint64 // filter transactions relevant to an asset
	AssetAmountGT *uint64
	AssetAmountLT *uint64

	ApplicationID uint64 // filter transactions relevant to an application

	EffectiveAmountGT *uint64 // Algo: Amount + CloseAmount > x
	EffectiveAmountLT *uint64 // Algo: Amount + CloseAmount < x

	// pointer to last returned object of previous query
	NextToken string

	Limit uint64

	// If this flag is set to true, then the query returns inner transactions
	// instead of converting them to the root transaction.
	SkipInnerTransactionConversion bool

	// If this flag is set to true, then the query only returns root
	// transactions and skips matching or returning inner transactions.
	SkipInnerTransactions bool

	// If this flag is set to true, then the query returns the block excluding
	// the transactions
	HeaderOnly bool
}

TransactionFilter is a parameter object with all the transaction filter options.

type TxnExtra

type TxnExtra struct {
	AssetCloseAmount uint64 `codec:"aca,omitempty"`
	// RootIntra is set only on inner transactions. Combined with the confirmation
	// round it can be used to lookup the root transaction.
	RootIntra OptionalUint `codec:"root-intra,omitempty"`
	// RootTxid is set on inner transactions. It is a convenience for the
	// future. If we decide to return inner transactions we'll want to include
	// the root txid.
	RootTxid string `codec:"root-txid,omitempty"`
}

TxnExtra is some additional metadata needed for a transaction.

type TxnRow

type TxnRow struct {
	// Round is the round where the transaction was committed.
	Round uint64

	// Round time  is the block time when the block was confirmed.
	RoundTime time.Time

	// Intra is the offset into the block where this transaction was placed.
	Intra int

	// TxnBytes is the raw signed transaction with apply data object, only used when the root txn is being returned.
	Txn *sdk.SignedTxnWithAD

	// RootTxnBytes the root transaction raw signed transaction with apply data object, only inner transactions have this.
	RootTxn *sdk.SignedTxnWithAD

	// AssetID is the ID of any asset or application created or configured by this
	// transaction.
	AssetID uint64

	// Extra are some additional fields which might be related to to the transaction.
	Extra TxnExtra

	// Error indicates that there was an internal problem processing the expected transaction.
	Error error
}

TxnRow is metadata relating to one transaction in a transaction query.

func (TxnRow) Next

func (tr TxnRow) Next(ascending bool) (string, error)

Next returns what should be an opaque string to be used with the next query to resume where a previous limit left off.

type TxnTypeEnum

type TxnTypeEnum int

TxnTypeEnum describes the type of a transaction. It is stored in the database for each transaction. The api layer can filter transactions by type by including the enum in the transaction filter.

const (
	TypeEnumPay TxnTypeEnum = iota + 1
	TypeEnumKeyreg
	TypeEnumAssetConfig
	TypeEnumAssetTransfer
	TypeEnumAssetFreeze
	TypeEnumApplication
	TypeEnumStateProof
)

All possible transaction types.

func GetTypeEnum

func GetTypeEnum(t sdk.TxType) (TxnTypeEnum, bool)

GetTypeEnum returns the enum for the given transaction type string.

Jump to

Keyboard shortcuts

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