storage

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 23 Imported by: 0

README

Storage封装了对底层数据库对象的增删改查操作,每个操作只针对一个对象,按存储的对象功能不同,分为:

  • DagDB
  • UTXODB
  • StateDB
  • IndexDB
  • PropertyDb 其中DAGDB存储所有区块(Unit)的信息,当然Unit中包含的Transaction也在其中。 UTXODB是根据Tx中的PaymentMessage而构建的Token UTXO状态的数据库,该数据库中的UTXO是进行软删除。 StateDB是根据Tx中的ContractInvoke中的RWSet而构建的状态数据库,状态数据在数据库中保存时存在版本信息。另外对账户状态,系统配置,合约模板,合约的其他属性等都在该数据库。 IndexDB是因为快速检索的需要而构建的索引数据库。我们可以通过toml中的配置来打开或关闭对某些数据的索引。 PropertyDB是专门为不需要保存到区块链,但是又需要临时存储的数据而设置的数据库。该数据库中包含了MediatorSchedule,GlobalProperty,DynamicProperty等。

UTXO DB的设计

UTXO DB中,以OutPoint为Key(UTXO_PREFIX),以Utxo为Value存储最基本的UTXO数据。 为了能够方便地址快速访问自己的UTXO,所以需要强制建立索引,索引的Key为: AddrOutPoint_Prefix+地址.Bytes()+OutPoint.Bytes() Value 仍然是 OutPoint这个对象的RLP编码

SaveUtxoEntity存储一个UTXO,同时也会存储一个对应Address对应的索引 删除Utxo的时候软删除Utxo,但是会物理删除对应的索引

DAG DB的设计

一个Unit分为Header,Body和Txs三部分存储。

  • Header在存储时,使用UnitHash作为key,但是为了能够通过Number也就是Height(ChainIndex)快速的检索到Header,所以需要存储ChainIndex到UnitHash的索引。
  • Body存储的是TxId的数组,仍然是以UnitHash为Key。为了能够通过TxId快速反查出所在的Unit和位置,所以存储了TxLookup,SaveTxLookupEntry会将每个TxId作为Key,TxLookupEntry作为Value。
  • Transaction是实际的交易对象,以TxId为Key,Value是编码后的Tx。Tx存储时包含以下索引:
    • 为了能够通过RequestId也查到该Tx,所以会建立RequestId到TxId的映射索引。
    • 为了快速知道每个Tx是哪个地址发起的(Msg0的Input对应的OutPoint的锁定脚本对应的地址),所以会建立FromAddress到Tx的映射索引。

State DB的设计

StateDB是一个带有Version的数据库,里面记录了最新版本的状态数据。Version在Value中最前面。 StateDB保存了以下信息:

  • 配置信息
  • 合约模板(源码,bin等)
  • 合约状态数据
  • 账户信息
  • 投票信息

Index DB的设计

IndexDB是一个可选的数据库,里面保存了为了快速查询某些信息而建立的关联关系信息。在TOML中可以开启或者关闭多个Index数据。 目前建立了Index的数据包括:

  • Address -> TxId
  • TokenAsset -> TxId
  • DataPayload.MainData-> TxId

基于Token的共识分区

每个分区有自己的唯一的GasToken,每个分区的创世单元为该GasToken创建时的单元。每个分区只记录自己GasToken相关的Unit全账本,PTN分区除了记录PTN全账本外,会同步所有其他分区的Unit Header。 每个分区以ChainIndex中的AssetId来唯一区分分区。 因为主分区(PTN分区)包含了所有分区的Header,所以分区之间的Token互换通过Relay模式来实现跨链。 因为分区的存在,所以在PTN分区上,就会有多个最新单元和多个最新稳定单元。

Documentation

Index

Constants

This section is empty.

Variables

Functions

func AddKeysWithTag

func AddKeysWithTag(db ptndb.Database, key, tag string) error

func BatchErrorHandler

func BatchErrorHandler(err error, errorList *[]error)

func BytesToUint64

func BytesToUint64(b []byte) uint64

func ConvertBytes

func ConvertBytes(val interface{}) (re []byte)

func Delete

func Delete(db ptndb.Deleter, key []byte) error

delete

func GetAddrTransactionsHash

func GetAddrTransactionsHash(db DatabaseReader, addr string) ([]common.Hash, error)

GetAdddrTransactionsHash

func GetBytes

func GetBytes(db ptndb.Database, key []byte) ([]byte, error)

func GetContractRlp

func GetContractRlp(db DatabaseReader, id common.Hash) (rlp.RawValue, error)

func GetContractStateKey added in v1.0.8

func GetContractStateKey(id []byte, field string) []byte

func GetKeysWithTag

func GetKeysWithTag(db ptndb.Database, tag string) []string

func GetMmediatorKey added in v1.0.5

func GetMmediatorKey(address common.Address) []byte

func GetString

func GetString(db ptndb.Database, key string) (string, error)

func GetUnitChainVersion

func GetUnitChainVersion(db ptndb.Database) int
get  unit chain version

