db

package
v0.0.0-...-a6db85c Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2018 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TypeMaster = 0
	TypeSub    = 1 << 1
	TypeMulti  = 1 << 2
	TypeNotify = 1 << 3
)
View Source
const (
	DriverName = "sqlite3"
	DBName     = "./spv_wallet.db"
)
View Source
const (
	ChainHeightKey = "ChainHeight"
)
View Source
const CreateAddrsDB = `CREATE TABLE IF NOT EXISTS Addrs(
				Hash BLOB NOT NULL PRIMARY KEY,
				Script BLOB,
				Type INTEGER NOT NULL
			);`
View Source
const CreateInfoDB = `CREATE TABLE IF NOT EXISTS Info(
				Key NOT NULL PRIMARY KEY,
				Value BLOB NOT NULL
			);`
View Source
const CreateSTXOsDB = `` /* 258-byte string literal not displayed */
View Source
const CreateTXNDB = `` /* 129-byte string literal not displayed */
View Source
const CreateUTXOsDB = `` /* 195-byte string literal not displayed */

Variables

View Source
var (
	BKTHeaders  = []byte("Headers")
	BKTChainTip = []byte("ChainTip")
	KEYChainTip = []byte("ChainTip")
)

Functions

This section is empty.

Types

type Addr

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

func NewAddr

func NewAddr(hash *Uint168, script []byte, addrType int) *Addr

func (*Addr) Hash

func (addr *Addr) Hash() *Uint168

func (*Addr) Script

func (addr *Addr) Script() []byte

func (*Addr) String

func (addr *Addr) String() string

func (*Addr) Type

func (addr *Addr) Type() int

func (*Addr) TypeName

func (addr *Addr) TypeName() string

type Addrs

type Addrs interface {
	// put a address to database
	Put(hash *Uint168, script []byte, addrType int) error

	// get a address from database
	Get(hash *Uint168) (*Addr, error)

	// get all addresss from database
	GetAll() ([]*Addr, error)

	// delete a address from database
	Delete(hash *Uint168) error
}

func NewAddrsDB

func NewAddrsDB(db *sql.DB, lock *sync.RWMutex) (Addrs, error)

type AddrsDB

type AddrsDB struct {
	*sync.RWMutex
	*sql.DB
}

func (*AddrsDB) Delete

func (db *AddrsDB) Delete(hash *Uint168) error

delete a script from database

func (*AddrsDB) Get

func (db *AddrsDB) Get(hash *Uint168) (*Addr, error)

get a script from database

func (*AddrsDB) GetAll

func (db *AddrsDB) GetAll() ([]*Addr, error)

get all Addrs from database

func (*AddrsDB) Put

func (db *AddrsDB) Put(hash *Uint168, script []byte, addrType int) error

put a script to database

type DataStore

type DataStore interface {
	Info() Info
	Addrs() Addrs
	Txs() Txs
	UTXOs() UTXOs
	STXOs() STXOs

	Rollback(height uint32) error
	// Reset database, clear all data
	Reset() error

	Close()
}

type HeaderCache

type HeaderCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*HeaderCache) Get

func (cache *HeaderCache) Get(hash common.Uint256) (*db.StoreHeader, error)

func (*HeaderCache) Set

func (cache *HeaderCache) Set(header *db.StoreHeader)

type Headers

type Headers interface {
	// Add a new header to blockchain
	Put(header *db.StoreHeader, newTip bool) error

	// Get previous block of the given header
	GetPrevious(header *db.StoreHeader) (*db.StoreHeader, error)

	// Get full header with it's hash
	GetHeader(hash common.Uint256) (*db.StoreHeader, error)

	// Get the header on chain tip
	GetTip() (*db.StoreHeader, error)

	// Reset database, clear all data
	Reset() error

	// Close db
	Close()
}

func NewHeadersDB

func NewHeadersDB() (Headers, error)

type HeadersDB

type HeadersDB struct {
	*sync.RWMutex
	*bolt.DB
	// contains filtered or unexported fields
}

HeadersDB implements Headers using bolt DB

func (*HeadersDB) Close

func (h *HeadersDB) Close()

Close db

func (*HeadersDB) GetHeader

func (h *HeadersDB) GetHeader(hash common.Uint256) (header *db.StoreHeader, err error)

