Documentation ¶
Overview ¶
Package history contains database record definitions useable for reading rows from a the history portion of horizon's database
Index ¶
- Variables
- func EncodeOfferId(id uint64, typ OfferIDType) int64
- type Account
- type AccountsQ
- type Asset
- type AssetStat
- type Effect
- type EffectType
- type EffectsQ
- func (q *EffectsQ) ForAccount(aid string) *EffectsQ
- func (q *EffectsQ) ForLedger(seq int32) *EffectsQ
- func (q *EffectsQ) ForOperation(id int64) *EffectsQ
- func (q *EffectsQ) ForOrderBook(selling, buying xdr.Asset) *EffectsQ
- func (q *EffectsQ) ForTransaction(hash string) *EffectsQ
- func (q *EffectsQ) OfType(typ EffectType) *EffectsQ
- func (q *EffectsQ) Page(page db2.PageQuery) *EffectsQ
- func (q *EffectsQ) Select(dest interface{}) error
- type FeeStats
- type LatestLedger
- type Ledger
- type LedgerCache
- type LedgersQ
- type OfferIDType
- type Operation
- type OperationsQ
- func (q *OperationsQ) ForAccount(aid string) *OperationsQ
- func (q *OperationsQ) ForLedger(seq int32) *OperationsQ
- func (q *OperationsQ) ForTransaction(hash string) *OperationsQ
- func (q *OperationsQ) OnlyPayments() *OperationsQ
- func (q *OperationsQ) Page(page db2.PageQuery) *OperationsQ
- func (q *OperationsQ) Select(dest interface{}) error
- type Q
- func (q *Q) AccountByAddress(dest interface{}, addy string) error
- func (q *Q) AccountByID(dest interface{}, id int64) error
- func (q *Q) Accounts() *AccountsQ
- func (q *Q) AccountsByAddresses(dest interface{}, addresses []string) error
- func (q *Q) CreateAccounts(dest interface{}, addresses []string) error
- func (q *Q) Effects() *EffectsQ
- func (q *Q) ElderLedger(dest interface{}) error
- func (q *Q) GetAssetByID(dest interface{}, id int64) (err error)
- func (q *Q) GetAssetID(asset xdr.Asset) (id int64, err error)
- func (q *Q) GetAssetIDs(assets []xdr.Asset) ([]int64, error)
- func (q *Q) GetCreateAccountID(aid xdr.AccountId) (result int64, err error)
- func (q *Q) GetCreateAssetID(asset xdr.Asset) (result int64, err error)
- func (q Q) GetTradeAggregationsQ(baseAssetID int64, counterAssetID int64, resolution int64, offset int64, ...) (*TradeAggregationsQ, error)
- func (q *Q) InsertTrade(opid int64, order int32, buyer xdr.AccountId, buyOfferExists bool, ...) error
- func (q *Q) LatestLedger(dest interface{}) error
- func (q *Q) LatestLedgerBaseFeeAndSequence(dest interface{}) error
- func (q *Q) LedgerBySequence(dest interface{}, seq int32) error
- func (q *Q) Ledgers() *LedgersQ
- func (q *Q) LedgersBySequence(dest interface{}, seqs ...int32) error
- func (q *Q) OldestOutdatedLedgers(dest interface{}, currentVersion int) error
- func (q *Q) OperationByID(dest interface{}, id int64) error
- func (q *Q) Operations() *OperationsQ
- func (q *Q) ReverseTrades() *TradesQ
- func (q *Q) Trades() *TradesQ
- func (q *Q) TradesForAssetPair(baseAssetId int64, counterAssetId int64) *TradesQ
- func (q *Q) TransactionByHash(dest interface{}, hash string) error
- func (q *Q) Transactions() *TransactionsQ
- func (q *Q) TransactionsForLastXLedgers(currentSeq int32, dest interface{}) error
- type TotalOrderID
- type Trade
- type TradeAggregation
- type TradeAggregationsQ
- type TradesQ
- type Transaction
- type TransactionsQ
Constants ¶
This section is empty.
Variables ¶
var AllowedResolutions = map[time.Duration]struct{}{ time.Minute: {}, time.Minute * 5: {}, time.Minute * 15: {}, time.Hour: {}, time.Hour * 24: {}, time.Hour * 24 * 7: {}, }
AllowedResolutions is the set of trade aggregation time windows allowed to be used as the `resolution` parameter.
var StrictResolutionFiltering = true
StrictResolutionFiltering represents a simple feature flag to determine whether only predetermined resolutions of trade aggregations are allowed.
Functions ¶
func EncodeOfferId ¶
func EncodeOfferId(id uint64, typ OfferIDType) int64
EncodeOfferId creates synthetic offer ids to be used by trade resources
This is required because stellar-core does not allocate offer ids for immediately filled offers, while clients expect them for aggregated views.
The encoded value is of type int64 for sql compatibility. The 2nd bit is used to differentiate between stellar-core offer ids and operation ids, which are toids.
Due to the 2nd bit being used, the largest possible toid is: 0011111111111111111111111111111100000000000000000001000000000001 \ ledger /\ transaction /\ op /
= 1073741823 with avg. 5 sec close time will reach in ~170 years
Types ¶
type AccountsQ ¶
type AccountsQ struct { Err error // contains filtered or unexported fields }
AccountsQ is a helper struct to aid in configuring queries that loads slices of account structs.
type Asset ¶
type Asset struct { ID int64 `db:"id"` Type string `db:"asset_type"` Code string `db:"asset_code"` Issuer string `db:"asset_issuer"` }
Asset is a row of data from the `history_assets` table
type AssetStat ¶
type AssetStat struct { ID int64 `db:"id"` Amount string `db:"amount"` NumAccounts int32 `db:"num_accounts"` Flags int8 `db:"flags"` Toml string `db:"toml"` }
AssetStat is a row in the asset_stats table representing the stats per Asset
type Effect ¶
type Effect struct { HistoryAccountID int64 `db:"history_account_id"` Account string `db:"address"` HistoryOperationID int64 `db:"history_operation_id"` Order int32 `db:"order"` Type EffectType `db:"type"` DetailsString null.String `db:"details"` }
Effect is a row of data from the `history_effects` table
func (*Effect) LedgerSequence ¶
LedgerSequence return the ledger in which the effect occurred.
func (*Effect) PagingToken ¶
PagingToken returns a cursor for this effect
func (*Effect) UnmarshalDetails ¶
UnmarshalDetails unmarshals the details of this effect into `dest`
type EffectType ¶
type EffectType int
EffectType is the numeric type for an effect, used as the `type` field in the `history_effects` table.
const ( // EffectAccountCreated effects occur when a new account is created EffectAccountCreated EffectType = 0 // from create_account // EffectAccountRemoved effects occur when one account is merged into another EffectAccountRemoved EffectType = 1 // from merge_account // EffectAccountCredited effects occur when an account receives some currency EffectAccountCredited EffectType = 2 // from create_account, payment, path_payment, merge_account // EffectAccountDebited effects occur when an account sends some currency EffectAccountDebited EffectType = 3 // from create_account, payment, path_payment, create_account // EffectAccountThresholdsUpdated effects occur when an account changes its // multisig thresholds. EffectAccountThresholdsUpdated EffectType = 4 // from set_options // EffectAccountHomeDomainUpdated effects occur when an account changes its // home domain. EffectAccountHomeDomainUpdated EffectType = 5 // from set_options // EffectAccountFlagsUpdated effects occur when an account changes its // account flags, either clearing or setting. EffectAccountFlagsUpdated EffectType = 6 // from set_options // EffectAccountInflationDestinationUpdated effects occur when an account changes its // inflation destination. EffectAccountInflationDestinationUpdated EffectType = 7 // from set_options // EffectSignerCreated occurs when an account gains a signer EffectSignerCreated EffectType = 10 // from set_options // EffectSignerRemoved occurs when an account loses a signer EffectSignerRemoved EffectType = 11 // from set_options // EffectSignerUpdated occurs when an account changes the weight of one of its // signers. EffectSignerUpdated EffectType = 12 // from set_options // EffectTrustlineCreated occurs when an account trusts an anchor EffectTrustlineCreated EffectType = 20 // from change_trust // EffectTrustlineRemoved occurs when an account removes struct by setting the // limit of a trustline to 0 EffectTrustlineRemoved EffectType = 21 // from change_trust // EffectTrustlineUpdated occurs when an account changes a trustline's limit EffectTrustlineUpdated EffectType = 22 // from change_trust, allow_trust // EffectTrustlineAuthorized occurs when an anchor has AUTH_REQUIRED flag set // to true and it authorizes another account's trustline EffectTrustlineAuthorized EffectType = 23 // from allow_trust // it issues. EffectTrustlineDeauthorized EffectType = 24 // from allow_trust // EffectOfferCreated occurs when an account offers to trade an asset EffectOfferCreated EffectType = 30 // from manage_offer, creat_passive_offer // EffectOfferRemoved occurs when an account removes an offer EffectOfferRemoved EffectType = 31 // from manage_offer, creat_passive_offer, path_payment // EffectOfferUpdated occurs when an offer is updated by the offering account. EffectOfferUpdated EffectType = 32 // from manage_offer, creat_passive_offer, path_payment // EffectTrade occurs when a trade is initiated because of a path payment or // offer operation. EffectTrade EffectType = 33 // from manage_offer, creat_passive_offer, path_payment // EffectDataCreated occurs when an account gets a new data field EffectDataCreated EffectType = 40 // from manage_data // EffectDataRemoved occurs when an account removes a data field EffectDataRemoved EffectType = 41 // from manage_data // EffectDataUpdated occurs when an account changes a data field's value EffectDataUpdated EffectType = 42 // from manage_data // EffectSequenceBumped occurs when an account bumps their sequence number EffectSequenceBumped EffectType = 43 // from bump_sequence )
type EffectsQ ¶
type EffectsQ struct { Err error // contains filtered or unexported fields }
EffectsQ is a helper struct to aid in configuring queries that loads slices of Ledger structs.
func (*EffectsQ) ForAccount ¶
ForAccount filters the operations collection to a specific account
func (*EffectsQ) ForLedger ¶
ForLedger filters the query to only effects in a specific ledger, specified by its sequence.
func (*EffectsQ) ForOperation ¶
ForOperation filters the query to only effects in a specific operation, specified by its id.
func (*EffectsQ) ForOrderBook ¶
ForOrderBook filters the query to only effects whose details indicate that the effect is for a specific asset pair.
func (*EffectsQ) ForTransaction ¶
ForTransaction filters the query to only effects in a specific transaction, specified by the transactions's hex-encoded hash.
func (*EffectsQ) OfType ¶
func (q *EffectsQ) OfType(typ EffectType) *EffectsQ
OfType filters the query to only effects of the given type.
type FeeStats ¶
FeeStats is a row of data from the min, mode aggregate functions over the `history_ledgers` table.
type LatestLedger ¶
LatestLedger represents a response from the raw LatestLedgerBaseFeeAndSequence query.
type Ledger ¶
type Ledger struct { TotalOrderID Sequence int32 `db:"sequence"` ImporterVersion int32 `db:"importer_version"` LedgerHash string `db:"ledger_hash"` PreviousLedgerHash null.String `db:"previous_ledger_hash"` TransactionCount int32 `db:"transaction_count"` OperationCount int32 `db:"operation_count"` ClosedAt time.Time `db:"closed_at"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` TotalCoins int64 `db:"total_coins"` FeePool int64 `db:"fee_pool"` BaseFee int32 `db:"base_fee"` BaseReserve int32 `db:"base_reserve"` MaxTxSetSize int32 `db:"max_tx_set_size"` ProtocolVersion int32 `db:"protocol_version"` LedgerHeaderXDR null.String `db:"ledger_header"` }
Ledger is a row of data from the `history_ledgers` table
type LedgerCache ¶
LedgerCache is a helper struct to load ledger data related to a batch of sequences.
func (*LedgerCache) Load ¶
func (lc *LedgerCache) Load(q *Q) error
Load loads a batch of ledgers identified by `sequences`, using `q`, and populates the cache with the results
func (*LedgerCache) Queue ¶
func (lc *LedgerCache) Queue(seq int32)
Queue adds `seq` to the load queue for the cache.
type LedgersQ ¶
type LedgersQ struct { Err error // contains filtered or unexported fields }
LedgersQ is a helper struct to aid in configuring queries that loads slices of Ledger structs.
type OfferIDType ¶
type OfferIDType uint64
const ( CoreOfferIDType OfferIDType = 0 TOIDType OfferIDType = 1 )
func DecodeOfferID ¶
func DecodeOfferID(encodedId int64) (uint64, OfferIDType)
DecodeOfferID performs the reverse operation of EncodeOfferID
type Operation ¶
type Operation struct { TotalOrderID TransactionID int64 `db:"transaction_id"` TransactionHash string `db:"transaction_hash"` ApplicationOrder int32 `db:"application_order"` Type xdr.OperationType `db:"type"` DetailsString null.String `db:"details"` SourceAccount string `db:"source_account"` }
Operation is a row of data from the `history_operations` table
func (*Operation) LedgerSequence ¶
LedgerSequence return the ledger in which the effect occurred.
func (*Operation) UnmarshalDetails ¶
UnmarshalDetails unmarshals the details of this operation into `dest`
type OperationsQ ¶
type OperationsQ struct { Err error // contains filtered or unexported fields }
OperationsQ is a helper struct to aid in configuring queries that loads slices of Operation structs.
func (*OperationsQ) ForAccount ¶
func (q *OperationsQ) ForAccount(aid string) *OperationsQ
ForAccount filters the operations collection to a specific account
func (*OperationsQ) ForLedger ¶
func (q *OperationsQ) ForLedger(seq int32) *OperationsQ
ForLedger filters the query to a only operations in a specific ledger, specified by its sequence.
func (*OperationsQ) ForTransaction ¶
func (q *OperationsQ) ForTransaction(hash string) *OperationsQ
ForTransaction filters the query to a only operations in a specific transaction, specified by the transactions's hex-encoded hash.
func (*OperationsQ) OnlyPayments ¶
func (q *OperationsQ) OnlyPayments() *OperationsQ
OnlyPayments filters the query being built to only include operations that are in the "payment" class of operations: CreateAccountOps, Payments, and PathPayments.
func (*OperationsQ) Page ¶
func (q *OperationsQ) Page(page db2.PageQuery) *OperationsQ
Page specifies the paging constraints for the query being built by `q`.
func (*OperationsQ) Select ¶
func (q *OperationsQ) Select(dest interface{}) error
Select loads the results of the query specified by `q` into `dest`.
type Q ¶
Q is a helper struct on which to hang common_trades queries against a history portion of the horizon database.
func (*Q) AccountByAddress ¶
AccountByAddress loads a row from `history_accounts`, by address
func (*Q) AccountByID ¶
AccountByID loads a row from `history_accounts`, by id
func (*Q) Accounts ¶
Accounts provides a helper to filter rows from the `history_accounts` table with pre-defined filters. See `AccountsQ` methods for the available filters.
func (*Q) AccountsByAddresses ¶
AccountsByAddresses loads a rows from `history_accounts`, by addresses
func (*Q) CreateAccounts ¶
CreateAccounts creates rows for addresses in history_accounts table and put
func (*Q) Effects ¶
Effects provides a helper to filter rows from the `history_effects` table with pre-defined filters. See `TransactionsQ` methods for the available filters.
func (*Q) ElderLedger ¶
ElderLedger loads the oldest ledger known to the history database
func (*Q) GetAssetByID ¶
func (*Q) GetAssetID ¶
GetAssetID fetches the id for an Asset. If fetching multiple values, look at GetAssetIDs
func (*Q) GetAssetIDs ¶
GetAssetIDs fetches the ids for many Assets at once
func (*Q) GetCreateAccountID ¶
Return id for account. If account doesn't exist, it will be created and the new id returned.
func (*Q) GetCreateAssetID ¶
Get asset row id. If asset is first seen, it will be inserted and the new id returned.
func (Q) GetTradeAggregationsQ ¶
func (q Q) GetTradeAggregationsQ(baseAssetID int64, counterAssetID int64, resolution int64, offset int64, pagingParams db2.PageQuery) (*TradeAggregationsQ, error)
GetTradeAggregationsQ initializes a TradeAggregationsQ query builder based on the required parameters
func (*Q) InsertTrade ¶
func (q *Q) InsertTrade( opid int64, order int32, buyer xdr.AccountId, buyOfferExists bool, buyOffer xdr.OfferEntry, trade xdr.ClaimOfferAtom, sellPrice xdr.Price, ledgerClosedAt time.Millis, ) error
Trade records a trade into the history_trades table
func (*Q) LatestLedger ¶
LatestLedger loads the latest known ledger
func (*Q) LatestLedgerBaseFeeAndSequence ¶
LatestLedgerBaseFeeAndSequence loads the latest known ledger's base fee and sequence number.
func (*Q) LedgerBySequence ¶
LedgerBySequence loads the single ledger at `seq` into `dest`
func (*Q) Ledgers ¶
Ledgers provides a helper to filter rows from the `history_ledgers` table with pre-defined filters. See `LedgersQ` methods for the available filters.
func (*Q) LedgersBySequence ¶
LedgersBySequence loads the a set of ledgers identified by the sequences `seqs` into `dest`.
func (*Q) OldestOutdatedLedgers ¶
OldestOutdatedLedgers populates a slice of ints with the first million outdated ledgers, based upon the provided `currentVersion` number
func (*Q) OperationByID ¶
OperationByID loads a single operation with `id` into `dest`
func (*Q) Operations ¶
func (q *Q) Operations() *OperationsQ
Operations provides a helper to filter the operations table with pre-defined filters. See `OperationsQ` for the available filters.
func (*Q) ReverseTrades ¶
ReverseTrades provides a helper to filter rows from the `history_trades` table with pre-defined filters and reversed base/counter. See `TradesQ` methods for the available filters.
func (*Q) Trades ¶
Trades provides a helper to filter rows from the `history_trades` table with pre-defined filters. See `TradesQ` methods for the available filters.
func (*Q) TradesForAssetPair ¶
TradesForAssetPair provides a helper to filter rows from the `history_trades` table with the base filter of a specific asset pair. See `TradesQ` methods for further available filters.
func (*Q) TransactionByHash ¶
TransactionByHash is a query that loads a single row from the `history_transactions` table based upon the provided hash.
func (*Q) Transactions ¶
func (q *Q) Transactions() *TransactionsQ
Transactions provides a helper to filter rows from the `history_transactions` table with pre-defined filters. See `TransactionsQ` methods for the available filters.
func (*Q) TransactionsForLastXLedgers ¶
TransactionsForLastXLedgers filters the query to only the last X ledgers worth of transactions. Currently, we hard code the query to return the last 5 ledgers worth of transactions. In the future this may be configurable.
type TotalOrderID ¶
type TotalOrderID struct {
ID int64 `db:"id"`
}
TotalOrderID represents the ID portion of rows that are identified by the "TotalOrderID". See total_order_id.go in the `db` package for details.
func (*TotalOrderID) PagingToken ¶
func (r *TotalOrderID) PagingToken() string
PagingToken returns a cursor for this record
type Trade ¶
type Trade struct { HistoryOperationID int64 `db:"history_operation_id"` Order int32 `db:"order"` LedgerCloseTime time.Time `db:"ledger_closed_at"` OfferID int64 `db:"offer_id"` BaseOfferID *int64 `db:"base_offer_id"` BaseAccount string `db:"base_account"` BaseAssetType string `db:"base_asset_type"` BaseAssetCode string `db:"base_asset_code"` BaseAssetIssuer string `db:"base_asset_issuer"` BaseAmount xdr.Int64 `db:"base_amount"` CounterOfferID *int64 `db:"counter_offer_id"` CounterAccount string `db:"counter_account"` CounterAssetType string `db:"counter_asset_type"` CounterAssetCode string `db:"counter_asset_code"` CounterAssetIssuer string `db:"counter_asset_issuer"` CounterAmount xdr.Int64 `db:"counter_amount"` BaseIsSeller bool `db:"base_is_seller"` PriceN null.Int `db:"price_n"` PriceD null.Int `db:"price_d"` }
Trade represents a trade from the trades table, joined with asset information from the assets table and account addresses from the accounts table
func (*Trade) PagingToken ¶
PagingToken returns a cursor for this trade
type TradeAggregation ¶
type TradeAggregation struct { Timestamp int64 `db:"timestamp"` TradeCount int64 `db:"count"` BaseVolume int64 `db:"base_volume"` CounterVolume int64 `db:"counter_volume"` Average float64 `db:"avg"` High xdr.Price `db:"high"` Low xdr.Price `db:"low"` Open xdr.Price `db:"open"` Close xdr.Price `db:"close"` }
TradeAggregation represents an aggregation of trades from the trades table
type TradeAggregationsQ ¶
type TradeAggregationsQ struct {
// contains filtered or unexported fields
}
TradeAggregationsQ is a helper struct to aid in configuring queries to bucket and aggregate trades
func (*TradeAggregationsQ) GetSql ¶
func (q *TradeAggregationsQ) GetSql() sq.SelectBuilder
GetSql generates a sql statement to aggregate Trades based on given parameters
func (*TradeAggregationsQ) WithEndTime ¶
func (q *TradeAggregationsQ) WithEndTime(endTime strtime.Millis) (*TradeAggregationsQ, error)
WithEndTime adds an upper optional time boundary filter to the trades being aggregated.
func (*TradeAggregationsQ) WithStartTime ¶
func (q *TradeAggregationsQ) WithStartTime(startTime strtime.Millis) (*TradeAggregationsQ, error)
WithStartTime adds an optional lower time boundary filter to the trades being aggregated.
type TradesQ ¶
type TradesQ struct { Err error // contains filtered or unexported fields }
TradesQ is a helper struct to aid in configuring queries that loads slices of trade structs.
func (*TradesQ) ForAccount ¶
filter Trades by account id
func (*TradesQ) JoinAccounts ¶
func (*TradesQ) JoinAssets ¶
type Transaction ¶
type Transaction struct { TotalOrderID TransactionHash string `db:"transaction_hash"` LedgerSequence int32 `db:"ledger_sequence"` LedgerCloseTime time.Time `db:"ledger_close_time"` ApplicationOrder int32 `db:"application_order"` Account string `db:"account"` AccountSequence string `db:"account_sequence"` FeePaid int32 `db:"fee_paid"` OperationCount int32 `db:"operation_count"` TxEnvelope string `db:"tx_envelope"` TxResult string `db:"tx_result"` TxMeta string `db:"tx_meta"` TxFeeMeta string `db:"tx_fee_meta"` SignatureString string `db:"signatures"` MemoType string `db:"memo_type"` Memo null.String `db:"memo"` ValidAfter null.Int `db:"valid_after"` ValidBefore null.Int `db:"valid_before"` CreatedAt time.Time `db:"created_at"` UpdatedAt time.Time `db:"updated_at"` }
Transaction is a row of data from the `history_transactions` table
type TransactionsQ ¶
type TransactionsQ struct { Err error // contains filtered or unexported fields }
TransactionsQ is a helper struct to aid in configuring queries that loads slices of transaction structs.
func (*TransactionsQ) ForAccount ¶
func (q *TransactionsQ) ForAccount(aid string) *TransactionsQ
ForAccount filters the transactions collection to a specific account
func (*TransactionsQ) ForLedger ¶
func (q *TransactionsQ) ForLedger(seq int32) *TransactionsQ
ForLedger filters the query to a only transactions in a specific ledger, specified by its sequence.
func (*TransactionsQ) Page ¶
func (q *TransactionsQ) Page(page db2.PageQuery) *TransactionsQ
Page specifies the paging constraints for the query being built by `q`.
func (*TransactionsQ) Select ¶
func (q *TransactionsQ) Select(dest interface{}) error
Select loads the results of the query specified by `q` into `dest`.