GetUnitChainVersion reads the version number from db.

func Init

func Init(path string, cache int, handles int) (ptndb.Database, error)

func JuryDepositKey added in v1.0.3

func JuryDepositKey(jurorAddr string) string

func MediatorDepositKey added in v1.0.3

func MediatorDepositKey(medAddr string) string

func RetrieveFromJsonBytes

func RetrieveFromJsonBytes(db ptndb.Database, key []byte, v interface{}) error

func RetrieveFromRlpBytes

func RetrieveFromRlpBytes(db ptndb.Database, key []byte, v interface{}) error

func SaveUnitChainVersion

func SaveUnitChainVersion(db ptndb.Putter, vsn int) error

SaveUnitChainVersion writes vsn as the version number to db.

func StoreString

func StoreString(db ptndb.Putter, key, value string) error

func StoreToJsonBytes

func StoreToJsonBytes(db ptndb.Putter, key []byte, value interface{}) error

func StoreToRlpBytes

func StoreToRlpBytes(db ptndb.Putter, key []byte, value interface{}) error

func Uint64ToBytes

func Uint64ToBytes(number uint64) []byte

encodeBlockNumber encodes a block number as big endian uint64

func Update

func Update(db ptndb.Database, key, value []byte) error

update

Types

type DagDb

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

对DAG对象的操作,包括:Unit,Tx等

func NewDagDb

func NewDagDb(db ptndb.Database) *DagDb

func (*DagDb) ForEachAllTxDo added in v1.0.3

func (dagdb *DagDb) ForEachAllTxDo(txAction func(key []byte, transaction *modules.Transaction) error) error

func (*DagDb) GetAllData added in v1.0.4

func (dagdb *DagDb) GetAllData() ([][]byte, [][]byte)

func (*DagDb) GetAllTxs

func (dagdb *DagDb) GetAllTxs() ([]*modules.Transaction, error)

func (*DagDb) GetBody

func (dagdb *DagDb) GetBody(unitHash common.Hash) ([]common.Hash, error)

func (*DagDb) GetCommon

func (dagdb *DagDb) GetCommon(key []byte) ([]byte, error)

----- common geter -----

func (*DagDb) GetCommonByPrefix

func (dagdb *DagDb) GetCommonByPrefix(prefix []byte) map[string][]byte

func (*DagDb) GetDb added in v1.0.6

func (dagdb *DagDb) GetDb() ptndb.Database

func (*DagDb) GetGenesisUnitHash

func (dagdb *DagDb) GetGenesisUnitHash() (common.Hash, error)

func (*DagDb) GetHashByNumber

func (dagdb *DagDb) GetHashByNumber(number *modules.ChainIndex) (common.Hash, error)

func (*DagDb) GetHeaderByHash

func (dagdb *DagDb) GetHeaderByHash(hash common.Hash) (*modules.Header, error)

func (*DagDb) GetPrefix

func (dagdb *DagDb) GetPrefix(prefix []byte) map[string][]byte

func (*DagDb) GetTransactionOnly

func (dagdb *DagDb) GetTransactionOnly(hash common.Hash) (*modules.Transaction, error)

GetTransactionOnly can get a transaction by hash.

func (*DagDb) GetTrieSyncProgress

func (dagdb *DagDb) GetTrieSyncProgress() (uint64, error)

GetTrieSyncProgress stores the fast sync trie process counter to support retrieving it across restarts.

func (*DagDb) GetTxHashByReqId

func (dagdb *DagDb) GetTxHashByReqId(reqid common.Hash) (common.Hash, error)

func (*DagDb) GetTxLookupEntry

func (dagdb *DagDb) GetTxLookupEntry(txHash common.Hash) (*modules.TxLookupEntry, error)

func (*DagDb) GetUnitTransactions

func (dagdb *DagDb) GetUnitTransactions(hash common.Hash) (modules.Transactions, error)

func (*DagDb) IsHeaderExist

func (dagdb *DagDb) IsHeaderExist(uHash common.Hash) (bool, error)

func (*DagDb) IsTransactionExist

func (dagdb *DagDb) IsTransactionExist(hash common.Hash) (bool, error)

func (*DagDb) PutTrieSyncProgress

func (dagdb *DagDb) PutTrieSyncProgress(count uint64) error

PutTrieSyncProgress stores the fast sync trie process counter to support retrieving it across restarts.

func (*DagDb) SaveBody

func (dagdb *DagDb) SaveBody(unitHash common.Hash, txsHash []common.Hash) error

* key: [BODY_PREFIX][unit hash] value: all transactions hash set's rlp encoding bytes

func (*DagDb) SaveCommon

func (dagdb *DagDb) SaveCommon(key, val []byte) error

----- common saver -----

func (*DagDb) SaveGenesisUnitHash

func (dagdb *DagDb) SaveGenesisUnitHash(hash common.Hash) error

func (*DagDb) SaveHeader

func (dagdb *DagDb) SaveHeader(h *modules.Header) error