Get full header with it's hash

func (*HeadersDB) GetPrevious

func (h *HeadersDB) GetPrevious(header *db.StoreHeader) (*db.StoreHeader, error)

Get previous block of the given header

func (*HeadersDB) GetTip

func (h *HeadersDB) GetTip() (header *db.StoreHeader, err error)

Get the header on chain tip

func (*HeadersDB) Put

func (h *HeadersDB) Put(header *db.StoreHeader, newTip bool) error

Add a new header to blockchain

func (*HeadersDB) Reset

func (h *HeadersDB) Reset() error

type Info

type Info interface {
	// get chain height
	ChainHeight() uint32

	// save chain height
	SaveChainHeight(height uint32)

	// put key and value into db
	Put(key string, data []byte) error

	// get value by key
	Get(key string) ([]byte, error)

	// delete value by key
	Delete(key string) error
}

func NewInfoDB

func NewInfoDB(db *sql.DB, lock *sync.RWMutex) (Info, error)

type InfoDB

type InfoDB struct {
	*sync.RWMutex
	*sql.DB
}

func (*InfoDB) ChainHeight

func (db *InfoDB) ChainHeight() uint32

get chain height

func (*InfoDB) Delete

func (db *InfoDB) Delete(key string) error

delete value by key

func (*InfoDB) Get

func (db *InfoDB) Get(key string) ([]byte, error)

get value by key

func (*InfoDB) Put

func (db *InfoDB) Put(key string, value []byte) error

put key and value into db

func (*InfoDB) SaveChainHeight

func (db *InfoDB) SaveChainHeight(height uint32)

save chain height

type SQLiteDB

type SQLiteDB struct {
	*sync.RWMutex
	*sql.DB
	// contains filtered or unexported fields
}

func NewSQLiteDB

func NewSQLiteDB() (*SQLiteDB, error)

func (*SQLiteDB) Addrs

func (db *SQLiteDB) Addrs() Addrs

func (*SQLiteDB) Close

func (db *SQLiteDB) Close()

func (*SQLiteDB) Info

func (db *SQLiteDB) Info() Info

func (*SQLiteDB) Reset

func (db *SQLiteDB) Reset() error

func (*SQLiteDB) Rollback

func (db *SQLiteDB) Rollback(height uint32) error

func (*SQLiteDB) STXOs

func (db *SQLiteDB) STXOs() STXOs

func (*SQLiteDB) Txs

func (db *SQLiteDB) Txs() Txs

func (*SQLiteDB) UTXOs

func (db *SQLiteDB) UTXOs() UTXOs

type STXO

type STXO struct {
	// When it used to be a UTXO
	UTXO

	// The height at which it met its demise
	SpendHeight uint32

	// The tx that consumed it
	SpendTxId Uint256
}

func (*STXO) IsEqual

func (stxo *STXO) IsEqual(alt *STXO) bool

func (*STXO) String

func (stxo *STXO) String() string

type STXOs

type STXOs interface {
	// Move a UTXO to STXO
	FromUTXO(outPoint *OutPoint, spendTxId *Uint256, spendHeight uint32) error

	// get a stxo from database
	Get(outPoint *OutPoint) (*STXO, error)

	// get stxos of the given address hash from database
	GetAddrAll(hash *Uint168) ([]*STXO, error)

	// Get all STXOs in database
	GetAll() ([]*STXO, error)

	// delete a stxo from database
	Delete(outPoint *OutPoint) error
}

func NewSTXOsDB

func NewSTXOsDB(db *sql.DB, lock *sync.RWMutex) (STXOs, error)

type STXOsDB

type STXOsDB struct {
	*sync.RWMutex
	*sql.DB
}

func (*STXOsDB) Delete

func (db *STXOsDB) Delete(outPoint *OutPoint) error

delete a stxo from database

func (*STXOsDB) FromUTXO

func (db *STXOsDB) FromUTXO(outPoint *OutPoint, spendTxId *Uint256, spendHeight uint32) error

Move a UTXO to STXO

func (*STXOsDB) Get

func (db *STXOsDB) Get(outPoint *OutPoint) (*STXO, error)

get a stxo from database

func (*STXOsDB) GetAddrAll

