pgdb

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: ISC Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MigrateUp causes migrations to be run in the "up" direction.
	MigrateUp = "up"
	// MigrateDown causes migrations to be run in the "down" direction.
	MigrateDown = "down"
)
View Source
const (
	DBVersion = "v1"
)

Variables

This section is empty.

Functions

func CreateSchema

func CreateSchema(db *bun.DB, chainName string) error

func CreateSchemaForIngester

func CreateSchemaForIngester(db *sql.DB) error

func DoTx

func DoTx(db *bun.DB, action func(dbTx *bun.Tx) error) error

func DropAllSchemas

func DropAllSchemas(db *bun.DB) error

func DropChainSchema

func DropChainSchema(db *bun.DB, chain uint32) error

func InitDatabaseForChain

func InitDatabaseForChain(dsn, chain string, migrate bool) (*bun.DB, error)

func Migrate

func Migrate(db *sql.DB, direction string) (int, error)

func MigrateSet

func MigrateSet(db *sql.DB, direction string, set ...Migrations) (int, error)

func MigrateSetDown

func MigrateSetDown(db *sql.DB, set ...Migrations) (int, error)

func MigrateSetUp

func MigrateSetUp(db *sql.DB, set ...Migrations) (int, error)

func NewAssetSource

func NewAssetSource(fs *embed.FS, rootDirectory string) migrate.MigrationSource

func NewConn

func NewConn(dsn string, chainName string) (*bun.DB, error)

func TransformSchemaAfterIngester

func TransformSchemaAfterIngester(db *sql.DB) error

Types

type Address

type Address struct {
	bun.BaseModel `bun:"table:addresses,alias:a"`
	PKScript      string `bun:"pk_script"`
	Address       string `bun:"address"`
}

type BalanceRow

type BalanceRow struct {
	bun.BaseModel `bun:"table:balance_vw,alias:bav" json:"-"`
	Balance       int64  `bun:"balance" json:"balance"`
	BalanceLocked int64  `bun:"balance_locked" json:"balanceLocked"`
	Address       string `bun:"address" json:"address"`
}

type BlockBits

type BlockBits struct {
	bun.BaseModel `bun:"table:block_headers,alias:bh"`
	Height        int64 `bun:"height"`
	BlockTime     int64 `bun:"block_time"`
	Bits          int64 `bun:"bits"`
}

type BlockHeaderRow

type BlockHeaderRow struct {
	bun.BaseModel `bun:"table:block_headers,alias:bh"`
	Hash          string `bun:"hash"`
	Orphan        bool   `bun:"orphan"`
	Height        int64  `bun:"height"`
	MMRRoot       string `bun:"mmr_root"`
	PrevBlockHash string `bun:"prev_block_hash"`
	BlockTime     int64  `bun:"block_time"`
	Bits          int64  `bun:"bits"`
	PowHash       string `bun:"pow_hash"`
	BlockSize     int64  `bun:"block_size"`
	HeaderSize    int64  `bun:"header_size"`
}

type BlockHeaderShortRow

type BlockHeaderShortRow struct {
	bun.BaseModel `bun:"table:block_headers,alias:bh"`
	Hash          string `bun:"hash"`
	Height        int64  `bun:"height"`
	Bits          int64  `bun:"bits"`
	BlockTime     int64  `bun:"block_time"`
	BlockSize     int64  `bun:"block_size"`
}

type BlockRow

type BlockRow struct {
	bun.BaseModel `bun:"table:blocks,alias:b"`
	ID            int64  `bun:"id"`
	Orphan        bool   `bun:"orphan"`
	Height        int64  `bun:"height"`
	Hash          string `bun:"hash"`
	PrevBlockHash string `bun:"prev_block_hash"`
	RawHeader     []byte `bun:"raw_header"`
	RawBlock      []byte `bun:"raw_block"`
}

func (*BlockRow) ToWire

func (b *BlockRow) ToWire() (*wire.MsgBlock, error)

type ChainDB

type ChainDB struct {
	ChainName string
	// contains filtered or unexported fields
}

func NewChainDB

func NewChainDB(db bun.IDB, chain string) *ChainDB

func (*ChainDB) DeleteBlocks

func (bt *ChainDB) DeleteBlocks(ctx context.Context, height int64) error

func (*ChainDB) GetAllBlockIDHashesByHeight

func (bt *ChainDB) GetAllBlockIDHashesByHeight(ctx context.Context, height int64) ([]IDHashOrphanRow, error)

func (*ChainDB) GetAllPkScriptsByAddress

func (bt *ChainDB) GetAllPkScriptsByAddress(ctx context.Context, address string) ([]string, error)

