blocksqldb

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockInfo

type BlockInfo struct {
	ChainId            string `gorm:"size:128"`
	BlockHeight        uint64 `gorm:"primaryKey;autoIncrement:false"`
	PreBlockHash       []byte `gorm:"size:128"`
	BlockHash          []byte `gorm:"size:128;index:idx_hash"`
	PreConfHeight      uint64 `gorm:"default:0"`
	BlockVersion       uint32 `gorm:"default:1"`
	DagHash            []byte `gorm:"size:128"`
	RwSetRoot          []byte `gorm:"size:128"`
	TxRoot             []byte `gorm:"size:128"`
	BlockTimestamp     int64  `gorm:"default:0"`
	ProposerOrgId      string `gorm:"size:128"`
	ProposerMemberInfo []byte `gorm:"type:blob;size:65535"`
	ProposerMemberType int    `gorm:"default:0"`
	ProposerSA         uint32 `gorm:"default:0"`
	ConsensusArgs      []byte `gorm:"type:blob"`
	TxCount            uint32 `gorm:"default:0"`
	Signature          []byte `gorm:"type:blob;size:65535"`
	BlockType          int    `gorm:"default:0"`
	Dag                []byte `gorm:"type:blob"`
	// TxIds is string , json marshal array of payload's tx_ids
	TxIds          string `gorm:"type:longtext"`
	AdditionalData []byte `gorm:"type:longblob"`
}

BlockInfo defines mysql orm model, used to create mysql table 'block_infos'

@Description:

func ConvertHeader2BlockInfo

func ConvertHeader2BlockInfo(header *commonPb.BlockHeader) *BlockInfo

ConvertHeader2BlockInfo transform BlockHeader to BlockInfo

@Description:
@param header
@return *BlockInfo

func NewBlockInfo

func NewBlockInfo(block *commonPb.Block) (*BlockInfo, error)

NewBlockInfo add next time

@Description:
@param block
@return *BlockInfo
@return error

func (*BlockInfo) GetBlock

func (b *BlockInfo) GetBlock() (*commonPb.Block, error)

GetBlock transfer the BlockInfo to commonPb.Block

@Description:
@receiver b
@return *commonPb.Block
@return error

func (*BlockInfo) GetBlockHeader

func (b *BlockInfo) GetBlockHeader() *commonPb.BlockHeader

GetBlockHeader retrieve BlockHeader from BlockInfo

@Description:
@receiver b
@return *commonPb.BlockHeader

func (*BlockInfo) GetCountSql

func (b *BlockInfo) GetCountSql() (string, []interface{})

GetCountSql generate table(block_infos)-count sentence , query item-counts according to block_height

@Description:
@receiver b
@return string
@return []interface{}

func (*BlockInfo) GetCreateTableSql

func (b *BlockInfo) GetCreateTableSql(dbType string) string

GetCreateTableSql generate table(block_infos)-create sentence , according to dbType

@Description:
@receiver b
@param dbType
@return string

func (*BlockInfo) GetFilteredBlock

func (b *BlockInfo) GetFilteredBlock() (*storePb.SerializedBlock, error)

GetFilteredBlock returns a filtered block given it's block height, or return nil if none exists.

@Description:
@receiver b
@return *storePb.SerializedBlock
@return error

func (*BlockInfo) GetInsertSql

func (b *BlockInfo) GetInsertSql(dbType string) (string, []interface{})

GetInsertSql generate table(block_infos)-insert sentence , according to dbType

@Description:
@receiver b
@param dbType
@return string
@return []interface{}

func (*BlockInfo) GetTableName

func (b *BlockInfo) GetTableName() string

GetTableName 获得表的名字

@Description:
@receiver b
@return string

func (*BlockInfo) GetTxList

func (b *BlockInfo) GetTxList() ([]string, error)

GetTxList returns the txId list , or return nil if an error occurred

@Description:
@receiver b
@return []string
@return error

func (*BlockInfo) GetUpdateSql

func (b *BlockInfo) GetUpdateSql() (string, []interface{})

GetUpdateSql generate table(block_infos)-update sentence , update chain_id according to block_height

@Description:
@receiver b
@return string
@return []interface{}

func (*BlockInfo) ScanObject

func (b *BlockInfo) ScanObject(scan func(dest ...interface{}) error) error

ScanObject use scan-func scan data into BlockInfo