###################### SAVE IMPL START ###################### * key: [HEADER_PREFIX][chain index number]_[chain index]_[unit hash] value: unit header rlp encoding bytes

save header

func (*DagDb) SaveHeaders

func (dagdb *DagDb) SaveHeaders(headers []*modules.Header) error

func (*DagDb) SaveTransaction

func (dagdb *DagDb) SaveTransaction(tx *modules.Transaction) error

* key: [TRANSACTION_PREFIX][tx hash] value: transaction struct rlp encoding bytes

func (*DagDb) SaveTxLookupEntry

func (dagdb *DagDb) SaveTxLookupEntry(hash common.Hash, height, timestamp uint64, index int,
	tx *modules.Transaction) error

type DatabaseReader

type DatabaseReader interface {
	Get(key []byte) (value []byte, err error)
	NewIterator() iterator.Iterator
	NewIteratorWithPrefix(prefix []byte) iterator.Iterator
}

DatabaseReader wraps the Get method of a backing data store.

type IDagDb

type IDagDb interface {
	GetDb() ptndb.Database
	GetGenesisUnitHash() (common.Hash, error)
	SaveGenesisUnitHash(hash common.Hash) error

	SaveHeader(h *modules.Header) error
	SaveHeaders(headers []*modules.Header) error
	SaveTransaction(tx *modules.Transaction) error
	GetAllTxs() ([]*modules.Transaction, error)
	SaveBody(unitHash common.Hash, txsHash []common.Hash) error
	GetBody(unitHash common.Hash) ([]common.Hash, error)
	SaveTxLookupEntry(hash common.Hash, height, timestamp uint64, index int, tx *modules.Transaction) error

	PutTrieSyncProgress(count uint64) error

	GetUnitTransactions(hash common.Hash) (modules.Transactions, error)
	GetTransactionOnly(hash common.Hash) (*modules.Transaction, error)
	GetTxLookupEntry(hash common.Hash) (*modules.TxLookupEntry, error)
	GetPrefix(prefix []byte) map[string][]byte
	GetHeaderByHash(hash common.Hash) (*modules.Header, error)
	IsHeaderExist(uHash common.Hash) (bool, error)
	IsTransactionExist(txHash common.Hash) (bool, error)
	GetHashByNumber(number *modules.ChainIndex) (common.Hash, error)

	GetTrieSyncProgress() (uint64, error)

	// common geter
	GetCommon(key []byte) ([]byte, error)
	GetCommonByPrefix(prefix []byte) map[string][]byte
	SaveCommon(key, val []byte) error
	GetAllData() ([][]byte, [][]byte)
	// get txhash  and save index
	//GetReqIdByTxHash(hash common.Hash) (common.Hash, error)
	GetTxHashByReqId(reqid common.Hash) (common.Hash, error)
	ForEachAllTxDo(txAction func(key []byte, transaction *modules.Transaction) error) error
}

type IIndexDb

type IIndexDb interface {
	SaveAddressTxId(address common.Address, txid common.Hash) error
	GetAddressTxIds(address common.Address) ([]common.Hash, error)
	//清空AddressTxIds
	TruncateAddressTxIds() error
	SaveTokenTxId(asset *modules.Asset, txid common.Hash) error
	GetTokenTxIds(asset *modules.Asset) ([]common.Hash, error)

	SaveMainDataTxId(maindata []byte, txid common.Hash) error
	GetMainDataTxIds(maindata []byte) ([]common.Hash, error)
	SaveProofOfExistence(poe *modules.ProofOfExistence) error
	QueryProofOfExistenceByReference(ref []byte) ([]*modules.ProofOfExistence, error)
	SaveAddress(address common.Address) error
	GetAddressCount() int
}

type ILocalDb added in v1.0.6

type ILocalDb interface {
	SaveLocalTx(tx *modules.Transaction) error
	GetLocalTx(txId common.Hash) (*modules.Transaction, error)
	SaveLocalTxStatus(txId common.Hash, status modules.TxStatus) error
	GetLocalTxStatus(txId common.Hash) (modules.TxStatus, error)
}

type IPropertyDb

type IPropertyDb interface {
	StoreGlobalProp(gp *modules.GlobalProperty) error
	RetrieveGlobalProp() (*modules.GlobalProperty, error)
	StoreDynGlobalProp(dgp *modules.DynamicGlobalProperty) error
	RetrieveDynGlobalProp() (*modules.DynamicGlobalProperty, error)
	StoreMediatorSchl(ms *modules.MediatorSchedule) error
	RetrieveMediatorSchl() (*modules.MediatorSchedule, error)

	SetNewestUnit(header *modules.Header) error
	//GetNewestUnit(token modules.AssetId) (common.Hash, *modules.ChainIndex, int64, error)
	GetNewestUnit(token modules.AssetId) (*modules.UnitProperty, error)

	GetChainParameters() *core.ChainParameters
}

type IStateDb

