database

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrArgInvalid      = errors.New("invalid argument")
	ErrExist           = errors.New("item already exists")
	ErrNoEvents        = errors.New("the times of pop event is more than push")
	ErrNotExist        = errors.New("item does not exist")
	ErrBigIntSetString = errors.New("big int setString error")
	ErrOutOfMemory     = errors.New("out of memory")
	ErrUnKnown         = errors.New("")
)
View Source
var (
	DRIVER_MYSQL = "mysql"
	HOST_MYSQL   = "root:123456@tcp(localhost:3306)/lemochain?charset=utf8mb4"
)
View Source
var (
	ContextKeyCurrentBlock = "context.chain.current_block"
)

Functions

func CreateDB

func CreateDB(db *sql.DB) (sql.Result, error)

func Del

func Del(db *sql.DB, key string) error

func ErrIsNotExist

func ErrIsNotExist(err error) bool

func GetAddressKey

func GetAddressKey(addr common.Address) []byte

func GetBlockHashKey

func GetBlockHashKey(hash common.Hash) []byte

func GetCanonicalKey

func GetCanonicalKey(height uint32) []byte

func GetStorageKey added in v1.2.0

func GetStorageKey(hash common.Hash) []byte

func NewAccountData

func NewAccountData(address common.Address) *types.AccountData

func Open

func Open(driver string, dbHost string) (*sql.DB, error)

driver = "mysql" dbHost = root:123123@tcp(localhost:3306)/lemochain?charset=utf8mb4

Types

type AccountDao

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

func NewAccountDao

func NewAccountDao(db DBEngine) *AccountDao

func (*AccountDao) Get

func (dao *AccountDao) Get(addr common.Address) (*types.AccountData, error)

func (*AccountDao) GetDB

func (dao *AccountDao) GetDB() *sql.DB

func (*AccountDao) Set

func (dao *AccountDao) Set(addr common.Address, account *types.AccountData) error

type AssetDao

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

func NewAssetDao

func NewAssetDao(db DBEngine) *AssetDao

func (*AssetDao) Get

func (dao *AssetDao) Get(code common.Hash) (*types.Asset, error)

func (*AssetDao) GetPage

func (dao *AssetDao) GetPage(addr common.Address, start, limit int) ([]*types.Asset, error)

func (*AssetDao) GetPageWithTotal

func (dao *AssetDao) GetPageWithTotal(addr common.Address, start, limit int) ([]*types.Asset, int, error)

func (*AssetDao) Set

func (dao *AssetDao) Set(asset *types.Asset) error

type AssetToken added in v1.2.2

type AssetToken struct {
	Id       common.Hash    `json:"assetId" gencodec:"required"`
	Code     common.Hash    `json:"assetCode" gencodec:"required"`
	Owner    common.Address `json:"owner" gencodec:"required"`
	MetaData string         `json:"metaData" gencodec:"required"`
}

func (AssetToken) MarshalJSON added in v1.2.2

func (a AssetToken) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*AssetToken) UnmarshalJSON added in v1.2.2

func (a *AssetToken) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type AssetTokenDao added in v1.2.2

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

func NewAssetTokenDao added in v1.2.2

func NewAssetTokenDao(db DBEngine) *AssetTokenDao

func (*AssetTokenDao) Get added in v1.2.2

func (dao *AssetTokenDao) Get(id common.Hash) (*AssetToken, error)

func (*AssetTokenDao) GetPage added in v1.2.2

func (dao *AssetTokenDao) GetPage(addr common.Address, start, limit int) ([]*AssetToken, error)

func (*AssetTokenDao) GetPageByCode added in v1.2.2

func (dao *AssetTokenDao) GetPageByCode(code common.Hash, start, limit int) ([]*AssetToken, error)

func (*AssetTokenDao) GetPageByCodeWithTotal added in v1.2.2

func (dao *AssetTokenDao) GetPageByCodeWithTotal(code common.Hash, start, limit int) ([]*AssetToken, int, error)

func (*AssetTokenDao) GetPageWithTotal added in v1.2.2

func (dao *AssetTokenDao) GetPageWithTotal(addr common.Address, start, limit int) ([]*AssetToken, int, error)

func (*AssetTokenDao) Set added in v1.2.2

func (dao *AssetTokenDao) Set(assetToken *AssetToken) error

type BlockDao

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

func NewBlockDao

func NewBlockDao(db DBEngine) *BlockDao

func (*BlockDao) GetBlock

func (dao *BlockDao) GetBlock(hash common.Hash) (*types.Block, error)

func (*BlockDao) GetBlockByHeight

func (dao *BlockDao) GetBlockByHeight(height uint32) (*types.Block, error)

func (*BlockDao) GetDB

func (dao *BlockDao) GetDB() *sql.DB

func (*BlockDao) IsExist

func (dao *BlockDao) IsExist(hash common.Hash) (bool, error)

func (*BlockDao) SetBlock

func (dao *BlockDao) SetBlock(hash common.Hash, block *types.Block) error

type CandidateDao

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

func NewCandidateDao

func NewCandidateDao(engine DBEngine) *CandidateDao

func (*CandidateDao) Del

func (dao *CandidateDao) Del(user common.Address) error

func (*CandidateDao) GetPage

func (dao *CandidateDao) GetPage(start, limit int) ([]*CandidateItem, error)

func (*CandidateDao) GetPageWithTotal

func (dao *CandidateDao) GetPageWithTotal(start, limit int) ([]*CandidateItem, int, error)

func (*CandidateDao) GetTop

func (dao *CandidateDao) GetTop(size int) ([]*CandidateItem, error)

func (*CandidateDao) Set

func (dao *CandidateDao) Set(item *CandidateItem) error

type CandidateItem