func (*ChainDB) GetBalance

func (bt *ChainDB) GetBalance(ctx context.Context, address string) (BalanceRow, error)

func (*ChainDB) GetBlockByHash

func (bt *ChainDB) GetBlockByHash(ctx context.Context, hash string) (*BlockRow, error)

func (*ChainDB) GetBlockByID

func (bt *ChainDB) GetBlockByID(ctx context.Context, id int64) (*BlockRow, error)

func (*ChainDB) GetBlockHeaderByHash

func (bt *ChainDB) GetBlockHeaderByHash(ctx context.Context, hash string) (*BlockHeaderRow, error)

func (*ChainDB) GetBlockHeaderByHeight

func (bt *ChainDB) GetBlockHeaderByHeight(ctx context.Context, height int64) (*BlockHeaderRow, error)

func (*ChainDB) GetBlockIDByHash

func (bt *ChainDB) GetBlockIDByHash(ctx context.Context, hash string) (int64, error)

func (*ChainDB) GetBlockIDHashByHeight

func (bt *ChainDB) GetBlockIDHashByHeight(ctx context.Context, height int64) (IDHashRow, error)

func (*ChainDB) GetChainsInfoByID

func (bt *ChainDB) GetChainsInfoByID(ctx context.Context, shardID uint32) (*ChainInfo, error)

func (*ChainDB) GetLastBlockID

func (bt *ChainDB) GetLastBlockID(ctx context.Context) (int64, error)

func (*ChainDB) GetLastTxID

func (bt *ChainDB) GetLastTxID(ctx context.Context) (int64, error)

func (*ChainDB) GetLastTxOutID

func (bt *ChainDB) GetLastTxOutID(ctx context.Context) (int64, error)

func (*ChainDB) GetNetwork

func (bt *ChainDB) GetNetwork(ctx context.Context) (string, error)

func (*ChainDB) GetScriptByAddress

func (bt *ChainDB) GetScriptByAddress(ctx context.Context, address string) (string, error)

func (*ChainDB) GetSwapTxOutsByTxHash

func (bt *ChainDB) GetSwapTxOutsByTxHash(ctx context.Context, hash string) ([]SwapTxOuts, error)

func (*ChainDB) GetTxByHash

func (bt *ChainDB) GetTxByHash(ctx context.Context, hash string) (*TxRow, error)

func (*ChainDB) GetTxIDByHash

func (bt *ChainDB) GetTxIDByHash(ctx context.Context, hash string) (int64, error)

func (*ChainDB) GetTxOutByOutPoint

func (bt *ChainDB) GetTxOutByOutPoint(ctx context.Context, hash string, outN int32) (*TxOutRow, error)

func (*ChainDB) InsertBlock

func (bt *ChainDB) InsertBlock(ctx context.Context, row BlockRow) error

func (*ChainDB) InsertBlockHeader

func (bt *ChainDB) InsertBlockHeader(ctx context.Context, row BlockHeaderRow) error

func (*ChainDB) InsertBlockHeaders

func (bt *ChainDB) InsertBlockHeaders(ctx context.Context, row []BlockHeaderRow) error

func (*ChainDB) InsertChainDBMeta

func (bt *ChainDB) InsertChainDBMeta(ctx context.Context, meta ChainDBMeta) error

func (*ChainDB) InsertChainsInfo

func (bt *ChainDB) InsertChainsInfo(ctx context.Context, chains []ChainInfo) error

func (*ChainDB) InsertExchangeAgent

func (bt *ChainDB) InsertExchangeAgent(ctx context.Context, ead ExchangeAgentRow) error

func (*ChainDB) InsertExchangeAgents

func (bt *ChainDB) InsertExchangeAgents(ctx context.Context, rows []ExchangeAgentRow) error

func (*ChainDB) InsertPkScript

func (bt *ChainDB) InsertPkScript(ctx context.Context, row PkScriptRow) error

func (*ChainDB) InsertSwapTxOut

func (bt *ChainDB) InsertSwapTxOut(ctx context.Context, row SwapTxOuts) error

func (*ChainDB) InsertSwapTxOuts

func (bt *ChainDB) InsertSwapTxOuts(ctx context.Context, rows []SwapTxOuts) error

func (*ChainDB) InsertTx

func (bt *ChainDB) InsertTx(ctx context.Context, row TxRow) error

func (*ChainDB) InsertTxIn

func (bt *ChainDB) InsertTxIn(ctx context.Context, row TxInRow) error

func (*ChainDB) InsertTxOut