type IStateDb interface {
	GetPrefix(prefix []byte) map[string][]byte
	SaveContract(contract *modules.Contract) error
	GetContract(id []byte) (*modules.Contract, error)
	GetAllContracts() ([]*modules.Contract, error)
	SaveContractState(id []byte, w *modules.ContractWriteSet, version *modules.StateVersion) error
	SaveContractStates(id []byte, wset []modules.ContractWriteSet, version *modules.StateVersion) error
	GetContractState(id []byte, field string) ([]byte, *modules.StateVersion, error)
	GetContractStatesByPrefix(id []byte, prefix string) (map[string]*modules.ContractStateValue, error)
	GetContractStatesById(id []byte) (map[string]*modules.ContractStateValue, error)

	UpdateStateByContractInvoke(invoke *modules.ContractInvokeRequestPayload,
		unitTime int64, version *modules.StateVersion) error

	SaveContractTpl(tpl *modules.ContractTemplate) error
	SaveContractTplCode(tplId []byte, byteCode []byte) error
	GetContractTpl(tplId []byte) (*modules.ContractTemplate, error)
	GetContractTplCode(tplId []byte) ([]byte, error)
	GetAllContractTpl() ([]*modules.ContractTemplate, error)
	GetContractTplFromSysContract(tplId []byte) (*modules.ContractTemplate, error)
	GetContractTplCodeFromSysContract(tplId []byte) ([]byte, error)
	GetAllContractTplFromSysContract() ([]*modules.ContractTemplate, error)
	GetContractIdsByTpl(tplId []byte) ([][]byte, error)
	SaveContractDeploy(reqid []byte, deploy *modules.ContractDeployPayload) error
	SaveContractDeployReq(reqid []byte, deploy *modules.ContractDeployRequestPayload) error
	SaveContractInvokeReq(reqid []byte, invoke *modules.ContractInvokeRequestPayload) error
	SaveContractStop(reqid []byte, stop *modules.ContractStopPayload) error
	SaveContractStopReq(reqid []byte, stopr *modules.ContractStopRequestPayload) error
	SaveContractSignature(reqid []byte, sig *modules.SignaturePayload) error

	GetContractDeploy(reqId []byte) (*modules.ContractDeployPayload, error)
	GetContractDeployReq(reqid []byte) (*modules.ContractDeployRequestPayload, error)
	GetContractInvoke(reqId []byte) (*modules.ContractInvokePayload, error)
	GetContractInvokeReq(reqid []byte) (*modules.ContractInvokeRequestPayload, error)
	GetContractStop(reqId []byte) (*modules.ContractStopPayload, error)
	GetContractStopReq(reqId []byte) (*modules.ContractStopRequestPayload, error)
	GetContractSignature(reqId []byte) (*modules.SignaturePayload, error)

	SaveAccountState(address common.Address, write *modules.AccountStateWriteSet, version *modules.StateVersion) error
	SaveAccountStates(address common.Address, writeset []modules.AccountStateWriteSet, version *modules.StateVersion) error
	GetAllAccountStates(address common.Address) (map[string]*modules.ContractStateValue, error)
	GetAccountState(address common.Address, statekey string) (*modules.ContractStateValue, error)
	UpdateAccountBalance(addr common.Address, addAmount int64) error
	GetAccountBalance(address common.Address) uint64
	GetAccountVotedMediators(addr common.Address) map[string]bool
	LookupAccount() map[common.Address]*modules.AccountInfo

	//获得一个合约的陪审团列表
	GetContractJury(contractId []byte) (*modules.ElectionNode, error)
	SaveContractJury(contractId []byte, jury modules.ElectionNode, version *modules.StateVersion) error

	StoreMediator(med *core.Mediator) error
	UpdateMediatorInfoExpand(med *core.Mediator) error
	StoreMediatorInfo(add common.Address, mi *modules.MediatorInfo) error
	RetrieveMediator(address common.Address) (*core.Mediator, error)
	GetMediators() map[common.Address]bool
	LookupMediatorInfo() []*modules.MediatorInfo
	IsMediator(address common.Address) bool
	RetrieveMediatorInfo(address common.Address) (*modules.MediatorInfo, error)

	GetCandidateMediatorList() (map[string]bool, error)
	GetJuryCandidateList() (map[string]bool, error)
	IsInJuryCandidateList(address common.Address) bool
	GetAllJuror() (map[string]*modules.JurorDeposit, error)
	GetJurorByAddr(addr string) (*modules.JurorDeposit, error)
	GetContractDeveloperList() ([]common.Address, error)
	IsInContractDeveloperList(address common.Address) bool

	GetDataVersion() (*modules.DataVersion, error)
	SaveDataVersion(dv *modules.DataVersion) error

	GetPartitionChains() ([]*modules.PartitionChain, error)
	GetMainChain() (*modules.MainChain, error)

	GetBlacklistAddress() ([]common.Address, *modules.StateVersion, error)

	GetSysParamWithoutVote() (map[string]string, error)
	GetSysParamsWithVotes() (*modules.SysTokenIDInfo, error)
	SaveSysConfigContract(key string, val []byte, ver *modules.StateVersion) error

	SaveContractWithJuryAddr(addr common.Hash, contract *modules.Contract) error
	GetContractsWithJuryAddr(addr common.Hash) []*modules.Contract
}