type CandidateItem struct {
	User  common.Address
	Votes *big.Int
}

type Context

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

type ContextDao

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

func NewContextDao

func NewContextDao(db DBEngine) *ContextDao

func (*ContextDao) ContextGet

func (dao *ContextDao) ContextGet(key string) ([]byte, error)

func (*ContextDao) ContextLoad

func (dao *ContextDao) ContextLoad() ([]*Context, error)

func (*ContextDao) ContextSet

func (dao *ContextDao) ContextSet(key string, val []byte) error

func (*ContextDao) GetCurrentBlock

func (dao *ContextDao) GetCurrentBlock() (*types.Block, error)

func (*ContextDao) SetCurrentBlock

func (dao *ContextDao) SetCurrentBlock(block *types.Block) error

type DBEngine

type DBEngine interface {
	GetDB() *sql.DB
}

type EquityDao

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

func NewEquityDao

func NewEquityDao(db DBEngine) *EquityDao

func (*EquityDao) Get

func (dao *EquityDao) Get(addr common.Address, id common.Hash) (*types.AssetEquity, error)

func (*EquityDao) GetPage

func (dao *EquityDao) GetPage(addr common.Address, start, limit int) ([]*types.AssetEquity, error)

func (*EquityDao) GetPageByCode

func (dao *EquityDao) GetPageByCode(addr common.Address, code common.Hash, start, limit int) ([]*types.AssetEquity, error)

func (*EquityDao) GetPageByCodeWithTotal

func (dao *EquityDao) GetPageByCodeWithTotal(addr common.Address, code common.Hash, start, limit int) ([]*types.AssetEquity, int, error)

func (*EquityDao) GetPageWithTotal

func (dao *EquityDao) GetPageWithTotal(addr common.Address, start, limit int) ([]*types.AssetEquity, int, error)

func (*EquityDao) Set

func (dao *EquityDao) Set(addr common.Address, assetEquity *types.AssetEquity) error

type KvDao

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

*

  • (1) hash => block
  • (2) hash => tx
  • (3) address => account

func NewKvDao

func NewKvDao(db DBEngine) *KvDao

func (*KvDao) Get

func (dao *KvDao) Get(key []byte) ([]byte, error)

func (*KvDao) Set

func (dao *KvDao) Set(key []byte, val []byte) error

type MySqlDB

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

func NewMySqlDB

func NewMySqlDB(driver string, dbHost string) *MySqlDB

func (*MySqlDB) Clear

func (db *MySqlDB) Clear() error

func (*MySqlDB) Close

func (db *MySqlDB) Close()

func (*MySqlDB) GetDB

func (db *MySqlDB) GetDB() *sql.DB

type Tx

type Tx struct {
	BHash       common.Hash
	Height      uint32
	PHash       common.Hash // 为箱子交易的时候的箱子的hash
	THash       common.Hash
	From        common.Address
	To          common.Address
	Tx          *types.Transaction
	Flag        int
	St          int64       // 交易保存进db的时间
	PackageTime uint32      // 打包交易的时间
	AssetCode   common.Hash // 如果是资产交易则对应资产code
	AssetId     common.Hash // 对应资产交易的资产id
}

type TxDao

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

func NewTxDao

func NewTxDao(db DBEngine) *TxDao

func (*TxDao) Get

func (dao *TxDao) Get(hash common.Hash) (*Tx, error)

func (*TxDao) GetByAddr

func (dao *TxDao) GetByAddr(addr common.Address, start, limit int) ([]*Tx, error)

func (*TxDao) GetByAddrWithTotal

func (dao *TxDao) GetByAddrWithTotal(addr common.Address, start, limit int) ([]*Tx, int, error)

func (*TxDao) GetByAddressAndAssetCodeOrAssetId added in v1.2.0

func (dao *TxDao) GetByAddressAndAssetCodeOrAssetId(addr common.Address, assetCodeOrId common.Hash, start, limit int) ([]*Tx, error)

通过 address 和 assetCode或者assetId查询交易

func (*TxDao) GetByAddressAndAssetCodeOrAssetIdWithTotal added in v1.2.0

func (dao *TxDao) GetByAddressAndAssetCodeOrAssetIdWithTotal(addr common.Address, assetCodeOrId common.Hash, start, limit int) ([]*Tx, int, error)

func (*TxDao) GetByFrom

func (dao *TxDao) GetByFrom(addr common.Address, start, limit int) ([]*Tx, error)

func (*TxDao) GetByFromWithTotal

func (dao *TxDao) GetByFromWithTotal(addr common.Address, start, limit int) ([]*Tx, int, error)

func (*TxDao) GetByTime

func (dao *TxDao) GetByTime(addr common.Address, stStart, stStop int64, start, limit int) ([]*Tx, error)

func (*TxDao) GetByTimeWithTotal

func (dao *TxDao) GetByTimeWithTotal(addr common.Address, stStart, stStop int64, start, limit int) ([]*Tx, int, error)

func (*TxDao) GetByTo

func (dao *TxDao) GetByTo(addr common.Address, start, limit int) ([]*Tx, error)

func (*TxDao) GetByToWithTotal

func (dao *TxDao) GetByToWithTotal(addr common.Address, start, limit int) ([]*Tx, int, error)

func (*TxDao) GetByType added in v1.2.2

func (dao *TxDao) GetByType(addr common.Address, txType uint16, start, limit int) ([]*Tx, error)

func (*TxDao) GetByTypeWithTotal added in v1.2.2

func (dao *TxDao) GetByTypeWithTotal(addr common.Address, txType uint16, start, limit int) ([]*Tx, int, error)

func (*TxDao) Set

func (dao *TxDao) Set(tx *Tx) error

Jump to

Keyboard shortcuts

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