func (bt *ChainDB) InsertTxOut(ctx context.Context, row TxOutRow) error

func (*ChainDB) InsertTxStats

func (bt *ChainDB) InsertTxStats(ctx context.Context, row TxStatsRow) error

func (*ChainDB) InsertTxStatsRows

func (bt *ChainDB) InsertTxStatsRows(ctx context.Context, rows []TxStatsRow) error

func (*ChainDB) ListInTxsForPKScript

func (bt *ChainDB) ListInTxsForPKScript(ctx context.Context, script string, limit, offset uint32) ([]TxHashRow, error)

func (*ChainDB) ListOutTxsForPKScript

func (bt *ChainDB) ListOutTxsForPKScript(ctx context.Context, script string, limit, offset uint32) ([]TxHashRow, error)

func (*ChainDB) ListTxHashesForAddress added in v0.4.11

func (bt *ChainDB) ListTxHashesForAddress(ctx context.Context, address string,
	since, until int64, limit, offset uint32) ([]TxIDRow, error)

func (*ChainDB) ListTxIDsForPKScript

func (bt *ChainDB) ListTxIDsForPKScript(ctx context.Context, script string,
	since, until int64, limit, offset uint32, strictRanges bool) ([]TxIDRow, error)

func (*ChainDB) ListTxOperationsForTxs added in v0.4.11

func (bt *ChainDB) ListTxOperationsForTxs(ctx context.Context, txHashes []string) ([]TxInOutViewRow, error)

func (*ChainDB) LockTxOuts

func (bt *ChainDB) LockTxOuts(ctx context.Context, list []int64, height int32, period int) error

func (*ChainDB) MarkBlockOrphan

func (bt *ChainDB) MarkBlockOrphan(ctx context.Context, blockHash string) error

func (*ChainDB) MarkTxOutSpent

func (bt *ChainDB) MarkTxOutSpent(ctx context.Context, outID int64) error

func (*ChainDB) PkScriptRow

func (bt *ChainDB) PkScriptRow(ctx context.Context, script string) (*PkScriptRow, error)

func (*ChainDB) SelectBlocksBits

func (bt *ChainDB) SelectBlocksBits(ctx context.Context, fromHeight, toHeight int64) ([]BlockBits, error)

func (*ChainDB) SelectChainsInfo

func (bt *ChainDB) SelectChainsInfo(ctx context.Context) ([]ChainInfo, error)

func (*ChainDB) SelectLatestBlocks

func (bt *ChainDB) SelectLatestBlocks(ctx context.Context, limit, offset uint32) ([]BlockHeaderShortRow, error)

func (*ChainDB) SelectLatestTxs

func (bt *ChainDB) SelectLatestTxs(ctx context.Context, limit, offset uint32) ([]TxStatsExtRow, error)

func (*ChainDB) SelectTxInsVWForHashes

func (bt *ChainDB) SelectTxInsVWForHashes(ctx context.Context, txHashes []string) ([]TxInViewRow, error)

func (*ChainDB) SelectTxOutsVWForHashes

func (bt *ChainDB) SelectTxOutsVWForHashes(ctx context.Context, txHashes []string) ([]TxOutViewRow, error)

func (*ChainDB) UTXO

func (bt *ChainDB) UTXO() *UTXOQ

func (*ChainDB) UnlockTxOuts

func (bt *ChainDB) UnlockTxOuts(ctx context.Context) error

func (*ChainDB) UpdateBalances added in v0.4.11

func (bt *ChainDB) UpdateBalances(ctx context.Context) error

type ChainDBMeta

type ChainDBMeta struct {
	Network   string
	DBVersion string
}

func (ChainDBMeta) ToKV

func (m ChainDBMeta) ToKV() []KV

type ChainInfo

type ChainInfo struct {
	bun.BaseModel   `bun:"table:chains,alias:c"`
	ChainID         int64  `bun:"chain_id"`
	ChainName       string `bun:"chain_name"`
	ChainGenesis    string `bun:"chain_genesis"`
	ExpansionHeight int32  `bun:"expansion_height"`
	ExpansionHash   string `bun:"expansion_hash"`
	GenesisBlock    []byte `bun:"genesis_block"`
}

type DBCfg

type DBCfg struct {
	ConnDSN string `toml:"conn_dsn"`
}

type ExchangeAgentRow

type ExchangeAgentRow struct {
	bun.BaseModel  `bun:"table:exchange_agents,alias:ead"`
	ID             int64  `bun:"id"`
	ShardID        int64  `bun:"shard_id"`
	NetAddress     string `bun:"net_address"`
	ExpirationDate int64  `bun:"expiration_date"`
	RawKey         []byte `bun:"raw_key"`
}