type IUtxoDb

type IUtxoDb interface {
	GetUtxoEntry(outpoint *modules.OutPoint) (*modules.Utxo, error)

	GetAddrOutpoints(addr common.Address) ([]modules.OutPoint, error)
	GetAddrUtxos(addr common.Address, asset *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)
	GetAllUtxos() (map[modules.OutPoint]*modules.Utxo, error)
	SaveUtxoEntity(outpoint *modules.OutPoint, utxo *modules.Utxo) error
	SaveUtxoView(view map[modules.OutPoint]*modules.Utxo) error
	DeleteUtxo(outpoint *modules.OutPoint, spentTxId common.Hash, spentTime uint64) error
	IsUtxoSpent(outpoint *modules.OutPoint) (bool, error)
	GetStxoEntry(outpoint *modules.OutPoint) (*modules.Stxo, error)
	ClearAddrUtxo(addr common.Address) error
	ClearUtxo() error

	SaveRequestAndTxHash(requestHash common.Hash, txHash common.Hash) error
	GetRequestAndTxMapping(hash common.Hash) (common.Hash, error)
}

type IndexDb

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

func NewIndexDb

func NewIndexDb(db ptndb.Database) *IndexDb

func (*IndexDb) GetAddressCount added in v1.0.6

func (db *IndexDb) GetAddressCount() int

func (*IndexDb) GetAddressTxIds

func (db *IndexDb) GetAddressTxIds(address common.Address) ([]common.Hash, error)

func (*IndexDb) GetMainDataTxIds

func (db *IndexDb) GetMainDataTxIds(filehash []byte) ([]common.Hash, error)

func (*IndexDb) GetTokenTxIds

func (db *IndexDb) GetTokenTxIds(asset *modules.Asset) ([]common.Hash, error)

func (*IndexDb) QueryProofOfExistenceByReference

func (db *IndexDb) QueryProofOfExistenceByReference(ref []byte) ([]*modules.ProofOfExistence, error)

func (*IndexDb) SaveAddress added in v1.0.6

func (db *IndexDb) SaveAddress(address common.Address) error

func (*IndexDb) SaveAddressTxId

func (db *IndexDb) SaveAddressTxId(address common.Address, txid common.Hash) error

func (*IndexDb) SaveMainDataTxId

func (db *IndexDb) SaveMainDataTxId(filehash []byte, txid common.Hash) error

save filehash key:IDX_MAIN_DATA_TXID value:Txid

func (*IndexDb) SaveProofOfExistence

func (db *IndexDb) SaveProofOfExistence(poe *modules.ProofOfExistence) error

func (*IndexDb) SaveTokenTxId

func (db *IndexDb) SaveTokenTxId(asset *modules.Asset, txid common.Hash) error

func (*IndexDb) TruncateAddressTxIds added in v1.0.3

func (db *IndexDb) TruncateAddressTxIds() error

type LocalDb added in v1.0.6

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

func NewLocalDb added in v1.0.6

func NewLocalDb(db ptndb.Database) *LocalDb

func (*LocalDb) GetLocalTx added in v1.0.6

func (db *LocalDb) GetLocalTx(hash common.Hash) (*modules.Transaction, error)

查询某交易的内容和状态

func (*LocalDb) GetLocalTxStatus added in v1.0.6

func (db *LocalDb) GetLocalTxStatus(txId common.Hash) (modules.TxStatus, error)

func (*LocalDb) SaveLocalTx added in v1.0.6

func (db *LocalDb) SaveLocalTx(tx *modules.Transaction) error

通过本地RPC创建或广播的交易

func (*LocalDb) SaveLocalTxStatus added in v1.0.6

func (db *LocalDb) SaveLocalTxStatus(txId common.Hash, status modules.TxStatus) error

保存某交易的状态

type PropertyDb

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

func NewPropertyDb

func NewPropertyDb(db ptndb.Database) *PropertyDb

modified by Yiran initialize PropertyDB , and retrieve gp,dgp,mc from IPropertyDb.

func (*PropertyDb) GetChainParameters

func (propdb *PropertyDb) GetChainParameters() *core.ChainParameters

func (*PropertyDb) GetNewestUnit

func (db *PropertyDb) GetNewestUnit(asset modules.AssetId) (*modules.UnitProperty, error)

