Documentation ¶
Index ¶
- Constants
- func GetDBManagerMock() mockMySQLDBManager
- func NewBucketNotFoundDBError() error
- func NewConfigDBError(err string) error
- func NewDBCursorStopError() error
- func NewDBError(err string, kind string) error
- func NewDBIsNotReadyError() error
- func NewHashDBError(err string) error
- func NewHashEmptyDBError() error
- func NewHashNotFoundDBError(err string) error
- func NewNotFoundDBError(kind string) error
- func NewRowNotFoundDBError(err string) error
- func Quote(s string) string
- type Blockchain
- func (bc *Blockchain) AddToChain(hash, prevHash []byte) error
- func (bc *Blockchain) BlockInChain(hash []byte) (bool, error)
- func (bc *Blockchain) CheckBlockExists(hash []byte) (bool, error)
- func (bc *Blockchain) DeleteBlock(hash []byte) error
- func (bc *Blockchain) GetBlock(hash []byte) ([]byte, error)
- func (bc *Blockchain) GetFirstHash() ([]byte, error)
- func (bc *Blockchain) GetLocationInChain(hash []byte) (bool, []byte, []byte, error)
- func (bc *Blockchain) GetTopBlock() ([]byte, error)
- func (bc *Blockchain) GetTopHash() ([]byte, error)
- func (bc *Blockchain) InitDB() error
- func (bc *Blockchain) PutBlock(hash []byte, blockdata []byte) error
- func (bc *Blockchain) PutBlockOnTop(hash []byte, blockdata []byte) error
- func (bc *Blockchain) RemoveFromChain(hash []byte) error
- func (bc *Blockchain) SaveFirstHash(hash []byte) error
- func (bc *Blockchain) SaveTopHash(hash []byte) error
- type BlockchainInterface
- type DBError
- type DBManager
- type DBQueryManager
- type DataReferencesaInterface
- type DatabaseConfig
- type DatabaseConnection
- type DatabaseLocker
- type ForEachKeyIteratorInterface
- type MySQLDB
- func (bdb *MySQLDB) Close() error
- func (bdb *MySQLDB) CreateTable(table string, keytype string, valuetype string) error
- func (bdb *MySQLDB) Delete(table string, k []byte) error
- func (bdb *MySQLDB) Get(table string, k []byte) ([]byte, error)
- func (bdb *MySQLDB) GetAll(table string) ([][][]byte, error)
- func (bdb *MySQLDB) Put(table string, k, v []byte) error
- func (bdb *MySQLDB) Truncate(table string) error
- type MySQLDBManager
- func (bdm *MySQLDBManager) CheckConnection() error
- func (bdm *MySQLDBManager) CheckDBExists() (bool, error)
- func (bdm *MySQLDBManager) CloseConnection() error
- func (bdm *MySQLDBManager) Dump(file string) error
- func (bdm MySQLDBManager) ExecuteSQL(sql string) error
- func (bdm MySQLDBManager) ExecuteSQLCountInTable(table string) (int, error)
- func (bdm MySQLDBManager) ExecuteSQLExplain(sql string) (r SQLExplainInfo, err error)
- func (bdm MySQLDBManager) ExecuteSQLNextKeyValue(table string) (string, error)
- func (bdm MySQLDBManager) ExecuteSQLPrimaryKey(table string) (column string, err error)
- func (bdm MySQLDBManager) ExecuteSQLRowByKey(table string, priKeyVal string) (data map[string]string, err error)
- func (bdm MySQLDBManager) ExecuteSQLSelectRow(sqlcommand string) (data map[string]string, err error)
- func (bdm MySQLDBManager) ExecuteSQLSelectRows(sqlcommand string) (data []resultRow, err error)
- func (bdm MySQLDBManager) ExecuteSQLTableDump(table string, limit int, offset int) (list []string, err error)
- func (bdm *MySQLDBManager) GetBlockchainObject() (BlockchainInterface, error)
- func (bdm *MySQLDBManager) GetDataReferencesObject() (DataReferencesaInterface, error)
- func (bdm *MySQLDBManager) GetLockerObject() DatabaseLocker
- func (bdm *MySQLDBManager) GetNodesObject() (NodesInterface, error)
- func (bdm *MySQLDBManager) GetTransactionsObject() (TranactionsInterface, error)
- func (bdm *MySQLDBManager) GetUnapprovedTransactionsObject() (UnapprovedTransactionsInterface, error)
- func (bdm *MySQLDBManager) GetUnspentOutputsObject() (UnspentOutputsInterface, error)
- func (bdm *MySQLDBManager) InitDatabase() error
- func (bdm *MySQLDBManager) IsConnectionOpen() bool
- func (bdm *MySQLDBManager) OpenConnection() error
- func (bdm *MySQLDBManager) QM() DBQueryManager
- func (bdm *MySQLDBManager) Restore(file string) error
- func (bdm *MySQLDBManager) SetConfig(config DatabaseConfig) error
- func (bdm *MySQLDBManager) SetLockerObject(lockerobj DatabaseLocker)
- func (bdm *MySQLDBManager) SetLogger(logger *utils.LoggerMan) error
- type Nodes
- type NodesInterface
- type SQLExplainInfo
- type Tranactions
- func (txs *Tranactions) DeleteTXSpentData(txID []byte) error
- func (txs *Tranactions) DeleteTXToBlockLink(txID []byte) error
- func (txs *Tranactions) GetBlockHashForTX(txID []byte) ([]byte, error)
- func (txs *Tranactions) GetTXSpentOutputs(txID []byte) ([]byte, error)
- func (txs *Tranactions) InitDB() error
- func (txs *Tranactions) PutTXSpentOutputs(txID []byte, outputs []byte) error
- func (txs *Tranactions) PutTXToBlockLink(txID []byte, blockHash []byte) error
- func (txs *Tranactions) TruncateDB() error
- type TranactionsInterface
- type UnapprovedTransactions
- func (uts *UnapprovedTransactions) DeleteTransaction(txID []byte) error
- func (uts *UnapprovedTransactions) ForEach(callback ForEachKeyIteratorInterface) error
- func (uts *UnapprovedTransactions) GetAll() ([][][]byte, error)
- func (uts *UnapprovedTransactions) GetCount() (int, error)
- func (uts *UnapprovedTransactions) GetTransaction(txID []byte) ([]byte, error)
- func (uts *UnapprovedTransactions) InitDB() error
- func (uts *UnapprovedTransactions) PutTransaction(txID []byte, txdata []byte) error
- func (uts *UnapprovedTransactions) TruncateDB() error
- type UnapprovedTransactionsInterface
- type UnspentOutputs
- func (uos *UnspentOutputs) DeleteDataForTransaction(txID []byte) error
- func (uos *UnspentOutputs) ForEach(callback ForEachKeyIteratorInterface) error
- func (uos *UnspentOutputs) GetCount() (int, error)
- func (uos *UnspentOutputs) GetDataForTransaction(txID []byte) ([]byte, error)
- func (uos *UnspentOutputs) InitDB() error
- func (uos *UnspentOutputs) PutDataForTransaction(txID []byte, txData []byte) error
- func (uos *UnspentOutputs) TruncateDB() error
- type UnspentOutputsInterface
Constants ¶
const ( ClassNameNodes = "nodes" ClassNameBlockchain = "blockchain" ClassNameTransactions = "transactions" ClassNameUnapprovedTransactions = "unapprovedtransactions" ClassNameUnspentOutputs = "unspentoutputs" )
const DBConfigError = "rownotfound"
const DBCursorBreak = "cursorbreak"
const DBHashEmptyError = "hashisemptyd"
const DBHashError = "hashemptyd"
const DBHashNotFoundError = "hashnotfound"
const DBRowNotFoundError = "rownotfound"
const TXVerifyErrorNoInput = "noinput"
Variables ¶
This section is empty.
Functions ¶
func GetDBManagerMock ¶
func GetDBManagerMock() mockMySQLDBManager
func NewBucketNotFoundDBError ¶
func NewBucketNotFoundDBError() error
func NewConfigDBError ¶
func NewDBCursorStopError ¶
func NewDBCursorStopError() error
func NewDBError ¶
func NewDBIsNotReadyError ¶
func NewDBIsNotReadyError() error
func NewHashDBError ¶
func NewHashEmptyDBError ¶
func NewHashEmptyDBError() error
func NewHashNotFoundDBError ¶
func NewNotFoundDBError ¶
func NewRowNotFoundDBError ¶
Types ¶
type Blockchain ¶
type Blockchain struct { DB *MySQLDB // contains filtered or unexported fields }
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 ¶
Finds if a hash is in the main chain, returns previous and next hash if it has
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 DBError ¶
type DBError struct {
// contains filtered or unexported fields
}
func (*DBError) IsRowNotFound ¶
type DBManager ¶
type DBManager interface { QM() DBQueryManager // get QueryManager object SetConfig(config DatabaseConfig) error SetLogger(logger *utils.LoggerMan) error GetLockerObject() DatabaseLocker SetLockerObject(lockerobj DatabaseLocker) InitDatabase() error CheckDBExists() (bool, error) CheckConnection() error OpenConnection() error CloseConnection() error IsConnectionOpen() bool GetBlockchainObject() (BlockchainInterface, error) GetTransactionsObject() (TranactionsInterface, error) GetUnapprovedTransactionsObject() (UnapprovedTransactionsInterface, error) GetUnspentOutputsObject() (UnspentOutputsInterface, error) GetNodesObject() (NodesInterface, error) GetDataReferencesObject() (DataReferencesaInterface, error) }
type DBQueryManager ¶
type DBQueryManager interface { Dump(file string) error Restore(file string) error ExecuteSQL(sql string) error ExecuteSQLExplain(sql string) (SQLExplainInfo, error) ExecuteSQLPrimaryKey(table string) (string, error) ExecuteSQLNextKeyValue(table string) (string, error) ExecuteSQLSelectRow(sqlcommand string) (data map[string]string, err error) ExecuteSQLSelectRows(sqlcommand string) (data []resultRow, err error) ExecuteSQLTableDump(table string, limit int, offset int) ([]string, error) ExecuteSQLCountInTable(table string) (int, error) }
type DataReferencesaInterface ¶
type DataReferencesaInterface interface { InitDB() error TruncateDB() error SetTXForRefID(RefID []byte, txID []byte) error GetTXForRefID(RefID []byte) ([]byte, error) DeleteRefID(RefID []byte) error }
this is interface for DB of connects of SQL refernces to transactions It keeps last transaction in a chain where a DB table row was updated
type DatabaseConfig ¶
type DatabaseConfig struct { MysqlHost string MysqlPort int MysqlSocket string DatabaseName string DbUser string DbPassword string TablesPrefix string }
func (*DatabaseConfig) GetMySQLConnString ¶
func (dbc *DatabaseConfig) GetMySQLConnString() string
func (*DatabaseConfig) GetServerAddress ¶
func (dbc *DatabaseConfig) GetServerAddress() string
func (*DatabaseConfig) HasMinimum ¶
func (dbc *DatabaseConfig) HasMinimum() bool
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 MySQLDB ¶
func (*MySQLDB) CreateTable ¶
create key value table
type MySQLDBManager ¶
type MySQLDBManager struct { Logger *utils.LoggerMan Config DatabaseConfig SessID string // contains filtered or unexported fields }
func (*MySQLDBManager) CheckConnection ¶
func (bdm *MySQLDBManager) CheckConnection() error
try to set up a connection to DB. and close it then
func (*MySQLDBManager) CheckDBExists ¶
func (bdm *MySQLDBManager) CheckDBExists() (bool, error)
Check if database was already inited
func (*MySQLDBManager) CloseConnection ¶
func (bdm *MySQLDBManager) CloseConnection() error
func (*MySQLDBManager) Dump ¶
func (bdm *MySQLDBManager) Dump(file string) error
func (MySQLDBManager) ExecuteSQL ¶
func (bdm MySQLDBManager) ExecuteSQL(sql string) error
execute query.
func (MySQLDBManager) ExecuteSQLCountInTable ¶
func (bdm MySQLDBManager) ExecuteSQLCountInTable(table string) (int, error)
Get count of rows in table
func (MySQLDBManager) ExecuteSQLExplain ¶
func (bdm MySQLDBManager) ExecuteSQLExplain(sql string) (r SQLExplainInfo, err error)
execute EXPLAIN query to check if sql query is correct and what is type and which table it affects
func (MySQLDBManager) ExecuteSQLNextKeyValue ¶
func (bdm MySQLDBManager) ExecuteSQLNextKeyValue(table string) (string, error)
Return next auto_increment before query executed
func (MySQLDBManager) ExecuteSQLPrimaryKey ¶
func (bdm MySQLDBManager) ExecuteSQLPrimaryKey(table string) (column string, err error)
get primary key column name for a table
func (MySQLDBManager) ExecuteSQLRowByKey ¶
func (bdm MySQLDBManager) ExecuteSQLRowByKey(table string, priKeyVal string) (data map[string]string, err error)
get row by table name and primary key value
func (MySQLDBManager) ExecuteSQLSelectRow ¶
func (bdm MySQLDBManager) ExecuteSQLSelectRow(sqlcommand string) (data map[string]string, err error)
get single row as a map
func (MySQLDBManager) ExecuteSQLSelectRows ¶
func (bdm MySQLDBManager) ExecuteSQLSelectRows(sqlcommand string) (data []resultRow, err error)
get all rows as array of maps
func (MySQLDBManager) ExecuteSQLTableDump ¶
func (bdm MySQLDBManager) ExecuteSQLTableDump(table string, limit int, offset int) (list []string, err error)
Return list of SQL queries as part of dump If offset is 0 we retrn table create SQL comand too
func (*MySQLDBManager) GetBlockchainObject ¶
func (bdm *MySQLDBManager) GetBlockchainObject() (BlockchainInterface, error)
returns BlockChain Database structure. does all init
func (*MySQLDBManager) GetDataReferencesObject ¶
func (bdm *MySQLDBManager) GetDataReferencesObject() (DataReferencesaInterface, error)
func (*MySQLDBManager) GetLockerObject ¶
func (bdm *MySQLDBManager) GetLockerObject() DatabaseLocker
func (*MySQLDBManager) GetNodesObject ¶
func (bdm *MySQLDBManager) GetNodesObject() (NodesInterface, error)
returns Nodes Database structure. does al init
func (*MySQLDBManager) GetTransactionsObject ¶
func (bdm *MySQLDBManager) GetTransactionsObject() (TranactionsInterface, error)
returns Transaction Index Database structure. does al init
func (*MySQLDBManager) GetUnapprovedTransactionsObject ¶
func (bdm *MySQLDBManager) GetUnapprovedTransactionsObject() (UnapprovedTransactionsInterface, error)
returns Unapproved Transaction Database structure. does al init
func (*MySQLDBManager) GetUnspentOutputsObject ¶
func (bdm *MySQLDBManager) GetUnspentOutputsObject() (UnspentOutputsInterface, error)
returns Unspent Transactions Database structure. does al init
func (*MySQLDBManager) InitDatabase ¶
func (bdm *MySQLDBManager) InitDatabase() error
create empty database. must create all creates tables for BC
func (*MySQLDBManager) IsConnectionOpen ¶
func (bdm *MySQLDBManager) IsConnectionOpen() bool
func (*MySQLDBManager) OpenConnection ¶
func (bdm *MySQLDBManager) OpenConnection() error
set status of connection to open
func (*MySQLDBManager) QM ¶
func (bdm *MySQLDBManager) QM() DBQueryManager
func (*MySQLDBManager) Restore ¶
func (bdm *MySQLDBManager) Restore(file string) error
func (*MySQLDBManager) SetConfig ¶
func (bdm *MySQLDBManager) SetConfig(config DatabaseConfig) error
func (*MySQLDBManager) SetLockerObject ¶
func (bdm *MySQLDBManager) SetLockerObject(lockerobj DatabaseLocker)
type Nodes ¶
type Nodes struct { DB *MySQLDB // contains filtered or unexported fields }
func (*Nodes) DeleteNode ¶
func (*Nodes) ForEach ¶
func (ns *Nodes) ForEach(callback ForEachKeyIteratorInterface) error
retrns nodes list iterator
type NodesInterface ¶
type SQLExplainInfo ¶
type Tranactions ¶
type Tranactions struct { DB *MySQLDB // contains filtered or unexported fields }
func (*Tranactions) DeleteTXSpentData ¶
func (txs *Tranactions) DeleteTXSpentData(txID []byte) error
Delete info about spent outputs for TX
func (*Tranactions) DeleteTXToBlockLink ¶
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) PutTXSpentOutputs ¶
func (txs *Tranactions) PutTXSpentOutputs(txID []byte, outputs []byte) error
Save spent outputs for TX
func (*Tranactions) PutTXToBlockLink ¶
func (txs *Tranactions) PutTXToBlockLink(txID []byte, blockHash []byte) error
Save link between TX and block hash
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 *MySQLDB // contains filtered or unexported fields }
func (*UnapprovedTransactions) DeleteTransaction ¶
func (uts *UnapprovedTransactions) DeleteTransaction(txID []byte) error
delete transation from DB
func (*UnapprovedTransactions) ForEach ¶
func (uts *UnapprovedTransactions) ForEach(callback ForEachKeyIteratorInterface) error
execute functon for each key/value in the bucket
func (*UnapprovedTransactions) GetAll ¶
func (uts *UnapprovedTransactions) GetAll() ([][][]byte, error)
Get all records as single request
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
Init DB. create table
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) GetAll() ([][][]byte, error) GetTransaction(txID []byte) ([]byte, error) PutTransaction(txID []byte, txdata []byte) error DeleteTransaction(txID []byte) error }
type UnspentOutputs ¶
type UnspentOutputs struct { DB *MySQLDB // contains filtered or unexported fields }
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) 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 }