type Executor

type Executor struct {
	Migrations
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor(db *sql.DB) (*Executor, error)

func (*Executor) Migrate

func (executor *Executor) Migrate(dir string) (int, error)

Migrate connects to the database and applies migrations.

func (*Executor) SetMigrations

func (executor *Executor) SetMigrations(set Migrations) *Executor

type IDHashOrphanRow

type IDHashOrphanRow struct {
	ID     int64  `bun:"id" json:"-"`
	Hash   string `bun:"hash" json:"blockHash"`
	Orphan bool   `bun:"orphan" json:"isOrphan"`
}

type IDHashRow

type IDHashRow struct {
	ID   int64  `bun:"id"`
	Hash string `bun:"hash"`
}

type IDInOutRow

type IDInOutRow struct {
	ID     int64  `bun:"id"`
	TxHash string `bun:"tx_hash"`
	N      int32  `bun:"n"`
}

type IDScriptRow

type IDScriptRow struct {
	ID       int64  `bun:"id"`
	PkScript string `bun:"pk_script"`
}

type KV

type KV struct {
	Key   string `bun:"key"`
	Value string `bun:"value"`
}

type Migrations

type Migrations struct {
	Table           string
	Schema          string
	EnablePatchMode bool
	Assets          migrate.MigrationSource
}

type PkScriptRow

type PkScriptRow struct {
	bun.BaseModel `bun:"table:pk_scripts,alias:p"`
	ID            int64          `bun:"id"`
	PkScript      string         `bun:"pk_script"`
	Addresses     []string       `bun:"addresses,array"`
	ScriptType    string         `bun:"script_type"`
	ReqSigs       int32          `bun:"req_sigs"`
	InnerScript   sql.NullString `bun:"inner_script"`
}

type RowID

type RowID struct {
	ID int64 `bun:"id"`
}

type SequenceValue

type SequenceValue struct {
	LastValue int64 `bun:"last_value"`
}

type SwapTxOuts

type SwapTxOuts struct {
	bun.BaseModel `bun:"table:swap_tx_outs,alias:sto"`
	TxHash        string `bun:"tx_hash"`
	OutN          int    `bun:"out_n"`
	ChainName     string `bun:"chain_name"`
	ChainID       int64  `bun:"chain_id"`
}

type TxHashRow

type TxHashRow struct {
	ID     int64  `bun:"id"`
	TxHash string `bun:"tx_hash"`
}

type TxIDRow added in v0.4.11

type TxIDRow struct {
	Height    int64  `bun:"height"`
	TxHash    string `bun:"tx_hash"`
	Direction string `bun:"direction"`
	BlockTime int64  `bun:"block_time"`
}

type TxInOutViewRow

type TxInOutViewRow struct {
	ID          int64  `bun:"id"`
	BlockHash   string `bun:"block_hash"`
	TxHash      string `bun:"tx_hash"`
	WitnessHash string `bun:"witness_hash"`
	Index       int32  `bun:"index"`
	Direction   string `bun:"direction"`
	PkScript    string `bun:"pk_script"`
	Address     string `bun:"address"`
	Value       int64  `bun:"value"`
	Height      int64  `bun:"height"`
	BlockTime   int64  `bun:"block_time"`
}

type TxInRow

type TxInRow struct {
	bun.BaseModel `bun:"table:tx_ins,alias:txi"`
	ID            int64  `bun:"id"`
	TxHash        string `bun:"tx_hash"`
	BlockHash     string `bun:"block_hash"`
	InN           int32  `bun:"in_n"`
	ParentOut     int64  `bun:"parent_out"`
	ParentTxHash  string `bun:"parent_tx_hash"`
	ParentOutN    int32  `bun:"parent_out_n"`
	PkScript      string `bun:"pk_script"`
	Value         int64  `bun:"value"`
}

type TxInViewRow

type TxInViewRow struct {
	bun.BaseModel `bun:"table:tx_in_vw,alias:txiv"`
	TxInOutViewRow
}

type TxOutRow

type TxOutRow struct {
	bun.BaseModel `bun:"table:tx_outs,alias:txo"`
	ID            int64  `bun:"id"`
	TxHash        string `bun:"tx_hash"`
	BlockHash     string `bun:"block_hash"`
	OutN          int32  `bun:"out_n"`
	PkScript      string `bun:"pk_script"`
	Value         int64  `bun:"value"`
	Orphan        bool   `bun:"orphan"`
	Spent         bool   `bun:"spent"`
	Locked        bool   `bun:"locked"`
	Height        int64  `bun:"height"`
	LockPeriod    int64  `bun:"lock_period"`
}

type TxOutViewRow

type TxOutViewRow struct {
	bun.BaseModel `bun:"table:tx_out_vw,alias:txov"`
	TxInOutViewRow
}

type TxRow

type TxRow struct {
	bun.BaseModel `bun:"table:transactions,alias:tx"`
	ID            int64  `bun:"id"`
	TxHash        string `bun:"tx_hash"`
	BlockHash     string `bun:"block_hash"`
	TxN           int32  `bun:"tx_n"`
	Version       int32  `bun:"version"`
	LockTime      int64  `bun:"lock_time"`
	Coinbase      bool   `bun:"coinbase"`
	WitnessHash   string `bun:"witness_hash"`
	RawTx         []byte `bun:"raw_tx"`
}

type TxStatsExtRow

type TxStatsExtRow struct {
	bun.BaseModel `bun:"table:tx_stats,alias:txst"`
	TxHash        string `bun:"tx_hash"`
	Height        int64  `bun:"height"`
	InValue       int64  `bun:"in_value"`
	OutValue      int64  `bun:"out_value"`
	Fee           int64  `bun:"fee"`
}

type TxStatsRow

type TxStatsRow struct {
	bun.BaseModel `bun:"table:tx_stats,alias:txst"`
	TxHash        string `bun:"tx_hash"`
	BlockHash     string `bun:"block_hash"`
	InValue       int64  `bun:"in_value"`
	OutValue      int64  `bun:"out_value"`
	Fee           int64  `bun:"fee"`
}

type UTXO

type UTXO struct {
	bun.BaseModel `bun:"table:utxo_vw,alias:utvw"`
	ID            int64  `bun:"id"`
	BlockHash     string `bun:"block_hash"`
	Height        int64  `bun:"height"`
	TxHash        string `bun:"tx_hash"`
	OutN          int64  `bun:"out_n"`
	Address       string `bun:"address"`
	Value         int64  `bun:"value"`
	Spent         bool   `bun:"spent"`
	PKScript      string `bun:"pk_script"`
	ScriptType    string `bun:"script_type"`
	Locked        bool   `bun:"locked"`
	LockPeriod    int64  `bun:"lock_period"`
	BlockTime     int64  `bun:"block_time"`
}

type UTXOQ

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

func NewUTXOQ

func NewUTXOQ(db bun.IDB, chainName string) *UTXOQ

func (*UTXOQ) OrderBy

func (table *UTXOQ) OrderBy(column, direction string) *UTXOQ

func (*UTXOQ) SelectUTXOByAddress

func (table *UTXOQ) SelectUTXOByAddress(ctx context.Context, address string) ([]UTXO, error)

func (*UTXOQ) SelectUTXOByAddressForAmount added in v0.4.11

func (table *UTXOQ) SelectUTXOByAddressForAmount(ctx context.Context, address string, amountLimit uint64) ([]UTXO, error)

func (*UTXOQ) SelectUTXOByTxHashes

func (table *UTXOQ) SelectUTXOByTxHashes(ctx context.Context, list []string) ([]UTXO, error)

func (*UTXOQ) SelectUTXOByTxHashesWithStatus added in v0.4.11

func (table *UTXOQ) SelectUTXOByTxHashesWithStatus(ctx context.Context, list []string, locked, spent bool) ([]UTXO, error)

func (*UTXOQ) Since added in v0.4.11

func (table *UTXOQ) Since(since int64) *UTXOQ

func (*UTXOQ) SinceStrict added in v0.4.11

func (table *UTXOQ) SinceStrict(since int64) *UTXOQ

func (*UTXOQ) Until added in v0.4.11

func (table *UTXOQ) Until(until int64) *UTXOQ

func (*UTXOQ) UntilStrict added in v0.4.11

func (table *UTXOQ) UntilStrict(until int64) *UTXOQ

func (*UTXOQ) WithAddress

func (table *UTXOQ) WithAddress(address string) *UTXOQ

func (*UTXOQ) WithLimit

func (table *UTXOQ) WithLimit(limit uint32) *UTXOQ

func (*UTXOQ) WithLockStatus

func (table *UTXOQ) WithLockStatus(isLocked bool) *UTXOQ

func (*UTXOQ) WithOffset

func (table *UTXOQ) WithOffset(offset uint32) *UTXOQ

func (*UTXOQ) WithSpentStatus

func (table *UTXOQ) WithSpentStatus(spent bool) *UTXOQ

Jump to

Keyboard shortcuts

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