func (db *PropertyDb) GetNewestUnit(asset modules.AssetId) (common.Hash, *modules.ChainIndex, int64, error) {

func (*PropertyDb) RetrieveDynGlobalProp

func (propdb *PropertyDb) RetrieveDynGlobalProp() (*modules.DynamicGlobalProperty, error)

func (*PropertyDb) RetrieveGlobalProp

func (propdb *PropertyDb) RetrieveGlobalProp() (*modules.GlobalProperty, error)

func (*PropertyDb) RetrieveMediatorSchl

func (propdb *PropertyDb) RetrieveMediatorSchl() (*modules.MediatorSchedule, error)

func (*PropertyDb) SetNewestUnit

func (db *PropertyDb) SetNewestUnit(header *modules.Header) error

func (*PropertyDb) StoreDynGlobalProp

func (propdb *PropertyDb) StoreDynGlobalProp(dgp *modules.DynamicGlobalProperty) error

func (*PropertyDb) StoreGlobalProp

func (propdb *PropertyDb) StoreGlobalProp(gp *modules.GlobalProperty) error

func (*PropertyDb) StoreMediatorSchl

func (propdb *PropertyDb) StoreMediatorSchl(ms *modules.MediatorSchedule) error

type StateDb

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

保存了对合约写集、Config、Asset信息

func NewStateDb

func NewStateDb(db ptndb.Database) *StateDb

func (*StateDb) DeleteState

func (statedb *StateDb) DeleteState(key []byte) error

func (*StateDb) GetAccountBalance

func (statedb *StateDb) GetAccountBalance(address common.Address) uint64

func (*StateDb) GetAccountState

func (statedb *StateDb) GetAccountState(address common.Address, statekey string) (*modules.ContractStateValue, error)

func (*StateDb) GetAccountVotedMediators

func (statedb *StateDb) GetAccountVotedMediators(addr common.Address) map[string]bool

func (*StateDb) GetAllAccountStates

func (statedb *StateDb) GetAllAccountStates(address common.Address) (map[string]*modules.ContractStateValue, error)

func (*StateDb) GetAllContractTpl

func (statedb *StateDb) GetAllContractTpl() ([]*modules.ContractTemplate, error)

func (*StateDb) GetAllContractTplFromSysContract added in v1.0.7

func (statedb *StateDb) GetAllContractTplFromSysContract() ([]*modules.ContractTemplate, error)

func (*StateDb) GetAllContracts

func (statedb *StateDb) GetAllContracts() ([]*modules.Contract, error)

func (*StateDb) GetAllJuror added in v1.0.3

func (statedb *StateDb) GetAllJuror() (map[string]*modules.JurorDeposit, error)

func (*StateDb) GetBlacklistAddress added in v1.0.3

func (statedb *StateDb) GetBlacklistAddress() ([]common.Address, *modules.StateVersion, error)

func (*StateDb) GetCandidateMediatorList added in v1.0.3

func (statedb *StateDb) GetCandidateMediatorList() (map[string]bool, error)

func (*StateDb) GetContract

func (statedb *StateDb) GetContract(id []byte) (*modules.Contract, error)

func (*StateDb) GetContractDeploy

func (statedb *StateDb) GetContractDeploy(reqId []byte) (*modules.ContractDeployPayload, error)

func (*StateDb) GetContractDeployReq

func (statedb *StateDb) GetContractDeployReq(reqId []byte) (*modules.ContractDeployRequestPayload, error)

func (*StateDb) GetContractDeveloperList added in v1.0.1

func (statedb *StateDb) GetContractDeveloperList() ([]common.Address, error)

func (*StateDb) GetContractIdsByTpl

func (statedb *StateDb) GetContractIdsByTpl(tplId []byte) ([][]byte, error)

func (*StateDb) GetContractInvoke

func (statedb *StateDb) GetContractInvoke(reqId []byte) (*modules.ContractInvokePayload, error)

func (*StateDb) GetContractInvokeReq

func (statedb *StateDb) GetContractInvokeReq(reqId []byte) (*modules.ContractInvokeRequestPayload, error)

func (*StateDb) GetContractJury

func (statedb *StateDb) GetContractJury(contractId []byte) (*modules.ElectionNode, error)

func (*StateDb) GetContractSignature

func (statedb *StateDb) GetContractSignature(reqId []byte) (*modules.SignaturePayload, error)

func (*StateDb) GetContractState

func (statedb *StateDb) GetContractState(id []byte, field string) ([]byte, *modules.StateVersion, error)

* 获取合约某一个属性 To get contract or contract template one field

func (*StateDb) GetContractStatesById

func (statedb *StateDb) GetContractStatesById(id []byte) (map[string]*modules.ContractStateValue, error)

* 获取合约全部属性 To get contract or contract template all fields

func (*StateDb) GetContractStatesByPrefix

func (statedb *StateDb) GetContractStatesByPrefix(id []byte,
	prefix string) (map[string]*modules.ContractStateValue, error)

* 获取合约全部属性 by Prefix To get contract or contract template all fields

func (*StateDb) GetContractStop

func (statedb *StateDb) GetContractStop(reqId []byte) (*modules.ContractStopPayload, error)

func (*StateDb) GetContractStopReq

func (statedb *StateDb) GetContractStopReq(reqId []byte) (*modules.ContractStopRequestPayload, error)

func (*StateDb) GetContractTpl

func (statedb *StateDb) GetContractTpl(tplId []byte) (*modules.ContractTemplate, error)

func (*StateDb) GetContractTplCode

func (statedb *StateDb) GetContractTplCode(tplId []byte) ([]byte, error)

func (*StateDb) GetContractTplCodeFromSysContract added in v1.0.7

func (statedb *StateDb) GetContractTplCodeFromSysContract(tplId []byte) ([]byte, error)

func (*StateDb) GetContractTplFromSysContract added in v1.0.7

func (statedb *StateDb) GetContractTplFromSysContract(tplId []byte) (*modules.ContractTemplate, error)

func (*StateDb) GetContractsWithJuryAddr added in v1.0.5

func (statedb *StateDb) GetContractsWithJuryAddr(addr common.Hash) []*modules.Contract

func (*StateDb) GetDataVersion

func (statedb *StateDb) GetDataVersion() (*modules.DataVersion, error)

func (*StateDb) GetJurorByAddr added in v1.0.3

func (statedb *StateDb) GetJurorByAddr(addr string) (*modules.JurorDeposit, error)

func (*StateDb) GetJuryCandidateList

func (statedb *StateDb) GetJuryCandidateList() (map[string]bool, error)

func (*StateDb) GetMainChain

func (statedb *StateDb) GetMainChain() (*modules.MainChain, error)

func (*StateDb) GetMediators

func (statedb *StateDb) GetMediators() map[common.Address]bool

func (*StateDb) GetPartitionChains

func (statedb *StateDb) GetPartitionChains() ([]*modules.PartitionChain, error)

func (*StateDb) GetPrefix

func (db *StateDb) GetPrefix(prefix []byte) map[string][]byte

get prefix: return maps

func (*StateDb) GetSysParamWithoutVote

func (statedb *StateDb) GetSysParamWithoutVote() (map[string]string, error)

func (*StateDb) GetSysParamsWithVotes

func (statedb *StateDb) GetSysParamsWithVotes() (*modules.SysTokenIDInfo, error)

func (*StateDb) IsInContractDeveloperList added in v1.0.1

func (statedb *StateDb) IsInContractDeveloperList(address common.Address) bool

func (*StateDb) IsInJuryCandidateList

func (statedb *StateDb) IsInJuryCandidateList(address common.Address) bool

func (*StateDb) IsMediator

func (statedb *StateDb) IsMediator(address common.Address) bool

func (*StateDb) LookupAccount

func (statedb *StateDb) LookupAccount() map[common.Address]*modules.AccountInfo

func (*StateDb) LookupMediatorInfo

func (statedb *StateDb) LookupMediatorInfo() []*modules.MediatorInfo

func (*StateDb) RetrieveMediator

func (statedb *StateDb) RetrieveMediator(address common.Address) (*core.Mediator, error)

func (*StateDb) RetrieveMediatorInfo

func (statedb *StateDb) RetrieveMediatorInfo(address common.Address) (*modules.MediatorInfo, error)

func (*StateDb) SaveAccountState

func (statedb *StateDb) SaveAccountState(address common.Address, write *modules.AccountStateWriteSet,
	version *modules.StateVersion) error

func (*StateDb) SaveAccountStates

func (statedb *StateDb) SaveAccountStates(address common.Address, writeset []modules.AccountStateWriteSet,
	version *modules.StateVersion) error

func (*StateDb) SaveContract

func (statedb *StateDb) SaveContract(contract *modules.Contract) error

func (*StateDb) SaveContractDeploy

func (statedb *StateDb) SaveContractDeploy(reqid []byte, deploy *modules.ContractDeployPayload) error

func (*StateDb) SaveContractDeployReq

func (statedb *StateDb) SaveContractDeployReq(reqid []byte, deploy *modules.ContractDeployRequestPayload) error

func (*StateDb) SaveContractInvokeReq

func (statedb *StateDb) SaveContractInvokeReq(reqid []byte, invoke *modules.ContractInvokeRequestPayload) error

func (*StateDb) SaveContractJury

func (statedb *StateDb) SaveContractJury(contractId []byte, jury modules.ElectionNode,
	version *modules.StateVersion) error

func (*StateDb) SaveContractSignature

func (statedb *StateDb) SaveContractSignature(reqid []byte, sig *modules.SignaturePayload) error

func (*StateDb) SaveContractState

func (statedb *StateDb) SaveContractState(contractId []byte, ws *modules.ContractWriteSet,
	version *modules.StateVersion) error

func (*StateDb) SaveContractStates

func (statedb *StateDb) SaveContractStates(id []byte, wset []modules.ContractWriteSet,
	version *modules.StateVersion) error

func (*StateDb) SaveContractStop

func (statedb *StateDb) SaveContractStop(reqid []byte, stop *modules.ContractStopPayload) error

func (*StateDb) SaveContractStopReq

func (statedb *StateDb) SaveContractStopReq(reqid []byte, stopr *modules.ContractStopRequestPayload) error

func (*StateDb) SaveContractTpl

func (statedb *StateDb) SaveContractTpl(tpl *modules.ContractTemplate) error

func (*StateDb) SaveContractTplCode

func (statedb *StateDb) SaveContractTplCode(tplId []byte, byteCode []byte) error

func (*StateDb) SaveContractWithJuryAddr added in v1.0.5

func (statedb *StateDb) SaveContractWithJuryAddr(addr common.Hash, contract *modules.Contract) error

func (*StateDb) SaveDataVersion

func (statedb *StateDb) SaveDataVersion(dv *modules.DataVersion) error

func (*StateDb) SaveSysConfigContract

func (statedb *StateDb) SaveSysConfigContract(key string, val []byte, ver *modules.StateVersion) error

var CONF_PREFIX = append(constants.CONTRACT_STATE_PREFIX, scc.SysConfigContractAddress.Bytes()...)

func (*StateDb) StoreMediator

func (statedb *StateDb) StoreMediator(med *core.Mediator) error

func (*StateDb) StoreMediatorInfo

func (statedb *StateDb) StoreMediatorInfo(add common.Address, mi *modules.MediatorInfo) error

func (*StateDb) UpdateAccountBalance

func (statedb *StateDb) UpdateAccountBalance(address common.Address, addAmount int64) error

func (*StateDb) UpdateMediatorInfoExpand added in v1.0.5

func (statedb *StateDb) UpdateMediatorInfoExpand(med *core.Mediator) error

func (*StateDb) UpdateStateByContractInvoke added in v1.0.1

func (statedb *StateDb) UpdateStateByContractInvoke(invoke *modules.ContractInvokeRequestPayload, unitTime int64,
	version *modules.StateVersion) error

type UtxoDb

type UtxoDb struct {
	ADDR_OUTPOINT_PREFIX []byte
	OUTPOINT_ADDR_PREFIX []byte
	SPENT_UTXO_PREFIX    []byte
	UTXO_PREFIX          []byte
	UTXO_INDEX_PREFIX    []byte
	// contains filtered or unexported fields
}

func NewUtxoDb

func NewUtxoDb(db ptndb.Database, tokenEngine tokenengine.ITokenEngine, isRequest bool) *UtxoDb

func (*UtxoDb) ClearAddrUtxo added in v1.0.4

func (db *UtxoDb) ClearAddrUtxo(addr common.Address) error

func (*UtxoDb) ClearUtxo

func (db *UtxoDb) ClearUtxo() error

func (*UtxoDb) DeleteUtxo

func (utxodb *UtxoDb) DeleteUtxo(outpoint *modules.OutPoint, spentTxId common.Hash, spentTime uint64) error

Remove the utxo

func (*UtxoDb) GetAddrOutpoints

func (db *UtxoDb) GetAddrOutpoints(address common.Address) ([]modules.OutPoint, error)

func (*UtxoDb) GetAddrUtxos

func (db *UtxoDb) GetAddrUtxos(addr common.Address, asset *modules.Asset) (
	map[modules.OutPoint]*modules.Utxo, error)

GetAddrUtxos if asset is nil, query all Asset from address

func (*UtxoDb) GetAllUtxos

func (db *UtxoDb) GetAllUtxos() (map[modules.OutPoint]*modules.Utxo, error)

func (*UtxoDb) GetRequestAndTxMapping added in v1.0.6

func (utxodb *UtxoDb) GetRequestAndTxMapping(hash common.Hash) (common.Hash, error)

func (*UtxoDb) GetStxoEntry added in v1.0.1

func (utxodb *UtxoDb) GetStxoEntry(outpoint *modules.OutPoint) (*modules.Stxo, error)

func (*UtxoDb) GetUtxoEntry

func (utxodb *UtxoDb) GetUtxoEntry(outpoint *modules.OutPoint) (*modules.Utxo, error)

###################### GET IMPL START ######################

dbFetchUtxoEntry

func (*UtxoDb) IsUtxoSpent added in v1.0.1

func (utxodb *UtxoDb) IsUtxoSpent(outpoint *modules.OutPoint) (bool, error)

func (*UtxoDb) SaveRequestAndTxHash added in v1.0.6

func (utxodb *UtxoDb) SaveRequestAndTxHash(requestHash common.Hash, txHash common.Hash) error

###################### GET IMPL END ######################

func (*UtxoDb) SaveStxoEntry added in v1.0.1

func (utxodb *UtxoDb) SaveStxoEntry(outpoint *modules.OutPoint, stxo *modules.Stxo) error

func (*UtxoDb) SaveUtxoEntity

func (utxodb *UtxoDb) SaveUtxoEntity(outpoint *modules.OutPoint, utxo *modules.Utxo) error

###################### UTXO Entity ######################

func (*UtxoDb) SaveUtxoSpent added in v1.0.1

func (utxodb *UtxoDb) SaveUtxoSpent(outpoint *modules.OutPoint, utxo *modules.Utxo,
	spentTxId common.Hash, spentTime uint64) error

func (*UtxoDb) SaveUtxoView

func (utxodb *UtxoDb) SaveUtxoView(view map[modules.OutPoint]*modules.Utxo) error

SaveUtxoView to update the utxo set in the database based on the provided utxo view.

Jump to

Keyboard shortcuts

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