db

package
v0.0.0-...-0ab412c Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CmdDBHost = "postgres-host"
View Source
const CmdDBName = "postgres-db"
View Source
const CmdDBPassword = "postgres-pwd"
View Source
const CmdDBPoolMax = "postgres-pool-max"
View Source
const CmdDBPoolMin = "postgres-pool-min"
View Source
const CmdDBPort = "postgres-port"
View Source
const CmdDBUser = "postgres-user"
View Source
const DefaultDBHost = "localhost"
View Source
const DefaultDBName = "postgres"
View Source
const DefaultDBPassword = "password"
View Source
const DefaultDBPoolMax = 32
View Source
const DefaultDBPoolMin = 4
View Source
const DefaultDBPort = "5432"
View Source
const DefaultDBUser = "postgres"
View Source
const MAX_LIMIT = 100
View Source
const META_BLOCK_HEIGHT = "latest_block_height"
View Source
const META_BLOCK_TIME_EPOCH_NS = "latest_block_time_epoch_ns"
View Source
const META_EXTRACTOR = "extractor_v1"
View Source
const NoTimeZoneTimeLayout = "2006-01-02T15:04:05"

Variables

View Source
var (
	MainAddressPrefix = "like"
	AddressPrefixes   = []string{MainAddressPrefix, "cosmos"}
)
View Source
var LIMIT = int64(utils.EnvInt("EXTRACTOR_LIMIT", 10000))

Functions

func AcquireFromPool

func AcquireFromPool(pool *pgxpool.Pool) (*pgxpool.Conn, error)

func ConfigCmd

func ConfigCmd(cmd *cobra.Command)

func Extract

func Extract(conn *pgxpool.Conn, extractor Extractor) (finished bool, err error)

func GetConnPoolFromCmdArgs

func GetConnPoolFromCmdArgs(cmd *cobra.Command) (*pgxpool.Pool, error)

func GetLatestBlockTime

func GetLatestBlockTime(conn *pgxpool.Conn) (time.Time, error)

func GetLatestHeight

func GetLatestHeight(conn *pgxpool.Conn) (int64, error)

func GetMetaHeight

func GetMetaHeight(conn *pgxpool.Conn, key string) (int64, error)

func GetTimeoutContext

func GetTimeoutContext() (context.Context, context.CancelFunc)

func NewConnPool

func NewConnPool(dbname string, host string, port string, user string, pwd string, poolMin int, poolMax int) (pool *pgxpool.Pool, err error)

func QueryCount

func QueryCount(conn *pgxpool.Conn, events types.StringEvents, height uint64) (uint64, error)

func QueryTxs

func QueryTxs(conn *pgxpool.Conn, events types.StringEvents, height uint64, p PageRequest) ([]byte, []*types.TxResponse, error)

Types

type Batch

type Batch struct {
	Conn  *pgxpool.Conn
	Batch pgx.Batch
	// contains filtered or unexported fields
}

func NewBatch

func NewBatch(conn *pgxpool.Conn, limit int) Batch

func (*Batch) DeleteNFTMarketplaceItem

func (batch *Batch) DeleteNFTMarketplaceItem(item NftMarketplaceItem)

func (*Batch) DeleteNFTMarketplaceItemSilently

func (batch *Batch) DeleteNFTMarketplaceItemSilently(item NftMarketplaceItem)

func (*Batch) Flush

func (batch *Batch) Flush() error

func (*Batch) InsertIscn

func (batch *Batch) InsertIscn(insert IscnInsert)

func (*Batch) InsertNFTMarketplaceItem

func (batch *Batch) InsertNFTMarketplaceItem(item NftMarketplaceItem)

func (*Batch) InsertNft

func (batch *Batch) InsertNft(n Nft)

func (*Batch) InsertNftClass

func (batch *Batch) InsertNftClass(c NftClass)

func (*Batch) InsertNftEvent

func (batch *Batch) InsertNftEvent(e NftEvent)

func (*Batch) InsertNftIncome

func (batch *Batch) InsertNftIncome(income NftIncome)

func (*Batch) InsertTx

func (batch *Batch) InsertTx(txRes types.TxResponse, height int64, txIndex int) error

func (*Batch) UpdateLatestBlockHeight

func (batch *Batch) UpdateLatestBlockHeight(height int64)

func (*Batch) UpdateLatestBlockTime

func (batch *Batch) UpdateLatestBlockTime(timeStr string) error

func (*Batch) UpdateMetaHeight

func (batch *Batch) UpdateMetaHeight(key string, height int64)

func (*Batch) UpdateNftClass

func (batch *Batch) UpdateNftClass(c NftClass)