func (db *STXOsDB) GetAddrAll(hash *Uint168) ([]*STXO, error)

get stxos of the given script hash from database

func (*STXOsDB) GetAll

func (db *STXOsDB) GetAll() ([]*STXO, error)

type SortableUTXOs

type SortableUTXOs []*UTXO

func (SortableUTXOs) Len

func (utxos SortableUTXOs) Len() int

func (SortableUTXOs) Less

func (utxos SortableUTXOs) Less(i, j int) bool

func (SortableUTXOs) Swap

func (utxos SortableUTXOs) Swap(i, j int)

type Txs

type Txs interface {
	// Put a new transaction to database
	Put(txn *db.StoreTx) error

	// Fetch a raw tx and it's metadata given a hash
	Get(txId *Uint256) (*db.StoreTx, error)

	// Fetch all transactions from database
	GetAll() ([]*db.StoreTx, error)

	// Fetch all transactions from the given height
	GetAllFrom(height uint32) ([]*db.StoreTx, error)

	// Update the height of a transaction
	UpdateHeight(txId *Uint256, height uint32) error

	// Delete a transaction from the db
	Delete(txId *Uint256) error
}

func NewTxsDB

func NewTxsDB(db *sql.DB, lock *sync.RWMutex) (Txs, error)

type TxsDB

type TxsDB struct {
	*sync.RWMutex
	*sql.DB
}

func (*TxsDB) Delete

func (t *TxsDB) Delete(txId *Uint256) error

Delete a transaction from the db

func (*TxsDB) Get

func (t *TxsDB) Get(txId *Uint256) (*db.StoreTx, error)

Fetch a raw tx and it's metadata given a hash

func (*TxsDB) GetAll

func (t *TxsDB) GetAll() ([]*db.StoreTx, error)

Fetch all transactions from database

func (*TxsDB) GetAllFrom

func (t *TxsDB) GetAllFrom(height uint32) ([]*db.StoreTx, error)

Fetch all transactions from the given height

func (*TxsDB) Put

func (t *TxsDB) Put(storeTx *db.StoreTx) error

Put a new transaction to database

func (*TxsDB) UpdateHeight

func (t *TxsDB) UpdateHeight(txId *Uint256, height uint32) error

Update the height of a transaction

type UTXO

type UTXO struct {
	// Previous txid and output index
	Op OutPoint

	// The higher the better
	Value Fixed64

	// The utxo locked height
	LockTime uint32

	// Block height where this tx was confirmed, 0 for unconfirmed
	AtHeight uint32
}

func SortUTXOs

func SortUTXOs(utxos []*UTXO) []*UTXO

func (*UTXO) IsEqual

func (utxo *UTXO) IsEqual(alt *UTXO) bool

func (*UTXO) String

func (utxo *UTXO) String() string

type UTXOs

type UTXOs interface {
	// put a utxo to database
	Put(hash *Uint168, utxo *UTXO) error

	// get a utxo from database
	Get(outPoint *OutPoint) (*UTXO, error)

	// get utxos of the given address hash from database
	GetAddrAll(hash *Uint168) ([]*UTXO, error)

	// Get all UTXOs in database
	GetAll() ([]*UTXO, error)

	// delete a utxo from database
	Delete(outPoint *OutPoint) error
}

func NewUTXOsDB

func NewUTXOsDB(db *sql.DB, lock *sync.RWMutex) (UTXOs, error)

type UTXOsDB

type UTXOsDB struct {
	*sync.RWMutex
	*sql.DB
}

func (*UTXOsDB) Delete

func (db *UTXOsDB) Delete(outPoint *OutPoint) error

delete a utxo from database

func (*UTXOsDB) Get

func (db *UTXOsDB) Get(outPoint *OutPoint) (*UTXO, error)

get a utxo from database

func (*UTXOsDB) GetAddrAll

func (db *UTXOsDB) GetAddrAll(hash *Uint168) ([]*UTXO, error)

get utxos of the given script hash from database

func (*UTXOsDB) GetAll

func (db *UTXOsDB) GetAll() ([]*UTXO, error)

func (*UTXOsDB) Put

func (db *UTXOsDB) Put(hash *Uint168, utxo *UTXO) error

put a utxo to database

Jump to

Keyboard shortcuts

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