postgres

package
v0.0.0-...-862ce61 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	Close() error
}

DB defines the interface that a database must implement

type Database

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

Database is our sweet database struct. Used for interacting with the database

func New

func New(dbConfig *config.DB, coin string) (*Database, error)

New makes a new database using the connection string and returns it, otherwise returns the error

func (*Database) Close

func (d *Database) Close() error

Close signals the monitor to stop and closes the underlying db connection

func (*Database) DeleteInvalidTxs

func (d *Database) DeleteInvalidTxs(ids []int) error

DeleteInvalidTxs removes invalid transactions and associated inputs/outputs

func (*Database) DeleteOrphans

func (d *Database) DeleteOrphans() error

DeleteOrphans will delete all orphaned txs and associated inputs and outputs

func (*Database) Get

func (d *Database) Get(key string) (string, error)

Get returns the value of key

func (*Database) GetBlock

func (d *Database) GetBlock(val interface{}) (*utxo.Block, error)

GetBlock returns a block at the specified height (int) or hash (string)

func (*Database) GetInputsByTxID

func (d *Database) GetInputsByTxID(txid string) ([]Input, error)

GetInputsByTxID returns a list of transaction inputs

func (*Database) GetNumTransactions

func (d *Database) GetNumTransactions() (int, error)

GetNumTransactions returns the number of transactions in the db

func (*Database) GetOrphanCount

func (d *Database) GetOrphanCount() (int, error)

GetOrphanCount returns the number of orphaned blocks in the db

func (*Database) GetOutputsByTxID

func (d *Database) GetOutputsByTxID(txid string, voutClause string) ([]Output, error)

GetOutputsByTxID returns a list of all transaction outputs from a txid The voutClause can specify searching outputs by vout number

func (*Database) GetPendingTxs

func (d *Database) GetPendingTxs(limitClause string) ([]*PendingTx, error)

GetPendingTxs returns all pending transactions

func (*Database) GetRawTxByTxID

func (d *Database) GetRawTxByTxID(txid string) (*RawTx, error)

GetRawTxByTxID gets the raw_transaction from the transaction table

func (*Database) GetSpentTxDetails

func (d *Database) GetSpentTxDetails(txid string, vout int) *SpentTxDetails

GetSpentTxDetails returns spent details for a specific vout in a txid

func (*Database) GetTotalTxsByAddresses

func (d *Database) GetTotalTxsByAddresses(addrs []string) (int, error)

GetTotalTxsByAddresses gets a total count of txs for a slice of address(es)

func (*Database) GetTotalTxsByBlockHash

func (d *Database) GetTotalTxsByBlockHash(hash string) (int, error)

GetTotalTxsByBlockHash gets the total number of txs in a block

func (*Database) GetTxAtBlockTime

func (d *Database) GetTxAtBlockTime(date time.Time) (int, error)

GetTxAtBlockTime returns the earliest inserted transaction at the block closest to date

func (*Database) GetTxByTxID

func (d *Database) GetTxByTxID(txid string) (*Tx, error)

GetTxByTxID returns transaction full details including vins and vouts Error if more than one tx found for that txid

func (*Database) GetTxHashesByBlockHash

func (d *Database) GetTxHashesByBlockHash(hash, limitClause, offsetClause string) ([]string, error)

GetTxHashesByBlockHash gets tx hashes by block hash

func (*Database) GetTxIDsByAddresses

func (d *Database) GetTxIDsByAddresses(addrs []string, limitClause, whereClause, offsetClause string) ([]string, error)

GetTxIDsByAddresses returns a slice of txids given a slice holding an address or addresses

func (*Database) GetUtxosByAddrs

func (d *Database) GetUtxosByAddrs(addrs []string) ([]*Utxo, error)

GetUtxosByAddrs returns unspent outputs for a given address

func (*Database) InsertBlock

func (d *Database) InsertBlock(b *utxo.Block, recover bool) (int, error)

InsertBlock inserts a utxo.Block into the database

func (*Database) InsertTx

func (d *Database) InsertTx(tx *utxo.Tx, txIndex int, blockID int) error

InsertTx inserts txs into the database, returns error if something bad happened

func (*Database) LastBlock

func (d *Database) LastBlock() (*utxo.Block, error)

LastBlock returns the last block added to the database

func (*Database) Set

func (d *Database) Set(key, value string) error

Set inserts or updates key with value

type Input

type Input struct {
	Vin         int      `json:"vin"`
	SpentTx     string   `json:"spent_txid"`
	SpentVout   int      `json:"spent_vout"`
	Asm         string   `json:"asm"`
	Hex         string   `json:"hex"`
	Sequence    int      `json:"sequence"`
	TxInWitness []string `json:"txinwitness"`
	Coinbase    string   `json:"coinbase"`
}

Input is utxo shape

type Output

type Output struct {
	Vout      int      `json:"vout"`
	SatAmount int64    `json:"amount"`
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex"`
	ReqSigs   int      `json:"reqSigs"`
	Type      string   `json:"type"`
	Address   string   `json:"address"`
	Addresses []string `json:"addresses"`
}

Output is utxo shape

type PendingTx

type PendingTx struct {
	ID   int    `json:"id,string"`
	TxID string `json:"txid"`
}

PendingTx contains data to validate against mempool

type RawTx

type RawTx struct {
	Hex string `json:"rawtx"`
}

RawTx structure

type SpentTxDetails

type SpentTxDetails struct {
	SpentTxID   string `json:"spentTxId"`
	SpentIndex  int    `json:"spentIndex"`
	SpentHeight int64  `json:"spentHeight"`
}

SpentTxDetails structure

type Tx

type Tx struct {
	ID          int      `json:"id,string"`
	TxID        string   `json:"txid"`
	Hash        string   `json:"hash"`
	Version     int      `json:"version"`
	Size        int      `json:"size"`
	VSize       int      `json:"vsize"`
	Weight      int      `json:"weight"`
	Locktime    int      `json:"locktime"`
	Inputs      []Input  `json:"vin"`
	Outputs     []Output `json:"vout"`
	BlockHash   string   `json:"blockhash"`
	BlockHeight int64    `json:"blockheight"`
	Time        string   `json:"time"`
	BlockTime   string   `json:"blocktime"`
	Cursor      string   `json:"cursor"`
	Mempool     bool     `json:"mempool"`
}

Tx is shape of transaction for return from graphql and API rest interfaces

type Utxo

type Utxo struct {
	Vout        int    `json:"vout"`
	Hex         string `json:"hex"`
	ReqSigs     int    `json:"reqSigs"`
	Type        string `json:"type"`
	Address     string `json:"address"`
	SatAmount   int64  `json:"amount"`
	TxID        string `json:"txid"`
	BlockHeight int64  `json:"height"`
	Timestamp   string `json:"ts"`
}

Utxo structure

Jump to

Keyboard shortcuts

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