databasemp

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 3 Imported by: 0

README

Mempool Persistence Database (MPDB)

Introduction

Mempool Persistence Database is a leveldb, which seperated from the main leveldb. This database only store transactions in mempool.

Transactions in mempool is stored in Memory (RAM), they will be erased when node is turned off or crashed. So, MPDB is used to stored current transactions in mempool. If transaction is removed in mempool for any reason, it will be removed out of mpdb as well.

This feature can be turn on and off by using config.

Feature

  • Add Transaction: add transaction to database
  • Remove Transaction: remove transaction out of database
  • Has Transaction: check transaction existence
  • Reset: delete all transactions in database
  • Load: load all transaction from database into memory

Documentation

Index

Constants

View Source
const (
	DriverExistErr = iota
	DriverNotRegisterErr

	// LevelDB
	OpenDbErr
	NotExistValue
	LvDbNotFound

	// BlockChain err
	NotImplHashMethod
	UnexpectedError
	KeyExisted
)

Variables

View Source
var ErrCodeMessage = map[int]struct {
	code    int
	message string
}{

	DriverExistErr:       {-1000, "Driver is already registered"},
	DriverNotRegisterErr: {-1001, "Driver is not registered"},

	OpenDbErr:     {-2000, "Open database error"},
	NotExistValue: {-2001, "H is not existed"},
	LvDbNotFound:  {-2002, "lvdb not found"},

	NotImplHashMethod: {-3000, "Data does not implement this method"},
	UnexpectedError:   {-3002, "Unexpected error"},
	KeyExisted:        {-3003, "PubKey already existed in database"},
}
View Source
var Logger = DBMemmpoolLogger{}

Global instant to use

Functions

func RegisterDriver

func RegisterDriver(d Driver) error

RegisterDriver registers the driver d.

Types

type DBMemmpoolLogger

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

func (*DBMemmpoolLogger) Init

func (dbLogger *DBMemmpoolLogger) Init(inst common.Logger)

type DatabaseInterface

type DatabaseInterface interface {
	Put(key, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	HasValue(key []byte) (bool, error)

	AddTransaction(txHash *common.Hash, txType string, valueTx []byte, valueDesc []byte) error
	RemoveTransaction(key *common.Hash) error
	GetTransaction(key *common.Hash) ([]byte, error)
	HasTransaction(key *common.Hash) (bool, error)
	Reset() error
	Load() ([][]byte, [][]byte, error)

	Close() error
}

func Open

func Open(typ string, args ...interface{}) (DatabaseInterface, error)

Open opens the db connection.

type DatabaseMempoolError

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

func NewDatabaseMempoolError

func NewDatabaseMempoolError(key int, err error) *DatabaseMempoolError

func (DatabaseMempoolError) Error

func (e DatabaseMempoolError) Error() string

func (DatabaseMempoolError) GetErrorCode

func (e DatabaseMempoolError) GetErrorCode() int

type Driver

type Driver struct {
	DbType string
	Open   func(args ...interface{}) (DatabaseInterface, error)
}

Driver defines a structure for backend drivers to use when they registered themselves as a backend which implements the DatabaseInterface interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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