@Description:
@receiver b
@param scan
@return error

type BlockSqlDB

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

BlockSqlDB provider a implementation of `blockdb.BlockDB` This implementation provides a mysql based data model @Description:

func NewBlockSqlDB

func NewBlockSqlDB(dbName string, db protocol.SqlDBHandle, logger protocol.Logger) *BlockSqlDB

NewBlockSqlDB constructs a new `BlockSqlDB` given an chainId and engine type

@Description:
@param dbName
@param db
@param logger
@return *BlockSqlDB

func (*BlockSqlDB) BlockExists

func (b *BlockSqlDB) BlockExists(blockHash []byte) (bool, error)

BlockExists returns true if the block hash exist, or returns false if none exists.

@Description:
@receiver b
@param blockHash
@return bool
@return error

func (*BlockSqlDB) Close

func (b *BlockSqlDB) Close()

Close is used to close database

@Description:
@receiver b

func (*BlockSqlDB) CommitBlock

func (b *BlockSqlDB) CommitBlock(blocksInfo *serialization.BlockWithSerializedInfo, isCache bool) error

CommitBlock commits the block and the corresponding rwsets in an atomic operation

@Description:
@receiver b
@param blocksInfo
@param isCache
@return error

func (*BlockSqlDB) ConfigBlockImport

func (b *BlockSqlDB) ConfigBlockImport(block *commonPb.Block) error

ConfigBlockImport import data from snapshot to blockdb

@Description:
@receiver b
@param block
@return error

func (*BlockSqlDB) GetArchivedPivot

func (db *BlockSqlDB) GetArchivedPivot() (uint64, error)

GetArchivedPivot return default 0 and nil

@Description:
@receiver db
@return uint64
@return error

func (*BlockSqlDB) GetBlock

func (b *BlockSqlDB) GetBlock(height uint64) (*commonPb.Block, error)

GetBlock returns a block given it's block height, or returns nil if none exists.

@Description:
@receiver b
@param height
@return *commonPb.Block
@return error

func (*BlockSqlDB) GetBlockByHash

func (b *BlockSqlDB) GetBlockByHash(blockHash []byte) (*commonPb.Block, error)

GetBlockByHash returns a block given it's hash, or returns nil if none exists.

@Description:
@receiver b
@param blockHash
@return *commonPb.Block
@return error

func (*BlockSqlDB) GetBlockByTx

func (b *BlockSqlDB) GetBlockByTx(txId string) (*commonPb.Block, error)

GetBlockByTx returns a block which contains a tx.

@Description:
@receiver b
@param txId
@return *commonPb.Block
@return error

func (*BlockSqlDB) GetBlockHeaderByHeight

func (db *BlockSqlDB) GetBlockHeaderByHeight(height uint64) (*commonPb.BlockHeader, error)

GetBlockHeaderByHeight 通过块高得到header

@Description:
@receiver db
@param height
@return *commonPb.BlockHeader
@return error

func (*BlockSqlDB) GetBlockIndex

func (b *BlockSqlDB) GetBlockIndex(height uint64) (*storePb.StoreInfo, error)

GetBlockIndex NotImplement

@Description:
@receiver b
@param height
@return *storePb.StoreInfo
@return error

func (*BlockSqlDB) GetBlockMetaIndex

func (b *BlockSqlDB) GetBlockMetaIndex(height uint64) (*storePb.StoreInfo, error)

GetBlockMetaIndex NotImplement

@Description:
@receiver b
@param height
@return *storePb.StoreInfo
@return error

func (*BlockSqlDB) GetFilteredBlock

func (b *BlockSqlDB) GetFilteredBlock(height uint64) (*storePb.SerializedBlock, error)

GetFilteredBlock returns a filtered block given it's block height, or return nil if none exists.

@Description:
@receiver b
@param height
@return *storePb.SerializedBlock
@return error

func (*BlockSqlDB) GetHeightByHash

func (db *BlockSqlDB) GetHeightByHash(blockHash []byte) (uint64, error)

GetHeightByHash 通过hash得到块高

@Description:
@receiver db
@param blockHash
@return uint64
@return error

func (*BlockSqlDB) GetLastBlock

func (b *BlockSqlDB) GetLastBlock() (*commonPb.Block, error)

GetLastBlock returns the last block.

@Description:
@receiver b
@return *commonPb.Block
@return error