type CollectedClass

type CollectedClass struct {
	ClassId string `json:"class_id"`
	Count   int    `json:"count"`
}

type CollectorTopRankedCreator

type CollectorTopRankedCreator struct {
	Creator string `json:"creator"`
	Rank    uint   `json:"rank"`
}

type Entity

type Entity struct {
	Id   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

func (*Entity) UnmarshalJSON

func (e *Entity) UnmarshalJSON(data []byte) (err error)

type EventContext

type EventContext struct {
	Batch      *Batch
	Messages   []json.RawMessage
	EventsList EventsList
	Timestamp  time.Time
	TxHash     string
	Memo       string

	// If the event is from authz, we process it by making a psuedo EventContext
	// for each authz message, and then set this field to the original EventContext
	AuthzParent *EventContext
}

type EventsList

type EventsList []struct {
	Events types.StringEvents `json:"events"`
}

type Extractor

type Extractor func(ctx EventContext) error

type IscnInsert

type IscnInsert struct {
	Iscn         string
	IscnPrefix   string
	Version      int
	Owner        string
	Timestamp    time.Time
	Ipld         string
	Name         string
	Description  string
	Url          string
	Keywords     []string
	Fingerprints []string
	Stakeholders []Stakeholder
	Data         []byte
}

type IscnQuery

type IscnQuery struct {
	SearchTerm      string   `form:"q"`
	IscnId          string   `form:"iscn_id"`
	IscnIdPrefix    string   `form:"iscn_id_prefix"`
	Owner           string   `form:"owner"`
	Keywords        []string `form:"keyword"`
	Fingerprints    []string `form:"fingerprint"`
	StakeholderId   string   `form:"stakeholder.id"`
	StakeholderName string   `form:"stakeholder.name"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
}

func (IscnQuery) Empty

func (q IscnQuery) Empty() bool

type IscnResponse

type IscnResponse struct {
	Records    []iscnResponseRecord `json:"records"`
	Pagination PageResponse         `json:"pagination"`
}

func QueryIscn

func QueryIscn(conn *pgxpool.Conn, query IscnQuery, page PageRequest) (IscnResponse, error)

func QueryIscnList

func QueryIscnList(conn *pgxpool.Conn, pagination PageRequest, allIscnVersions bool) (IscnResponse, error)

func QueryIscnSearch

func QueryIscnSearch(conn *pgxpool.Conn, term string, pagination PageRequest, allIscnVersions bool) (IscnResponse, error)

type LegacyPageRequest

type LegacyPageRequest struct {
	Key     uint64 `form:"key"`
	Limit   int    `form:"limit,default=100" binding:"gte=1,lte=100"`
	Reverse bool   `form:"reverse"`
	Offset  uint64 `form:"offset"`
}

type Nft

type Nft struct {
	NftId          string          `json:"nft_id"`
	ClassId        string          `json:"class_id"`
	Owner          string          `json:"owner"`
	Uri            string          `json:"uri"`
	UriHash        string          `json:"uri_hash"`
	Metadata       json.RawMessage `json:"metadata"`
	Timestamp      time.Time       `json:"timestamp"`
	LatestPrice    uint64          `json:"latest_price,omitempty"`
	PriceUpdatedAt *NoTimeZoneTime `json:"price_updated_at,omitempty"`
}

type NftClass

type NftClass struct {
	Id             string          `json:"id"`
	Name           string          `json:"name"`
	Description    string          `json:"description"`
	Symbol         string          `json:"symbol"`
	URI            string          `json:"uri"`
	URIHash        string          `json:"uri_hash"`
	Config         json.RawMessage `json:"config"`
	Metadata       json.RawMessage `json:"metadata"`
	Parent         NftClassParent  `json:"parent"`
	CreatedAt      time.Time       `json:"created_at"`
	LatestPrice    uint64          `json:"latest_price,omitempty"`
	PriceUpdatedAt *time.Time      `json:"price_updated_at,omitempty"`
}

type NftClassIncomeResponse

type NftClassIncomeResponse struct {
	ClassId     string              `json:"class_id"`
	CreatedAt   time.Time           `json:"created_at"`
	Sales       uint64              `json:"sales"`
	TotalAmount uint64              `json:"total_amount"`
	Incomes     []NftIncomeResponse `json:"incomes"`
}

type NftClassParent

type NftClassParent struct {
	Type         string `json:"type"`
	IscnIdPrefix string `json:"iscn_id_prefix"`
	Account      string `json:"account"`
}

type NftClassRankingResponse

type NftClassRankingResponse struct {
	NftClass
	Owner          string `json:"owner"`
	SoldCount      int    `json:"sold_count"`
	TotalSoldValue int64  `json:"total_sold_value"`
}

type NftClassResponse

type NftClassResponse struct {
	NftClass
	Owner          string     `json:"owner"`
	NftOwnedCount  *int       `json:"nft_owned_count,omitempty"`
	NftLastOwnedAt *time.Time `json:"nft_last_owned_at,omitempty"`
	LastOwnedNftId *string    `json:"last_owned_nft_id,omitempty"`
}

type NftEvent

type NftEvent struct {
	Action    NftEventAction     `json:"action"`
	ClassId   string             `json:"class_id"`
	NftId     string             `json:"nft_id"`
	Sender    string             `json:"sender"`
	Receiver  string             `json:"receiver"`
	Events    types.StringEvents `json:"events,omitempty"`
	TxHash    string             `json:"tx_hash"`
	Timestamp time.Time          `json:"timestamp"`
	Memo      string             `json:"memo"`
	Price     uint64             `json:"price,omitempty"`
}

type NftEventAction

type NftEventAction string
const (
	ACTION_SEND         NftEventAction = "/cosmos.nft.v1beta1.MsgSend"
	ACTION_MINT         NftEventAction = "mint_nft"
	ACTION_NEW_CLASS    NftEventAction = "new_class"
	ACTION_UPDATE_CLASS NftEventAction = "update_class"
	ACTION_BUY          NftEventAction = "buy_nft"
	ACTION_SELL         NftEventAction = "sell_nft"
)

type NftIncome

type NftIncome struct {
	ClassId   string `json:"class_id"`
	NftId     string `json:"nft_id"`
	TxHash    string `json:"tx_hash"`
	Address   string `json:"address"`
	Amount    uint64 `json:"amount"`
	IsRoyalty bool   `json:"is_royalty"`
}

type NftIncomeResponse

type NftIncomeResponse struct {
	Address   string `json:"address"`
	Amount    uint64 `json:"amount"`
	IsRoyalty bool   `json:"is_royalty"`
}

type NftMarketplaceItem

type NftMarketplaceItem struct {
	Type       string    `json:"action,omitempty"`
	ClassId    string    `json:"class_id"`
	NftId      string    `json:"nft_id"`
	Creator    string    `json:"creator"`
	Price      uint64    `json:"price,omitempty"`
	Expiration time.Time `json:"expiration,omitempty"`
}

type NftMarketplaceItemResponse

type NftMarketplaceItemResponse struct {
	NftMarketplaceItem
	ClassMetadata json.RawMessage `json:"class_metadata"`
	NftMetadata   json.RawMessage `json:"nft_metadata"`
}

type NftResponse

type NftResponse struct {
	Nft
	ClassParent NftClassParent `json:"class_parent"`
	ClassData   *NftClass      `json:"class_data,omitempty"`
}

type NftReturningCreatorCountResponse

type NftReturningCreatorCountResponse struct {
	StartAt               time.Time `json:"start_at"`
	NewCreatorCount       uint64    `json:"new_creator_count"`
	ReturningCreatorCount uint64    `json:"returning_creator_count"`
}

type NoTimeZoneTime

type NoTimeZoneTime struct {
	time.Time
}

func (*NoTimeZoneTime) UnmarshalJSON

func (ntzt *NoTimeZoneTime) UnmarshalJSON(b []byte) error

type Order

type Order string
const (
	ORDER_ASC  Order = "ASC"
	ORDER_DESC Order = "DESC"
)

type OwnerResponse

type OwnerResponse struct {
	Owner string   `json:"owner"`
	Count int      `json:"count,omitempty"`
	Nfts  []string `json:"nfts,omitempty"`
}

type PageRequest

type PageRequest struct {
	Key     uint64 `form:"pagination.key"`
	Limit   int    `form:"pagination.limit,default=100" binding:"gte=1,lte=100"`
	Reverse bool   `form:"pagination.reverse"`
	Offset  uint64 `form:"pagination.offset"`
}

func (*PageRequest) After

func (p *PageRequest) After() uint64

func (*PageRequest) Before

func (p *PageRequest) Before() uint64

func (*PageRequest) Order

func (p *PageRequest) Order() Order

type PageResponse

type PageResponse struct {
	NextKey uint64 `json:"next_key,omitempty"`
	Count   int    `json:"count,omitempty"`
	Total   int    `json:"total,omitempty"`
}

type QueryClassRequest

type QueryClassRequest struct {
	IscnIdPrefix    string   `form:"iscn_id_prefix"`
	Account         string   `form:"account"`
	IscnOwner       []string `form:"iscn_owner"`
	Owner           string   `form:"owner"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
}

type QueryClassResponse

type QueryClassResponse struct {
	Classes    []NftClassResponse `json:"classes"`
	Pagination PageResponse       `json:"pagination"`
}

type QueryClassesOwnersRequest

type QueryClassesOwnersRequest struct {
	ClassIds []string `form:"class_ids" binding:"required"`
	Owners   []string `form:"owners"`
}

type QueryClassesOwnersResponse

type QueryClassesOwnersResponse struct {
	// key: owner address, value: class IDs
	Owners map[string][]string `json:"owners"`
}

type QueryCollectorRequest

type QueryCollectorRequest struct {
	Creator         string   `form:"creator"`
	IgnoreList      []string `form:"ignore_list"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
	IncludeOwner    bool     `form:"include_owner,default=true"`
	PriceBy         string   `form:"price_by,default=nft"`
	OrderBy         string   `form:"order_by,default=price"`
}

type QueryCollectorResponse

type QueryCollectorResponse struct {
	Collectors []accountCollection `json:"collectors"`
	Pagination PageResponse        `json:"pagination"`
}

func GetCollector

func GetCollector(conn *pgxpool.Conn, q QueryCollectorRequest, p PageRequest) (res QueryCollectorResponse, err error)

type QueryCollectorTopRankedCreatorsRequest

type QueryCollectorTopRankedCreatorsRequest struct {
	Collector       string   `form:"collector" binding:"required"`
	IgnoreList      []string `form:"ignore_list"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
	IncludeOwner    bool     `form:"include_owner,default=true"`
	Top             uint     `form:"top,default=5"`
}

type QueryCollectorTopRankedCreatorsResponse

type QueryCollectorTopRankedCreatorsResponse struct {
	Creators []CollectorTopRankedCreator `json:"creators"`
}

type QueryCountResponse

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

func GetISCNOwnerCount

func GetISCNOwnerCount(conn *pgxpool.Conn) (count QueryCountResponse, err error)

func GetISCNRecordCount

func GetISCNRecordCount(conn *pgxpool.Conn) (count QueryCountResponse, err error)

func GetNftCount

func GetNftCount(conn *pgxpool.Conn, q QueryNftCountRequest) (count QueryCountResponse, err error)

func GetNftCreatorCount

func GetNftCreatorCount(conn *pgxpool.Conn) (count QueryCountResponse, err error)

func GetNftOwnerCount

func GetNftOwnerCount(conn *pgxpool.Conn) (count QueryCountResponse, err error)

type QueryCreatorRequest

type QueryCreatorRequest struct {
	Collector       string   `form:"collector"`
	IgnoreList      []string `form:"ignore_list"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
	IncludeOwner    bool     `form:"include_owner,default=true"`
	PriceBy         string   `form:"price_by,default=nft"`
	OrderBy         string   `form:"order_by,default=price"`
}

type QueryCreatorResponse

type QueryCreatorResponse struct {
	Creators   []accountCollection `json:"creators"`
	Pagination PageResponse        `json:"pagination"`
}

func GetCreators

func GetCreators(conn *pgxpool.Conn, q QueryCreatorRequest, p PageRequest) (res QueryCreatorResponse, err error)

type QueryEventsRequest

type QueryEventsRequest struct {
	ClassId        string           `form:"class_id"`
	NftId          string           `form:"nft_id"`
	IscnIdPrefix   string           `form:"iscn_id_prefix"`
	Sender         []string         `form:"sender"`
	Receiver       []string         `form:"receiver"`
	Creator        []string         `form:"creator"`
	Involver       []string         `form:"involver"`
	Verbose        bool             `form:"verbose"`
	ActionType     []NftEventAction `form:"action_type"`
	IgnoreFromList []string         `form:"ignore_from_list"`
	IgnoreToList   []string         `form:"ignore_to_list"`
}

type QueryEventsResponse

type QueryEventsResponse struct {
	Pagination PageResponse `json:"pagination"`
	Events     []NftEvent   `json:"events"`
}

type QueryIncomesRequest

type QueryIncomesRequest struct {
	ClassId             string           `form:"class_id"`
	Owner               string           `form:"owner"`
	Address             string           `form:"address"`
	After               int64            `form:"after"`
	Before              int64            `form:"before"`
	ActionType          []NftEventAction `form:"action_type"`
	IsIscnOwner         *bool            `form:"is_iscn_owner"`
	IsRoyalty           *bool            `form:"is_royalty"`
	ExcludeSelfPurchase bool             `form:"exclude_self_purchase"`
	OrderBy             string           `form:"order_by"`
}

type QueryIncomesResponse

type QueryIncomesResponse struct {
	TotalSales   uint64                   `json:"total_sales"`
	TotalAmount  uint64                   `json:"total_amount"`
	ClassIncomes []NftClassIncomeResponse `json:"class_incomes"`
	Pagination   PageResponse             `json:"pagination"`
}

type QueryNftCountRequest

type QueryNftCountRequest struct {
	IncludeOwner bool     `form:"include_owner"`
	IgnoreList   []string `form:"ignore_list"`
}

type QueryNftMarketplaceItemsRequest

type QueryNftMarketplaceItemsRequest struct {
	Type    string `form:"type"`
	ClassId string `form:"class_id"`
	NftId   string `form:"nft_id"`
	Creator string `form:"creator"`
	Expand  bool   `form:"expand"`
}

type QueryNftMarketplaceItemsResponse

type QueryNftMarketplaceItemsResponse struct {
	Items      []NftMarketplaceItemResponse `json:"items"`
	Pagination PageResponse                 `json:"pagination"`
}

type QueryNftOwnerListResponse

type QueryNftOwnerListResponse struct {
	Owners     []OwnerResponse `json:"owners"`
	Pagination PageResponse    `json:"pagination"`
}

func GetNftOwnerList

func GetNftOwnerList(conn *pgxpool.Conn, p PageRequest) (res QueryNftOwnerListResponse, err error)

type QueryNftRequest

type QueryNftRequest struct {
	Owner         string `form:"owner" binding:"required"`
	ExpandClasses bool   `form:"expand_classes"`
}

type QueryNftResponse

type QueryNftResponse struct {
	Pagination PageResponse  `json:"pagination"`
	Nfts       []NftResponse `json:"nfts"`
}

type QueryNftReturningCreatorCountRequest

type QueryNftReturningCreatorCountRequest struct {
	ReturningThresholdDays int    `form:"returning_threshold_days"`
	Interval               string `form:"interval"`
	After                  int64  `form:"after"`
	Before                 int64  `form:"before"`
}

type QueryNftReturningCreatorCountResponse

type QueryNftReturningCreatorCountResponse struct {
	Intervals []NftReturningCreatorCountResponse `json:"intervals"`
}

type QueryNftTradeStatsRequest

type QueryNftTradeStatsRequest struct {
}

type QueryNftTradeStatsResponse

type QueryNftTradeStatsResponse struct {
	Count       uint64 `json:"count"`
	TotalVolume uint64 `json:"total_volume"`
}

type QueryOwnerRequest

type QueryOwnerRequest struct {
	ClassId          string   `form:"class_id" binding:"required"`
	ExcludeIscnOwner bool     `form:"exclude_iscn_owner"`
	IgnoreList       []string `form:"ignore_list"`
}

type QueryOwnerResponse

type QueryOwnerResponse struct {
	Pagination PageResponse    `json:"pagination"`
	Owners     []OwnerResponse `json:"owners"`
}

type QueryRankingRequest

type QueryRankingRequest struct {
	StakeholderId   string   `form:"stakeholder_id"`
	StakeholderName string   `form:"stakeholder_name"`
	Creator         string   `form:"creator"`
	Type            string   `form:"type"`
	Collector       string   `form:"collector"`
	CreatedAfter    int64    `form:"created_after"`
	CreatedBefore   int64    `form:"created_before"`
	IncludeOwner    bool     `form:"include_owner"`
	IgnoreList      []string `form:"ignore_list"`
	ApiAddresses    []string `form:"api_addresses"`
	After           int64    `form:"after"`
	Before          int64    `form:"before"`
	OrderBy         string   `form:"order_by"`
}

type QueryRankingResponse

type QueryRankingResponse struct {
	Classes    []NftClassRankingResponse `json:"classes"`
	Pagination PageResponse              `json:"pagination"`
}

type QueryUserStatRequest

type QueryUserStatRequest struct {
	User            string   `form:"user"`
	IgnoreList      []string `form:"ignore_list"`
	AllIscnVersions bool     `form:"all_iscn_versions"`
}

type QueryUserStatResponse

type QueryUserStatResponse struct {
	CollectedClasses []CollectedClass `json:"collected_classes"`
	CreatedCount     int              `json:"created_count"`
	CollectorCount   int              `json:"collector_count"`
	TotalSales       uint64           `json:"total_sales"`
	TotalIncomes     uint64           `json:"total_incomes"`
}

func GetUserStat

func GetUserStat(conn *pgxpool.Conn, q QueryUserStatRequest) (res QueryUserStatResponse, err error)

type Stakeholder

type Stakeholder struct {
	Entity Entity `json:"entity,omitempty"`
	Data   []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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