pubrecdb

package
v0.0.0-...-5da9300 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2016 License: GPL-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockNotTip error = errors.New("block is not chain tip")
)

Functions

func ExecPragma

func ExecPragma(db *PublicRecord, on bool) error

ExecPragma executes directives that are needed for the write side of the SQL conn to enforce high quality (and secure!) sql statements.

Types

type PublicRecord

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

The overarching struct that contains everything needed for a connection to a sqlite db containing the public record.

func InitDB

func InitDB(path string, params *chaincfg.Params) (*PublicRecord, error)

Creates a DB at the desired path or drops an existing one and recreates a new empty one at the path. The bitcoin network is needed because the genesis block must be inserted first for the DB to initialized properly.

func LoadDB

func LoadDB(path string) (*PublicRecord, error)

Loads a sqlite db, checks if its reachabale and prepares all the queries.

func (*PublicRecord) BlockCount

func (db *PublicRecord) BlockCount() (int, error)

BlockCount returns the number of blocks stored in the DB

func (*PublicRecord) BulletinCount

func (db *PublicRecord) BulletinCount() (int, error)

func (*PublicRecord) DeleteBlockTip

func (db *PublicRecord) DeleteBlockTip(sha *wire.ShaHash) (error, bool)

DeleteBlockTip deletes the block header and any dependent data. It will throw a ErrBlockNotTip error if you try to delete any block that is not the tip.

func (*PublicRecord) DropAfterBlockBySha

func (db *PublicRecord) DropAfterBlockBySha(sha *wire.ShaHash) error

DropAfterBlockBySha deletes all of the blocks after the passed sha in the database.

func (*PublicRecord) EmptyTables

func (db *PublicRecord) EmptyTables() error

EmptyTables deletes all of the rows from the public record

func (*PublicRecord) EndoCount

func (db *PublicRecord) EndoCount() (int, error)

func (*PublicRecord) FindHeight

func (db *PublicRecord) FindHeight(hash *wire.ShaHash) (int32, error)

FindHeight returns the height of the block. It returns -1, sql.ErrNoRows if block hash is not in the record. If the passed hash is the prevHash of the peg block, FindHeight returns the height from memory, it does not make a round trip to the db.

func (*PublicRecord) GetAuthor

func (db *PublicRecord) GetAuthor(author btcutil.Address) (*ombjson.AuthorResp, error)

GetAuthor returns the bulletins and the endorsements a bitcoin address has sent.

func (*PublicRecord) GetBestTags

func (db *PublicRecord) GetBestTags() ([]*ombjson.Tag, error)

GetBestTag returns the 'best' tags as determined by a simple geometric formula that takes into account the number of times the tag has been used and the first time the tag was seen in the record.

func (*PublicRecord) GetBlock

func (db *PublicRecord) GetBlock(hash *wire.ShaHash) (*ombjson.Block, error)

GetBlock returns the block in the record specified by 'hash'. If it is not present then sql.ErrNoRows is returned.

func (*PublicRecord) GetBlockTip

func (db *PublicRecord) GetBlockTip() (*ombjson.Block, error)

GetBlockTip works exactly the same as GetBlock except that the query always returns the block at the tip of the chain. This is the block that has the greatest height in the record.

func (*PublicRecord) GetBulletin

func (db *PublicRecord) GetBulletin(txid *wire.ShaHash) (*ombjson.Bulletin, error)

GetBulletin returns a single bulletin as json that is identified by txid. If the bltn does not exist the functions returns sql.ErrNoRows. The function assumes that the passed txid string is correctly formed (all lower case hex string).

func (*PublicRecord) GetEndorsement

func (db *PublicRecord) GetEndorsement(txid *wire.ShaHash) (*ombjson.Endorsement, error)

GetEndorsement returns a single json Endorsement. If the record does not exist the method throws sql.ErrNoRows

func (*PublicRecord) GetEndosByBid

