Documentation
¶
Index ¶
- Constants
- Variables
- func AssignTestDbInstanceName() string
- func Connect(connectURL string) *sqlx.DB
- func ConnectionStr() string
- func CreatePgDb(dbName string)
- func DbExists(dbname string) (bool, error)
- func DbName() string
- func DeletePgDb(dbName string)
- func InitDB(flag bool) (*sqlx.DB, error)
- func InnerSGetAccount(db *SPGDatabase, address string) (stypes.SAccounts, bool)
- func MakeTableQuery() string
- func SGetAccount(address string) (string, error)
- func SGetAccountTxs(address string) (string, error)
- func SGetAllAccountBlocks() (string, error)
- func SGetAllAccounts() (string, error)
- func SGetAllBlocks() (string, error)
- func SGetAllBlocksMinedByAddress(coinbase string) (string, error)
- func SGetAllInternalTransactions() (string, error)
- func SGetAllTransactions() (string, error)
- func SGetAllTransactionsFromBlock(blockNumber string) (string, error)
- func SGetBlock(blockNumber string) (string, error)
- func SGetInternalTransaction(txHash string) (string, error)
- func SGetRecentBlock() (string, error)
- func SGetTransaction(txHash string) (string, error)
- func ShyftConnectStr() string
- type Account
- type AccountBlock
- type AccountBlockArray
- type Batch
- type Block
- type Database
- type Deleter
- type LDBDatabase
- func (db *LDBDatabase) Close()
- func (db *LDBDatabase) Delete(key []byte) error
- func (db *LDBDatabase) Get(key []byte) ([]byte, error)
- func (db *LDBDatabase) Has(key []byte) (bool, error)
- func (db *LDBDatabase) LDB() *leveldb.DB
- func (db *LDBDatabase) Meter(prefix string)
- func (db *LDBDatabase) NewBatch() Batch
- func (db *LDBDatabase) NewIterator() iterator.Iterator
- func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
- func (db *LDBDatabase) Path() string
- func (db *LDBDatabase) Put(key []byte, value []byte) error
- type MemDatabase
- func (db *MemDatabase) Close()
- func (db *MemDatabase) Delete(key []byte) error
- func (db *MemDatabase) Get(key []byte) ([]byte, error)
- func (db *MemDatabase) Has(key []byte) (bool, error)
- func (db *MemDatabase) Keys() [][]byte
- func (db *MemDatabase) Len() int
- func (db *MemDatabase) NewBatch() Batch
- func (db *MemDatabase) Put(key []byte, value []byte) error
- type PgTransaction
- type Putter
- type SDatabase
- type SPGDatabase
- func (db *SPGDatabase) AccountExists(addr string) (string, string, error)
- func (db *SPGDatabase) BlockExists(hash string) bool
- func (db *SPGDatabase) CreateAccount(addr string, balance string, nonce string) error
- func (db *SPGDatabase) InsertBlock(blockData stypes.SBlock)
- func (db *SPGDatabase) InsertInternals(i stypes.InteralWrite) error
- func (db *SPGDatabase) InsertTx(txData stypes.ShyftTxEntryPretty) error
- func (db *SPGDatabase) IsContract(addr string) bool
- func (db *SPGDatabase) RollbackPgDb(blockheaders []string) error
- func (db *SPGDatabase) Transact(txFunc func(*sqlx.Tx) error) (err error)
- func (db *SPGDatabase) TruncateTables()
- func (db *SPGDatabase) UpdateMinerAccount(addr string, blockHash string, reward *big.Int) error
Constants ¶
const AccountRollback = `` /* 171-byte string literal not displayed */
AccountRollBack - finds the relevant account and reverses the balance and nonce
const BlockRollback = `
DELETE FROM blocks WHERE hash = ANY($1);
`
BlockRollback - deletes all blocks whose hash is contained in the array of blockheaders
const CreateInternalTxTableStmnt = `` /* 191-byte string literal not displayed */
Creates an internal transaction records in the internal tx table
const CreateTxTableStmnt = `` /* 299-byte string literal not displayed */
Creates a transaction record in the tx table
const FindOrCreateAcctBlockStmnt = `` /* 434-byte string literal not displayed */
FindOrCreateAcctBlockStmnt - query to find or create an accountblock record returning
const FindOrCreateAcctBlockStmntForInternals = `` /* 451-byte string literal not displayed */
FindOrCreateAcctBlockStmntForInternals - query to find or create an accountblock record returning
const FindOrCreateAcctBlockStmntToAddr = `` /* 434-byte string literal not displayed */
FindOrCreateAcctBlockStmnt - query to find or create an accountblock record returning
const FindOrCreateAcctStmnt = `
INSERT INTO accounts(addr, balance, nonce) VALUES($1, $2, $3)
ON CONFLICT ON CONSTRAINT accounts_pkey DO NOTHING;
`
FindOrCreateAcctStmnt - query to create account if it doesnt exist - and return it if it does Parameters are addr = $1 balance = $2 nonce = $3
const IdealBatchSize = 100 * 1024
Code using batches should try to add this much data to the batch. The value was determined empirically.
const InternalTransactionRollback = `
DELETE FROM internaltxs WHERE blockhash = ANY($1);
`
InternalTransactionRollback - deletes all transactions whose blockhash is contained in the array of blockheaders
const TransactionRollback = `
DELETE FROM txs WHERE blockhash = ANY($1);
`
TransactionRollback - deletes all transactions whose blockhash is contained in the array of blockheaders
const UpdateBalanceNonce = `` /* 292-byte string literal not displayed */
UpdateBalanceNonce - query to update the balance and nonce for a transaction Parameters are addr = $1 amount = $2
const UpdateToBalanceNonce = `` /* 290-byte string literal not displayed */
Variables ¶
var OpenFileLimit = 64
var TestDbInstances []string
Functions ¶
func AssignTestDbInstanceName ¶
func AssignTestDbInstanceName() string
AssignTestDbInstanceName - returns a Db Name for testing
func ConnectionStr ¶
func ConnectionStr() string
ConnectionStr - return a Connection to the PG admin database
func InnerSGetAccount ¶
func InnerSGetAccount(db *SPGDatabase, address string) (stypes.SAccounts, bool)
func SGetAccount ¶
GetAccount returns account balances
func SGetAccountTxs ¶
GetAccount returns account balances
func SGetAllAccountBlocks ¶
func SGetAllAccounts ¶
GetAllAccounts returns all accounts and balances
func SGetAllBlocks ¶
func SGetAllInternalTransactions ¶
GetAllInternalTransactions getter fn for API
func SGetAllTransactions ¶
GetAllTransactions getter fn for API
func SGetBlock ¶
GetBlock queries to send single block info TODO provide blockHash arg passed from handler.go
func SGetInternalTransaction ¶
GetInternalTransaction fn returns single tx
func SGetRecentBlock ¶
func SGetTransaction ¶
GetTransaction fn returns single tx
func ShyftConnectStr ¶
func ShyftConnectStr() string
ShyftConnectStr - Returns the Connection String With The appropriate database
Types ¶
type Account ¶
type Account struct { Addr string `db:"addr"` Balance string `db:"balance"` Nonce uint64 `db:"nonce"` }
Account - - struct for reading and writing database data
type AccountBlock ¶
type AccountBlock struct { Acct string `db:"acct"` Blockhash string `db:"blockhash"` Delta int64 `db:"delta"` TxCount int64 `db:"txcount"` }
AccountBlock - struct for reading and writing database data
type AccountBlockArray ¶
type AccountBlockArray struct {
AccountBlocks []AccountBlock
}
type Batch ¶
type Batch interface { Putter Deleter ValueSize() int // amount of data in the batch Write() error // Reset resets the batch for reuse Reset() }
Batch is a write-only database that commits changes to its host database when Write is called. Batch cannot be used concurrently.
func NewTableBatch ¶
NewTableBatch returns a Batch object which prefixes all keys with a given string.
type Block ¶
type Block struct { Hash string `db:"hash"` Coinbase string `db:"coinbase"` GasUsed int64 `db:"gasused"` GasLimit int64 `db:"gaslimit"` TxCount int64 `db:"txcount"` UncleCount int64 `db:"unclecount"` Age time.Time `db:"age"` ParentHash string `db:"parenthash"` UncleHash string `db:"unclehash"` Difficulty string `db:"difficulty"` Size string `db:"size"` Nonce int64 `db:"nonce"` Rewards string `db:"rewards"` Number string `db:"number"` }
Block - - struct for reading and writing database data
type Database ¶
type Database interface { Putter Deleter Get(key []byte) ([]byte, error) Has(key []byte) (bool, error) Close() NewBatch() Batch }
Database wraps all database operations. All methods are safe for concurrent use.
type Deleter ¶
Deleter wraps the database delete operation supported by both batches and regular databases.
type LDBDatabase ¶
type LDBDatabase struct {
// contains filtered or unexported fields
}
func NewLDBDatabase ¶
func NewLDBDatabase(file string, cache int, handles int) (*LDBDatabase, error)
NewLDBDatabase returns a LevelDB wrapped object.
func (*LDBDatabase) Close ¶
func (db *LDBDatabase) Close()
func (*LDBDatabase) Delete ¶
func (db *LDBDatabase) Delete(key []byte) error
Delete deletes the key from the queue and database
func (*LDBDatabase) Get ¶
func (db *LDBDatabase) Get(key []byte) ([]byte, error)
Get returns the given key if it's present.
func (*LDBDatabase) LDB ¶
func (db *LDBDatabase) LDB() *leveldb.DB
func (*LDBDatabase) Meter ¶
func (db *LDBDatabase) Meter(prefix string)
Meter configures the database metrics collectors and
func (*LDBDatabase) NewBatch ¶
func (db *LDBDatabase) NewBatch() Batch
func (*LDBDatabase) NewIterator ¶
func (db *LDBDatabase) NewIterator() iterator.Iterator
func (*LDBDatabase) NewIteratorWithPrefix ¶
func (db *LDBDatabase) NewIteratorWithPrefix(prefix []byte) iterator.Iterator
NewIteratorWithPrefix returns a iterator to iterate over subset of database content with a particular prefix.
func (*LDBDatabase) Path ¶
func (db *LDBDatabase) Path() string
Path returns the path to the database directory.
type MemDatabase ¶
type MemDatabase struct {
// contains filtered or unexported fields
}
* This is a test memory database. Do not use for any production it does not get persisted
func NewMemDatabase ¶
func NewMemDatabase() *MemDatabase
func NewMemDatabaseWithCap ¶
func NewMemDatabaseWithCap(size int) *MemDatabase
func (*MemDatabase) Close ¶
func (db *MemDatabase) Close()
func (*MemDatabase) Delete ¶
func (db *MemDatabase) Delete(key []byte) error
func (*MemDatabase) Keys ¶
func (db *MemDatabase) Keys() [][]byte
func (*MemDatabase) Len ¶
func (db *MemDatabase) Len() int
func (*MemDatabase) NewBatch ¶
func (db *MemDatabase) NewBatch() Batch
type PgTransaction ¶
type PgTransaction struct { TxHash string `db:"txhash"` To string `db:"to_addr"` From string `db:"from_addr"` Blockhash string `db:"blockhash"` Blocknumber string `db:"blocknumber"` Amount string `db:"amount"` Gasprice uint64 `db:"gasprice"` Gas uint64 `db:"gas"` GasLimit uint64 `db:"gaslimit"` TxFee string `db:"txfee"` Nonce uint64 `db:"nonce"` TxStatus string `db:"txstatus"` IsContract bool `db:"iscontract"` Age time.Time `db:"age"` Data []byte `db:"data"` }
PgTransaction struct for scanning db transactions from table txs
type Putter ¶
Putter wraps the database write operation supported by both batches and regular databases.
type SDatabase ¶
type SDatabase interface { AccountExists(addr string) (string, string, error) BlockExists(hash string) bool IsContract(addr string) bool CreateAccount(addr string, balance string, nonce string) error UpdateMinerAccount(addr string, blockHash string, reward *big.Int) error InsertBlock(blockData stypes.SBlock) InsertTx(txData stypes.ShyftTxEntryPretty) error InsertInternals(i stypes.InteralWrite) error RollbackPgDb(blockheaders []string) error TruncateTables() }
type SPGDatabase ¶
type SPGDatabase struct {
// contains filtered or unexported fields
}
func NewShyftDatabase ¶
func NewShyftDatabase() (*SPGDatabase, error)
NewLDBDatabase returns a PostgresDB wrapped object.
func NewTestInstanceShyftDatabase ¶
func NewTestInstanceShyftDatabase() (*SPGDatabase, error)
func ReturnShyftDatabase ¶
func ReturnShyftDatabase() (*SPGDatabase, error)
func (*SPGDatabase) AccountExists ¶
func (db *SPGDatabase) AccountExists(addr string) (string, string, error)
func (*SPGDatabase) BlockExists ¶
func (db *SPGDatabase) BlockExists(hash string) bool
BlockExists checks if block exists in Postgres Db Refactor as a transaction
func (*SPGDatabase) CreateAccount ¶
func (db *SPGDatabase) CreateAccount(addr string, balance string, nonce string) error
CreateAccount writes new account to Postgres Db
func (*SPGDatabase) InsertBlock ¶
func (db *SPGDatabase) InsertBlock(blockData stypes.SBlock)
InsertBlock writes block to Postgres Db
func (*SPGDatabase) InsertInternals ¶
func (db *SPGDatabase) InsertInternals(i stypes.InteralWrite) error
InsertInternals - Inserts transactions to pg internaltxs and updates/creates accounts/accountblocks tables accordingly
func (*SPGDatabase) InsertTx ¶
func (db *SPGDatabase) InsertTx(txData stypes.ShyftTxEntryPretty) error
InsertTx writes tx to Postgres Db
func (*SPGDatabase) IsContract ¶
func (db *SPGDatabase) IsContract(addr string) bool
IsContract checks if toAddr is from a contract in Postgres Db
func (*SPGDatabase) RollbackPgDb ¶
func (db *SPGDatabase) RollbackPgDb(blockheaders []string) error
RollbackPgDb - rollsback the PG database by: deleting blocks designated by the passed in Blockheaders deleting all transactions contained in the foregoing Blockheaders reversing each account balance by the delta included in the account blocks table reversing the account nonce values by the transaction count included in the accountblocks table
func (*SPGDatabase) Transact ¶
func (db *SPGDatabase) Transact(txFunc func(*sqlx.Tx) error) (err error)
Transact - A wrapper around pg - transaction to allow a panic after a rollback
func (*SPGDatabase) TruncateTables ¶
func (db *SPGDatabase) TruncateTables()
TruncateTables - Is primarily user to clear the pg database between unit tests
func (*SPGDatabase) UpdateMinerAccount ¶
updateMinerAccount updates account in Postgres Db