ethdb

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const AccountRollback = `` /* 171-byte string literal not displayed */

AccountRollBack - finds the relevant account and reverses the balance and nonce

View Source
const BlockRollback = `
DELETE FROM blocks WHERE hash = ANY($1);
`

BlockRollback - deletes all blocks whose hash is contained in the array of blockheaders

View Source
const CreateInternalTxTableStmnt = `` /* 191-byte string literal not displayed */

Creates an internal transaction records in the internal tx table

View Source
const CreateTxTableStmnt = `` /* 299-byte string literal not displayed */

Creates a transaction record in the tx table

View Source
const FindOrCreateAcctBlockStmnt = `` /* 434-byte string literal not displayed */

FindOrCreateAcctBlockStmnt - query to find or create an accountblock record returning

View Source
const FindOrCreateAcctBlockStmntForInternals = `` /* 451-byte string literal not displayed */

FindOrCreateAcctBlockStmntForInternals - query to find or create an accountblock record returning

View Source
const FindOrCreateAcctBlockStmntToAddr = `` /* 434-byte string literal not displayed */

FindOrCreateAcctBlockStmnt - query to find or create an accountblock record returning

View Source
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

View Source
const IdealBatchSize = 100 * 1024

Code using batches should try to add this much data to the batch. The value was determined empirically.

View Source
const InternalTransactionRollback = `
DELETE FROM internaltxs WHERE blockhash = ANY($1);
`

InternalTransactionRollback - deletes all transactions whose blockhash is contained in the array of blockheaders

View Source
const TransactionRollback = `
DELETE FROM txs WHERE blockhash = ANY($1);
`

TransactionRollback - deletes all transactions whose blockhash is contained in the array of blockheaders

View Source
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

View Source
const UpdateToBalanceNonce = `` /* 290-byte string literal not displayed */

Variables

View Source
var OpenFileLimit = 64
View Source
var TestDbInstances []string

Functions

func AssignTestDbInstanceName

func AssignTestDbInstanceName() string

AssignTestDbInstanceName - returns a Db Name for testing

func Connect

func Connect(connectURL string) *sqlx.DB

Connect - return a connection to a postgres database wi

func ConnectionStr

func ConnectionStr() string

ConnectionStr - return a Connection to the PG admin database

func CreatePgDb

func CreatePgDb(dbName string)

CreatePgDb - Creates a DB

func DbExists

func DbExists(dbname string) (bool, error)

DbExists - Checks whether the named database exists returns true or false

func DbName

func DbName() string

DbName - gets the correct db name based on the environment

func DeletePgDb

func DeletePgDb(dbName string)

DeletePgDb - Deletes the designated DB

func InitDB

func InitDB(flag bool) (*sqlx.DB, error)

InitDB - initializes a Postgresql Database for use by the Blockexplorer

func InnerSGetAccount

func InnerSGetAccount(db *SPGDatabase, address string) (stypes.SAccounts, bool)

func MakeTableQuery

func MakeTableQuery() string

MakeTableQuery - returns sql to create db tables

func SGetAccount

func SGetAccount(address string) (string, error)

GetAccount returns account balances

func SGetAccountTxs

func SGetAccountTxs(address string) (string, error)

GetAccount returns account balances

func SGetAllAccountBlocks

func SGetAllAccountBlocks() (string, error)

func SGetAllAccounts

func SGetAllAccounts() (string, error)

GetAllAccounts returns all accounts and balances

func SGetAllBlocks

func SGetAllBlocks() (string, error)

func SGetAllBlocksMinedByAddress

func SGetAllBlocksMinedByAddress(coinbase string) (string, error)

func SGetAllInternalTransactions

func SGetAllInternalTransactions() (string, error)

GetAllInternalTransactions getter fn for API

func SGetAllTransactions

func SGetAllTransactions() (string, error)

GetAllTransactions getter fn for API

func SGetAllTransactionsFromBlock

func SGetAllTransactionsFromBlock(blockNumber string) (string, error)

func SGetBlock

func SGetBlock(blockNumber string) (string, error)

GetBlock queries to send single block info TODO provide blockHash arg passed from handler.go

func SGetInternalTransaction

func SGetInternalTransaction(txHash string) (string, error)

GetInternalTransaction fn returns single tx

func SGetRecentBlock

func SGetRecentBlock() (string, error)

func SGetTransaction

func SGetTransaction(txHash string) (string, error)

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

func NewTableBatch(db Database, prefix string) Batch

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.

func NewTable

func NewTable(db Database, prefix string) Database

NewTable returns a Database object that prefixes all keys with a given string.

type Deleter

type Deleter interface {
	Delete(key []byte) error
}

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) Has

func (db *LDBDatabase) Has(key []byte) (bool, error)

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.

func (*LDBDatabase) Put

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

Put puts the given key / value to the queue

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) Get

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

func (*MemDatabase) Has

func (db *MemDatabase) Has(key []byte) (bool, 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

func (*MemDatabase) Put

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

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

type Putter interface {
	Put(key []byte, value []byte) error
}

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

func (db *SPGDatabase) UpdateMinerAccount(addr string, blockHash string, reward *big.Int) error

updateMinerAccount updates account in Postgres Db

Jump to

Keyboard shortcuts

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