database

package
v0.0.0-...-e49ae39 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassNameNodes                  = "nodes"
	ClassNameBlockchain             = "blockchain"
	ClassNameTransactions           = "transactions"
	ClassNameUnapprovedTransactions = "unapprovedtransactions"
	ClassNameUnspentOutputs         = "unspentoutputs"
)
View Source
const DBCursorBreak = "cursorbreak"
View Source
const DBHashEmptyError = "hashisemptyd"
View Source
const DBHashError = "hashemptyd"
View Source
const DBHashNotFoundError = "hashnotfound"
View Source
const TXVerifyErrorNoInput = "noinput"

Variables

This section is empty.

Functions

func NewBucketNotFoundDBError

func NewBucketNotFoundDBError() error

func NewDBCursorStopError

func NewDBCursorStopError() error

func NewDBError

func NewDBError(err string, kind string) error

func NewDBIsNotReadyError

func NewDBIsNotReadyError() error

func NewHashDBError

func NewHashDBError(err string) error

func NewHashEmptyDBError

func NewHashEmptyDBError() error

func NewHashNotFoundDBError

func NewHashNotFoundDBError(err string) error

func NewNotFoundDBError

func NewNotFoundDBError(kind string) error

Types

type Blockchain

type Blockchain struct {
	DB *BoltDB
}

func (*Blockchain) AddToChain

func (bc *Blockchain) AddToChain(hash, prevHash []byte) error

add block to chain

func (*Blockchain) BlockInChain

func (bc *Blockchain) BlockInChain(hash []byte) (bool, error)

func (*Blockchain) CheckBlockExists

func (bc *Blockchain) CheckBlockExists(hash []byte) (bool, error)

Check if block exists by hash

func (*Blockchain) DeleteBlock

func (bc *Blockchain) DeleteBlock(hash []byte) error

Delete block record

func (*Blockchain) GetBlock

func (bc *Blockchain) GetBlock(hash []byte) ([]byte, error)

Get block data by hash. It returns just []byte and and must be deserialised on ther place

func (*Blockchain) GetFirstHash

func (bc *Blockchain) GetFirstHash() ([]byte, error)

func (*Blockchain) GetLocationInChain

func (bc *Blockchain) GetLocationInChain(hash []byte) (bool, []byte, []byte, error)

func (*Blockchain) GetTopBlock

func (bc *Blockchain) GetTopBlock() ([]byte, error)

Get block on the top of blockchain

func (*Blockchain) GetTopHash

func (bc *Blockchain) GetTopHash() ([]byte, error)

Get top level block hash

func (*Blockchain) InitDB

func (bc *Blockchain) InitDB() error

create bucket etc. DB is already inited

func (*Blockchain) PutBlock

func (bc *Blockchain) PutBlock(hash []byte, blockdata []byte) error

Add block record

func (*Blockchain) PutBlockOnTop

func (bc *Blockchain) PutBlockOnTop(hash []byte, blockdata []byte) error

Add block to the top of block chain

func (*Blockchain) RemoveFromChain

func (bc *Blockchain) RemoveFromChain(hash []byte) error

remove block from chain

func (*Blockchain) SaveFirstHash

func (bc *Blockchain) SaveFirstHash(hash []byte) error

Save first (or genesis) block hash. It should be called when blockchain is created

func (*Blockchain) SaveTopHash

func (bc *Blockchain) SaveTopHash(hash []byte) error

Save top level block hash

type BlockchainInterface

type BlockchainInterface interface {
	InitDB() error

	GetTopBlock() ([]byte, error)
	GetBlock(hash []byte) ([]byte, error)
	PutBlockOnTop(hash []byte, blockdata []byte) error
	PutBlock(hash []byte, blockdata []byte) error
	CheckBlockExists(hash []byte) (bool, error)
	DeleteBlock(hash []byte) error
	SaveTopHash(hash []byte) error
	GetTopHash() ([]byte, error)
	SaveFirstHash(hash []byte) error
	GetFirstHash() ([]byte, error)

	GetLocationInChain(hash []byte) (bool, []byte, []byte, error)
	BlockInChain(hash []byte) (bool, error)
	RemoveFromChain(hash []byte) error
	AddToChain(hash, prevHash []byte) error
}

type BoltDB

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

func (*BoltDB) Close

func (bdb *BoltDB) Close() error

type BoltDBLocker

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

type BoltDBManager

type BoltDBManager struct {
	Logger *utils.LoggerMan
	Config DatabaseConfig

	SessID string
	// contains filtered or unexported fields
}

func (*BoltDBManager) CheckDBExists