func (*BlockSqlDB) GetLastConfigBlock

func (b *BlockSqlDB) GetLastConfigBlock() (*commonPb.Block, error)

GetLastConfigBlock returns the last config block.

@Description:
@receiver b
@return *commonPb.Block
@return error

func (*BlockSqlDB) GetLastConfigBlockHeight

func (b *BlockSqlDB) GetLastConfigBlockHeight() (uint64, error)

GetLastConfigBlockHeight returns the last config block height.

@Description:
@receiver b
@return uint64
@return error

func (*BlockSqlDB) GetLastSavepoint

func (b *BlockSqlDB) GetLastSavepoint() (uint64, error)

GetLastSavepoint returns the last block height

@Description:
@receiver b
@return uint64
@return error

func (*BlockSqlDB) GetTx

func (b *BlockSqlDB) GetTx(txId string) (*commonPb.Transaction, error)

GetTx retrieves a transaction by txid, or returns nil if none exists.

@Description:
@receiver b
@param txId
@return *commonPb.Transaction
@return error

func (*BlockSqlDB) GetTxConfirmedTime

func (b *BlockSqlDB) GetTxConfirmedTime(txId string) (int64, error)

GetTxConfirmedTime NotImplement

@Description:
@receiver b
@param txId
@return int64
@return error

func (*BlockSqlDB) GetTxHeight

func (db *BlockSqlDB) GetTxHeight(txId string) (uint64, error)

GetTxHeight 通过txid得到块高

@Description:
@receiver db
@param txId
@return uint64
@return error

func (*BlockSqlDB) GetTxIndex

func (b *BlockSqlDB) GetTxIndex(txId string) (*storePb.StoreInfo, error)

GetTxIndex NotImplement

@Description:
@receiver b
@param txId
@return *storePb.StoreInfo
@return error

func (*BlockSqlDB) GetTxInfoOnly

func (b *BlockSqlDB) GetTxInfoOnly(txId string) (*storePb.TransactionStoreInfo, error)

GetTxInfoOnly 获得除Tx之外的其他TxInfo信息

@Description:
@receiver b
@param txId
@return *storePb.TransactionStoreInfo
@return error

func (*BlockSqlDB) GetTxWithBlockInfo

func (b *BlockSqlDB) GetTxWithBlockInfo(txId string) (*storePb.TransactionStoreInfo, error)

GetTxWithBlockInfo 通过交易id 得到交易Info信息

@Description:
@receiver b
@param txId
@return *storePb.TransactionStoreInfo
@return error

func (*BlockSqlDB) GetTxidSet

func (b *BlockSqlDB) GetTxidSet() ([]protocol.Iterator, error)

GetTxidSet get all tx id

@Description:
@receiver b
@param block
@return error

func (*BlockSqlDB) ImportSetSavePoint

func (b *BlockSqlDB) ImportSetSavePoint(height uint64) error

ImportSetSavePoint set up savePoint when import snapshot

@Description:
@receiver b
@param height
@return error

func (*BlockSqlDB) ImportTxID

func (b *BlockSqlDB) ImportTxID(key, value []byte) error

ImportTxID import tx id from snapshot data into db

@Description:
@receiver b
@param key
@param value
@return error

func (*BlockSqlDB) InitGenesis

func (b *BlockSqlDB) InitGenesis(genesisBlock *serialization.BlockWithSerializedInfo) error

InitGenesis 创世块初始化

@Description:
@receiver b
@param genesisBlock
@return error

func (*BlockSqlDB) RestoreBlocks

func (db *BlockSqlDB) RestoreBlocks(blockInfos []*serialization.BlockWithSerializedInfo) error

RestoreBlocks NotImplement

@Description:
@receiver db
@param blockInfos
@return error

func (*BlockSqlDB) ShrinkBlocks

func (db *BlockSqlDB) ShrinkBlocks(startHeight uint64, endHeight uint64) (map[uint64][]string, error)

ShrinkBlocks add NotImplement

@Description:
@receiver db
@param startHeight
@param endHeight
@return map[uint64][]string
@return error

func (*BlockSqlDB) TxArchived

func (db *BlockSqlDB) TxArchived(txId string) (bool, error)

TxArchived 交易归档

@Description:
@receiver db
@param txId
@return bool
@return error

func (*BlockSqlDB) TxExists

