Documentation ¶
Index ¶
- type DB
- type Database
- func (d *Database) Close() error
- func (d *Database) DeleteInvalidTxs(ids []int) error
- func (d *Database) DeleteOrphans() error
- func (d *Database) Get(key string) (string, error)
- func (d *Database) GetBlock(val interface{}) (*utxo.Block, error)
- func (d *Database) GetInputsByTxID(txid string) ([]Input, error)
- func (d *Database) GetNumTransactions() (int, error)
- func (d *Database) GetOrphanCount() (int, error)
- func (d *Database) GetOutputsByTxID(txid string, voutClause string) ([]Output, error)
- func (d *Database) GetPendingTxs(limitClause string) ([]*PendingTx, error)
- func (d *Database) GetRawTxByTxID(txid string) (*RawTx, error)
- func (d *Database) GetSpentTxDetails(txid string, vout int) *SpentTxDetails
- func (d *Database) GetTotalTxsByAddresses(addrs []string) (int, error)
- func (d *Database) GetTotalTxsByBlockHash(hash string) (int, error)
- func (d *Database) GetTxAtBlockTime(date time.Time) (int, error)
- func (d *Database) GetTxByTxID(txid string) (*Tx, error)
- func (d *Database) GetTxHashesByBlockHash(hash, limitClause, offsetClause string) ([]string, error)
- func (d *Database) GetTxIDsByAddresses(addrs []string, limitClause, whereClause, offsetClause string) ([]string, error)
- func (d *Database) GetUtxosByAddrs(addrs []string) ([]*Utxo, error)
- func (d *Database) InsertBlock(b *utxo.Block, recover bool) (int, error)
- func (d *Database) InsertTx(tx *utxo.Tx, txIndex int, blockID int) error
- func (d *Database) LastBlock() (*utxo.Block, error)
- func (d *Database) Set(key, value string) error
- type Input
- type Output
- type PendingTx
- type RawTx
- type SpentTxDetails
- type Tx
- type Utxo
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 ¶
New makes a new database using the connection string and returns it, otherwise returns the error
func (*Database) DeleteInvalidTxs ¶
DeleteInvalidTxs removes invalid transactions and associated inputs/outputs
func (*Database) DeleteOrphans ¶
DeleteOrphans will delete all orphaned txs and associated inputs and outputs
func (*Database) GetInputsByTxID ¶
GetInputsByTxID returns a list of transaction inputs
func (*Database) GetNumTransactions ¶
GetNumTransactions returns the number of transactions in the db
func (*Database) GetOrphanCount ¶
GetOrphanCount returns the number of orphaned blocks in the db
func (*Database) GetOutputsByTxID ¶
GetOutputsByTxID returns a list of all transaction outputs from a txid The voutClause can specify searching outputs by vout number
func (*Database) GetPendingTxs ¶
GetPendingTxs returns all pending transactions
func (*Database) GetRawTxByTxID ¶
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 ¶
GetTotalTxsByAddresses gets a total count of txs for a slice of address(es)
func (*Database) GetTotalTxsByBlockHash ¶
GetTotalTxsByBlockHash gets the total number of txs in a block
func (*Database) GetTxAtBlockTime ¶
GetTxAtBlockTime returns the earliest inserted transaction at the block closest to date
func (*Database) GetTxByTxID ¶
GetTxByTxID returns transaction full details including vins and vouts Error if more than one tx found for that txid
func (*Database) GetTxHashesByBlockHash ¶
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 ¶
GetUtxosByAddrs returns unspent outputs for a given address
func (*Database) InsertBlock ¶
InsertBlock inserts a utxo.Block into the database
func (*Database) InsertTx ¶
InsertTx inserts txs into the database, returns error if something bad happened
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 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