func (bdm *BoltDBManager) CheckDBExists() (bool, error)

Check if database was already inited

func (*BoltDBManager) CloseConnection

func (bdm *BoltDBManager) CloseConnection() error

func (*BoltDBManager) GetBlockchainObject

func (bdm *BoltDBManager) GetBlockchainObject() (BlockchainInterface, error)

returns BlockChain Database structure. does al init

func (*BoltDBManager) GetLockerObject

func (bdm *BoltDBManager) GetLockerObject() DatabaseLocker

func (*BoltDBManager) GetNodesObject

func (bdm *BoltDBManager) GetNodesObject() (NodesInterface, error)

returns Nodes Database structure. does al init

func (*BoltDBManager) GetTransactionsObject

func (bdm *BoltDBManager) GetTransactionsObject() (TranactionsInterface, error)

returns Transaction Index Database structure. does al init

func (*BoltDBManager) GetUnapprovedTransactionsObject

func (bdm *BoltDBManager) GetUnapprovedTransactionsObject() (UnapprovedTransactionsInterface, error)

returns Unapproved Transaction Database structure. does al init

func (*BoltDBManager) GetUnspentOutputsObject

func (bdm *BoltDBManager) GetUnspentOutputsObject() (UnspentOutputsInterface, error)

returns Unspent Transactions Database structure. does al init

func (*BoltDBManager) InitDatabase

func (bdm *BoltDBManager) InitDatabase() error

create empty database. must create all

func (*BoltDBManager) IsConnectionOpen

func (bdm *BoltDBManager) IsConnectionOpen() bool

func (*BoltDBManager) OpenConnection

func (bdm *BoltDBManager) OpenConnection(reason string) error

func (*BoltDBManager) SetConfig

func (bdm *BoltDBManager) SetConfig(config DatabaseConfig) error

func (*BoltDBManager) SetLockerObject

func (bdm *BoltDBManager) SetLockerObject(lockerobj DatabaseLocker)

func (*BoltDBManager) SetLogger

func (bdm *BoltDBManager) SetLogger(logger *utils.LoggerMan) error

type DBError

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

func (*DBError) Error

func (e *DBError) Error() string

func (*DBError) IsKind

func (e *DBError) IsKind(kind string) bool

func (*DBError) Kind

func (e *DBError) Kind() string

type DBManager

type DBManager interface {
	SetConfig(config DatabaseConfig) error
	SetLogger(logger *utils.LoggerMan) error
	GetLockerObject() DatabaseLocker
	SetLockerObject(lockerobj DatabaseLocker)

	InitDatabase() error
	CheckDBExists() (bool, error)

	OpenConnection(reason string) error
	CloseConnection() error
	IsConnectionOpen() bool

	GetBlockchainObject() (BlockchainInterface, error)
	GetTransactionsObject() (TranactionsInterface, error)
	GetUnapprovedTransactionsObject() (UnapprovedTransactionsInterface, error)
	GetUnspentOutputsObject() (UnspentOutputsInterface, error)
	GetNodesObject() (NodesInterface, error)
}

type DatabaseConfig

type DatabaseConfig struct {
	DataDir        string
	BlockchainFile string
	NodesFile      string
}

func (*DatabaseConfig) IsEmpty

func (dbc *DatabaseConfig) IsEmpty() bool

func (*DatabaseConfig) SetDefault

func (dbc *DatabaseConfig) SetDefault() error

type DatabaseConnection

type DatabaseConnection interface {
	Close() error
}

type DatabaseLocker

type DatabaseLocker interface {
}

locker interface. is empty for now. maybe in future we will have some methods

type ForEachKeyIteratorInterface

type ForEachKeyIteratorInterface func(key, value []byte) error

type Nodes

type Nodes struct {
	DB *BoltDB
}

func (*Nodes) DeleteNode

func (ns *Nodes) DeleteNode(nodeID []byte) error

func (*Nodes) ForEach

func (ns *Nodes) ForEach(callback ForEachKeyIteratorInterface) error

retrns nodes list iterator

func (*Nodes) GetCount

func (ns *Nodes) GetCount() (int, error)

get count of records in the table

func (*Nodes) InitDB

func (ns *Nodes) InitDB() error

func (*Nodes) PutNode

func (ns *Nodes) PutNode(nodeID []byte, nodeData []byte) error

Save node info

type NodesInterface

type NodesInterface interface {
	InitDB() error
	ForEach(callback ForEachKeyIteratorInterface) error
	GetCount() (int, error)

	PutNode(nodeID []byte, nodeData []byte) error
	DeleteNode(nodeID []byte) error
}

type Tranactions