func (b *BlockSqlDB) TxExists(txId string) (bool, error)

TxExists returns true if the tx exist, or returns false if none exists.

@Description:
@receiver b
@param txId
@return bool
@return error

type TxInfo

type TxInfo struct {
	ChainId        string `gorm:"size:128"`
	TxType         int32  `gorm:"default:0"`
	TxId           string `gorm:"primaryKey;size:128"`
	Timestamp      int64  `gorm:"default:0"`
	ExpirationTime int64  `gorm:"default:0"`

	ContractName string `gorm:"size:128"`
	// invoke method
	Method string `gorm:"size:128"`
	// invoke parameters in k-v format
	Parameters []byte `gorm:"type:longblob"` //json
	//sequence number 交易顺序号,以Sender为主键,0表示无顺序要求,>0则必须连续递增。
	Sequence uint64 `gorm:"default:0"`
	// gas price+gas limit; fee; timeout seconds;
	Limit *commonPb.Limit `gorm:"type:blob;size:65535"`

	SenderOrgId      string `gorm:"size:128"`
	SenderMemberInfo []byte `gorm:"type:blob;size:65535"`
	SenderMemberType int    `gorm:"default:0"`
	//SenderSA         uint32 `gorm:"default:0"`
	SenderSignature []byte `gorm:"type:blob;size:65535"`
	Endorsers       string `gorm:"type:longtext"` //json

	TxStatusCode       int32
	ContractResultCode uint32
	ResultData         []byte `gorm:"type:longblob"`
	ResultMessage      string `gorm:"size:2000"`
	GasUsed            uint64
	ContractEvents     string `gorm:"type:longtext"` //json
	RwSetHash          []byte `gorm:"size:128"`
	Message            string `gorm:"size:2000"`

	BlockHeight uint64 `gorm:"index:idx_height_offset"`
	BlockHash   []byte `gorm:"size:128"`
	Offset      uint32 `gorm:"index:idx_height_offset"`
}

TxInfo TxInfo defines mysql orm model, used to create mysql table 'tx_infos'

@Description:

func NewTxInfo

func NewTxInfo(tx *commonPb.Transaction, blockHeight uint64, blockHash []byte, offset uint32) (*TxInfo, error)

NewTxInfo construct new `TxInfo`

@Description:
@param tx
@param blockHeight
@param blockHash
@param offset
@return *TxInfo
@return error

func (*TxInfo) GetCountSql

func (b *TxInfo) GetCountSql() (string, []interface{})

GetCountSql generate table(tx_infos)-count sentence , query item-counts according to tx_id

@Description:
@receiver b
@return string
@return []interface{}

func (*TxInfo) GetCreateTableSql

func (t *TxInfo) GetCreateTableSql(dbType string) string

GetCreateTableSql generate table(tx_infos)-create sentence , according to dbType

@Description:
@receiver t
@param dbType
@return string

func (*TxInfo) GetInsertSql

func (t *TxInfo) GetInsertSql(dbType string) (string, []interface{})

GetInsertSql generate table(tx_infos)-insert sentence , according to dbType

@Description:
@receiver t
@param dbType
@return string
@return []interface{}

func (*TxInfo) GetTableName

func (t *TxInfo) GetTableName() string

GetTableName 获得表的名字

@Description:
@receiver t
@return string

func (*TxInfo) GetTx

func (t *TxInfo) GetTx() (*commonPb.Transaction, error)

GetTx transfer TxInfo to commonPb.Transaction

@Description:
@receiver t
@return *commonPb.Transaction
@return error

func (*TxInfo) GetTxInfo

func (t *TxInfo) GetTxInfo() (*storePb.TransactionStoreInfo, error)

GetTxInfo retrieve TransactionStoreInfo from TxInfo

@Description:
@receiver t
@return *storePb.TransactionStoreInfo
@return error

func (*TxInfo) GetUpdateSql

func (t *TxInfo) GetUpdateSql() (string, []interface{})

GetUpdateSql generate table(tx_infos)-update sentence , update chain_id according to tx_id

@Description:
@receiver t
@return string
@return []interface{}

func (*TxInfo) ScanObject

func (t *TxInfo) ScanObject(scan func(dest ...interface{}) error) error

ScanObject use scan-func scan data into TxInfo

@Description:
@receiver t
@param scan
@return error

Jump to

Keyboard shortcuts

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