func (db *PublicRecord) GetEndosByBid(bid *wire.ShaHash) ([]*ombjson.Endorsement, error)

GetEndosByBid returns all of the endorsements for a specific bulletin. This is used by GetBulletin to fill out the endorsements a specific bulletin has received.

func (*PublicRecord) GetEndosByHeight

func (db *PublicRecord) GetEndosByHeight(startH, stopH int32) ([]*ombjson.Endorsement, error)

GetEndosByHeight returns all of the endorsements between start and stop where anything stored at the stop height is excluded

func (*PublicRecord) GetLatestPage

func (db *PublicRecord) GetLatestPage() (*ombjson.Page, error)

GetLatestPage returns all of the bulletins and endorsements under the max query limit.

func (*PublicRecord) GetMostEndorsedBltns

func (db *PublicRecord) GetMostEndorsedBltns(lim int) ([]*ombjson.Bulletin, error)

GetMostEndorsedBltns returns a list of bltns sorted by number of endorsements received. It does not return bltns with 0 endorsements.

func (*PublicRecord) GetNearbyBltns

func (db *PublicRecord) GetNearbyBltns(lat, lon, r float64) ([]*ombjson.Bulletin, error)

GetNearbyBltns returns bulletins that were tagged with a location within r kilometers of lat, lon. The bulletin are ordered by block timestamp and are NOT sorted by distance from the point.

func (*PublicRecord) GetStatistics

func (db *PublicRecord) GetStatistics(start, fin time.Time) (*ombjson.Statistics, error)

GetStatistics returns information about some continous period of time over which records and blocks were stored in the public record. Currently it only produces counts, but one day it will produce interesting facts for the scientists to measure.

func (*PublicRecord) GetTag

func (db *PublicRecord) GetTag(tag ombutil.Tag) (*ombjson.BltnPage, error)

GetTag returns a blk cursor with all of the bulletins in a tag ordered by the bulletins timestamp. If no bulletins exist in the record with that tag, an empty list is returned. WARNING THIS DOES NOT PROVIDE THE RIGHT ANSWER FOR TESTNET

func (*PublicRecord) InsertBlockHead

func (db *PublicRecord) InsertBlockHead(blk *btcutil.Block) (error, bool)

InsertBlockHead only inserts the headers of the block into the DB. If the block is already in the record then an error is thrown. It makes no effort to insert bulletins or endorsements contained within it.

func (*PublicRecord) InsertBulletin

func (db *PublicRecord) InsertBulletin(bltn *ombutil.Bulletin) (error, bool)

InsertBulletin takes a bulletins and inserts it into the pubrecord. A ombproto.Bulletin is used here instead of a wire.Bulletin because of the high level utilities offered by the ombproto type.

func (*PublicRecord) InsertEndorsement

func (db *PublicRecord) InsertEndorsement(endo *ombutil.Endorsement) (error, bool)

InsertEndorsement commits an endorsement into the public record. It DOES NOT enforce foreign key constraints. This allows endorsements to come in out of order (or in a staggered fashion) endorsing a bulletin that is yet to be mined.

func (*PublicRecord) InsertGenesisBlk

func (db *PublicRecord) InsertGenesisBlk(net wire.BitcoinNet) error

func (*PublicRecord) InsertUBlock

func (db *PublicRecord) InsertUBlock(oblk *ombutil.UBlock) (error, bool)

InsertUBlock creates a SQL transaction that commits everything in the block in one go into the sqlite db. This preserves the consistency of the database even in cases where the power fails. If the insert was succesful the funciton will return (nil, true). If (anything, false) then the insert failed.

func (*PublicRecord) QueryRange

func (db *PublicRecord) QueryRange(start, stop *wire.ShaHash) (*ombjson.Page, error)

QueryRange returns all of the bulletins and endorsements within the selected start and stop block

Jump to

Keyboard shortcuts

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