type Tranactions struct {
	DB *BoltDB
}

func (*Tranactions) DeleteTXSpentData

func (txs *Tranactions) DeleteTXSpentData(txID []byte) error

Delete info about spent outputs for TX

func (txs *Tranactions) DeleteTXToBlockLink(txID []byte) error

Delete link between TX and a block hash

func (*Tranactions) GetBlockHashForTX

func (txs *Tranactions) GetBlockHashForTX(txID []byte) ([]byte, error)

Get block hash for TX

func (*Tranactions) GetTXSpentOutputs

func (txs *Tranactions) GetTXSpentOutputs(txID []byte) ([]byte, error)

Get spent outputs for TX , seialised to bytes

func (*Tranactions) InitDB

func (txs *Tranactions) InitDB() error

Init database

func (*Tranactions) PutTXSpentOutputs

func (txs *Tranactions) PutTXSpentOutputs(txID []byte, outputs []byte) error

Save spent outputs for TX

func (txs *Tranactions) PutTXToBlockLink(txID []byte, blockHash []byte) error

Save link between TX and block hash

func (*Tranactions) TruncateDB

func (txs *Tranactions) TruncateDB() error

type TranactionsInterface

type TranactionsInterface interface {
	InitDB() error
	TruncateDB() error
	PutTXToBlockLink(txID []byte, blockHash []byte) error
	GetBlockHashForTX(txID []byte) ([]byte, error)
	DeleteTXToBlockLink(txID []byte) error
	PutTXSpentOutputs(txID []byte, outputs []byte) error
	GetTXSpentOutputs(txID []byte) ([]byte, error)
	DeleteTXSpentData(txID []byte) error
}

type UnapprovedTransactions

type UnapprovedTransactions struct {
	DB *BoltDB
}

func (*UnapprovedTransactions) DeleteTransaction

func (uts *UnapprovedTransactions) DeleteTransaction(txID []byte) error

delete transation from DB

func (*UnapprovedTransactions) ForEach

execute functon for each key/value in the bucket

func (*UnapprovedTransactions) GetCount

func (uts *UnapprovedTransactions) GetCount() (int, error)

get count of records in the table

func (*UnapprovedTransactions) GetTransaction

func (uts *UnapprovedTransactions) GetTransaction(txID []byte) ([]byte, error)

returns transaction by ID if it exists

func (*UnapprovedTransactions) InitDB

func (uts *UnapprovedTransactions) InitDB() error

func (*UnapprovedTransactions) PutTransaction

func (uts *UnapprovedTransactions) PutTransaction(txID []byte, txdata []byte) error

Add transaction record

func (*UnapprovedTransactions) TruncateDB

func (uts *UnapprovedTransactions) TruncateDB() error

type UnapprovedTransactionsInterface

type UnapprovedTransactionsInterface interface {
	InitDB() error
	TruncateDB() error
	ForEach(callback ForEachKeyIteratorInterface) error
	GetCount() (int, error)

	GetTransaction(txID []byte) ([]byte, error)
	PutTransaction(txID []byte, txdata []byte) error
	DeleteTransaction(txID []byte) error
}

type UnspentOutputs

type UnspentOutputs struct {
	DB *BoltDB
}

func (*UnspentOutputs) DeleteDataForTransaction

func (uos *UnspentOutputs) DeleteDataForTransaction(txID []byte) error

func (*UnspentOutputs) ForEach

func (uos *UnspentOutputs) ForEach(callback ForEachKeyIteratorInterface) error

execute functon for each key/value in the bucket

func (*UnspentOutputs) GetCount

func (uos *UnspentOutputs) GetCount() (int, error)

get count of records in the table

func (*UnspentOutputs) GetDataForTransaction

func (uos *UnspentOutputs) GetDataForTransaction(txID []byte) ([]byte, error)

func (*UnspentOutputs) InitDB

func (uos *UnspentOutputs) InitDB() error

func (*UnspentOutputs) PutDataForTransaction

func (uos *UnspentOutputs) PutDataForTransaction(txID []byte, txData []byte) error

func (*UnspentOutputs) TruncateDB

func (uos *UnspentOutputs) TruncateDB() error

type UnspentOutputsInterface

type UnspentOutputsInterface interface {
	InitDB() error
	TruncateDB() error
	ForEach(callback ForEachKeyIteratorInterface) error
	GetCount() (int, error)

	GetDataForTransaction(txID []byte) ([]byte, error)
	DeleteDataForTransaction(txID []byte) error
	PutDataForTransaction(txID []byte, txData []byte) error
}

Jump to

Keyboard shortcuts

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