Documentation
¶
Index ¶
- Constants
- Variables
- func InvokeRequestFromJSON2Pb(jsonRequest []InvokeRequest) ([]*protos.InvokeRequest, error)
- func MakeBlockID(block *pb.InternalBlock) ([]byte, error)
- func MakeMerkleTree(txList []*pb.Transaction) [][]byte
- func VerifyMerkle(block *pb.InternalBlock) error
- type ConfirmStatus
- type GasPrice
- type GenesisBlock
- type InvokeRequest
- type Ledger
- func (l *Ledger) AssignRewards(address string, blockAward *big.Int) *big.Int
- func (l *Ledger) Close()
- func (l *Ledger) ConfirmBlock(block *pb.InternalBlock, isRoot bool) ConfirmStatus
- func (l *Ledger) Discount(write kvdb.Batch, args map[string]string, initiator string, tx *pb.Transaction)
- func (l *Ledger) Dump() ([][]string, error)
- func (l *Ledger) ExistBlock(blockid []byte) bool
- func (l *Ledger) FindUndoAndTodoBlocks(curBlockid []byte, destBlockid []byte) ([]*pb.InternalBlock, []*pb.InternalBlock, error)
- func (l *Ledger) FormatBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, ...) (*pb.InternalBlock, error)
- func (l *Ledger) FormatFakeBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, ...) (*pb.InternalBlock, error)
- func (l *Ledger) FormatMinerBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, ...) (*pb.InternalBlock, error)
- func (l *Ledger) FormatRootBlock(txList []*pb.Transaction) (*pb.InternalBlock, error)
- func (l *Ledger) GetAward() string
- func (l *Ledger) GetBaseDB() kvdb.Database
- func (l *Ledger) GetBranchInfo(targetBlockid []byte, targetBlockHeight int64) ([]string, error)
- func (l *Ledger) GetCommonParentBlockid(branch1Blockid, branch2Blockid []byte) ([]byte, error)
- func (l *Ledger) GetForbiddenContract() ([]*protos.InvokeRequest, error)
- func (l *Ledger) GetGasPrice() *protos.GasPrice
- func (l *Ledger) GetGenesisBlock() *GenesisBlock
- func (l *Ledger) GetGroupChainContract() ([]*protos.InvokeRequest, error)
- func (l *Ledger) GetIrreversibleSlideWindow() int64
- func (l *Ledger) GetLDB() kvdb.Database
- func (l *Ledger) GetMaxBlockSize() int64
- func (l *Ledger) GetMeta() *pb.LedgerMeta
- func (l *Ledger) GetNewAccountResourceAmount() int64
- func (l *Ledger) GetNoFee() bool
- func (l *Ledger) GetPendingBlock(blockID []byte) (*pb.InternalBlock, error)
- func (l *Ledger) GetReservedContracts() ([]*protos.InvokeRequest, error)
- func (l *Ledger) GetTokenRequired(height int64) *big.Int
- func (l *Ledger) GetTransferFeeAmount() int64
- func (l *Ledger) HandleFork(oldTip []byte, newTip []byte, batchWrite kvdb.Batch) (*pb.InternalBlock, error)
- func (l *Ledger) HasTransaction(txid []byte) (bool, error)
- func (l *Ledger) IsTxInTrunk(txid []byte) bool
- func (l *Ledger) IsValidTx(idx int, tx *pb.Transaction, block *pb.InternalBlock) bool
- func (l *Ledger) QueryBlock(blockid []byte) (*pb.InternalBlock, error)
- func (l *Ledger) QueryBlockByHeight(height int64) (*pb.InternalBlock, error)
- func (l *Ledger) QueryBlockByTxid(txid []byte) (*pb.InternalBlock, error)
- func (l *Ledger) QueryBlockHeader(blockid []byte) (*pb.InternalBlock, error)
- func (l *Ledger) QueryBlockHeaderByHeight(height int64) (*pb.InternalBlock, error)
- func (l *Ledger) QueryTransaction(txid []byte) (*pb.Transaction, error)
- func (l *Ledger) ReadBallotTable(user string, table *protos.CandidateRatio) error
- func (l *Ledger) RemoveBlocks(fromBlockid []byte, toBlockid []byte, batch kvdb.Batch) error
- func (l *Ledger) RevokeVote(batch kvdb.Batch, user string, Args map[string]string) error
- func (l *Ledger) SavePendingBlock(block *pb.InternalBlock) error
- func (l *Ledger) SetMeta(meta *pb.LedgerMeta)
- func (l *Ledger) Truncate(utxovmLastID []byte) error
- func (l *Ledger) UpdateBlockChainData(txid string, ptxid string, publickey string, sign string, height int64) error
- func (l *Ledger) VerifyBlock(block *pb.InternalBlock, logid string) (bool, error)
- func (l *Ledger) VoteCandidateTable(batch kvdb.Batch, user string, Args map[string]string) error
- func (l *Ledger) WriteCandidateTable(batch kvdb.Batch, user string, Args map[string]string, height int64) error
- func (l *Ledger) WriteFreezeTable(batch kvdb.Batch, amount string, user string, tx *pb.Transaction) error
- func (l *Ledger) WriteReCandidateTable(batch kvdb.Batch, user string, Args map[string]string) error
- func (l *Ledger) WriteThawTable(batch kvdb.Batch, cliAmount string, user string, tx *pb.Transaction) error
- type LedgerCtx
- type Predistribution
- type RootConfig
- func (rc *RootConfig) GetAward() string
- func (rc *RootConfig) GetCryptoType() string
- func (rc *RootConfig) GetForbiddenContract() ([]*protos.InvokeRequest, error)
- func (rc *RootConfig) GetGasPrice() *protos.GasPrice
- func (rc *RootConfig) GetGenesisConsensus() (map[string]interface{}, error)
- func (rc *RootConfig) GetGroupChainContract() ([]*protos.InvokeRequest, error)
- func (rc *RootConfig) GetIrreversibleSlideWindow() int64
- func (rc *RootConfig) GetMaxBlockSizeInByte() (n int64)
- func (rc *RootConfig) GetNewAccountResourceAmount() int64
- func (rc *RootConfig) GetNominatePercent() int64
- func (rc *RootConfig) GetPredistribution() []Predistribution
- func (rc *RootConfig) GetReservedContract() ([]*protos.InvokeRequest, error)
- func (rc *RootConfig) GetReservedWhitelistAccount() string
- func (rc *RootConfig) GetTransferFeeAmount() int64
- type TxDesc
Constants ¶
const ( // RootBlockVersion for version 1 RootBlockVersion = 0 // BlockVersion for version 1 BlockVersion = 1 // BlockCacheSize block counts in lru cache BlockCacheSize = 1000 // block counts in lru cache TxCacheSize = 100000 // tx counts in lru cache MaxBlockSizeKey = "MaxBlockSize" ReservedContractsKey = "ReservedContracts" ForbiddenContractKey = "ForbiddenContract" NewAccountResourceAmountKey = "NewAccountResourceAmount" // Irreversible block height & slide window IrreversibleBlockHeightKey = "IrreversibleBlockHeight" IrreversibleSlideWindowKey = "IrreversibleSlideWindow" GasPriceKey = "GasPrice" GroupChainContractKey = "GroupChainContract" TransferFeeAmountKey = "TransferFeeAmount" AwardKey = "Award" )
Variables ¶
var ( // ErrBlockNotExist is returned when a block to query not exist in specific chain ErrBlockNotExist = errors.New("block not exist in this chain") // ErrTxNotFound is returned when a transaction to query not exist in confirmed table ErrTxNotFound = errors.New("transaction not found") // ErrTxDuplicated ... ErrTxDuplicated = errors.New("transaction duplicated in different blocks") // ErrRootBlockAlreadyExist is returned when two genesis block is checked in the process of confirming block ErrRootBlockAlreadyExist = errors.New("this ledger already has genesis block") // ErrTxNotConfirmed return tx not confirmed error ErrTxNotConfirmed = errors.New("transaction not confirmed") // NumCPU returns the number of CPU cores for the current system NumCPU = runtime.NumCPU() )
var ( // MemCacheSize baseDB memory level max size MemCacheSize = 128 //MB // FileHandlersCacheSize baseDB memory file handler cache max size FileHandlersCacheSize = 1024 //how many opened files-handlers cached // DisableTxDedup ... DisableTxDedup = false //whether disable dedup tx before confirm )
Functions ¶
func InvokeRequestFromJSON2Pb ¶
func InvokeRequestFromJSON2Pb(jsonRequest []InvokeRequest) ([]*protos.InvokeRequest, error)
func MakeBlockID ¶
func MakeBlockID(block *pb.InternalBlock) ([]byte, error)
MakeBlockID generate BlockID
func MakeMerkleTree ¶
func MakeMerkleTree(txList []*pb.Transaction) [][]byte
MakeMerkleTree generate merkele-tree
Types ¶
type ConfirmStatus ¶
type ConfirmStatus struct { Succ bool // 区块是否提交成功 Split bool // 提交后是否发生了分叉 Orphan bool // 是否是个孤儿节点 TrunkSwitch bool // 是否导致了主干分支切换 Error error //错误消息 }
ConfirmStatus block status
type GasPrice ¶
type GasPrice struct { CpuRate int64 `json:"cpu_rate" mapstructure:"cpu_rate"` MemRate int64 `json:"mem_rate" mapstructure:"mem_rate"` DiskRate int64 `json:"disk_rate" mapstructure:"disk_rate"` XfeeRate int64 `json:"xfee_rate" mapstructure:"xfee_rate"` }
GasPrice define gas rate for utxo
type GenesisBlock ¶
type GenesisBlock struct {
// contains filtered or unexported fields
}
GenesisBlock genesis block data structure
func NewGenesisBlock ¶
func NewGenesisBlock(genesisCfg []byte) (*GenesisBlock, error)
NewGenesisBlock new a genesis block
func (*GenesisBlock) CalcAward ¶
func (gb *GenesisBlock) CalcAward(blockHeight int64) *big.Int
CalcAward calc system award by block height
func (*GenesisBlock) GetConfig ¶
func (gb *GenesisBlock) GetConfig() *RootConfig
GetConfig get config of genesis block
type InvokeRequest ¶
type InvokeRequest struct { ModuleName string `json:"module_name" mapstructure:"module_name"` ContractName string `json:"contract_name" mapstructure:"contract_name"` MethodName string `json:"method_name" mapstructure:"method_name"` Args map[string]string `json:"args" mapstructure:"args"` }
InvokeRequest define genesis reserved_contracts configure
type Ledger ¶
type Ledger struct { ConfirmedTable kvdb.Database // 已确认的订单表 GenesisBlock *GenesisBlock //创始块 ConfirmBatch kvdb.Batch //新增区块 // contains filtered or unexported fields }
Ledger define data structure of Ledger
func CreateLedger ¶
NewLedger create an empty ledger, if it already exists, open it directly
func OpenLedger ¶
OpenLedger open ledger which already exists
func (*Ledger) AssignRewards ¶
//设置奖励分配
func (*Ledger) ConfirmBlock ¶
func (l *Ledger) ConfirmBlock(block *pb.InternalBlock, isRoot bool) ConfirmStatus
ConfirmBlock submit a block to ledger
func (*Ledger) Discount ¶
func (l *Ledger) Discount(write kvdb.Batch, args map[string]string, initiator string, tx *pb.Transaction)
用户分红奖励提现
func (*Ledger) ExistBlock ¶
ExistBlock check if a block exists in the ledger
func (*Ledger) FindUndoAndTodoBlocks ¶
func (l *Ledger) FindUndoAndTodoBlocks(curBlockid []byte, destBlockid []byte) ([]*pb.InternalBlock, []*pb.InternalBlock, error)
FindUndoAndTodoBlocks get blocks required to undo and todo range from curBlockid to destBlockid
func (*Ledger) FormatBlock ¶
func (l *Ledger) FormatBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, timestamp int64, curTerm int64, curBlockNum int64, preHash []byte, utxoTotal *big.Int) (*pb.InternalBlock, error)
FormatBlock format normal block
func (*Ledger) FormatFakeBlock ¶
func (l *Ledger) FormatFakeBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, timestamp int64, curTerm int64, curBlockNum int64, preHash []byte, utxoTotal *big.Int, blockHeight int64) (*pb.InternalBlock, error)
FormatFakeBlock format fake block for contract pre-execution without signing
func (*Ledger) FormatMinerBlock ¶
func (l *Ledger) FormatMinerBlock(txList []*pb.Transaction, proposer []byte, ecdsaPk *ecdsa.PrivateKey, timestamp int64, curTerm int64, curBlockNum int64, preHash []byte, targetBits int32, utxoTotal *big.Int, qc *pb.QuorumCert, failedTxs map[string]string, blockHeight int64) (*pb.InternalBlock, error)
FormatMinerBlock format block for miner
func (*Ledger) FormatRootBlock ¶
func (l *Ledger) FormatRootBlock(txList []*pb.Transaction) (*pb.InternalBlock, error)
FormatRootBlock format genesis block
func (*Ledger) GetBranchInfo ¶
func (*Ledger) GetCommonParentBlockid ¶
func (*Ledger) GetForbiddenContract ¶
func (l *Ledger) GetForbiddenContract() ([]*protos.InvokeRequest, error)
func (*Ledger) GetGasPrice ¶
func (*Ledger) GetGenesisBlock ¶
func (l *Ledger) GetGenesisBlock() *GenesisBlock
GetGenesisBlock returns genesis block if it exists
func (*Ledger) GetGroupChainContract ¶
func (l *Ledger) GetGroupChainContract() ([]*protos.InvokeRequest, error)
func (*Ledger) GetIrreversibleSlideWindow ¶
GetIrreversibleSlideWindow return irreversible slide window
func (*Ledger) GetMaxBlockSize ¶
GetMaxBlockSize return max block size
func (*Ledger) GetMeta ¶
func (l *Ledger) GetMeta() *pb.LedgerMeta
GetMeta returns meta info of Ledger, such as genesis block ID, current block height, tip block ID
func (*Ledger) GetNewAccountResourceAmount ¶
GetNewAccountResourceAmount return the resource amount of new an account
func (*Ledger) GetPendingBlock ¶
func (l *Ledger) GetPendingBlock(blockID []byte) (*pb.InternalBlock, error)
GetPendingBlock get block from pending table
func (*Ledger) GetReservedContracts ¶
func (l *Ledger) GetReservedContracts() ([]*protos.InvokeRequest, error)
func (*Ledger) HandleFork ¶
func (*Ledger) HasTransaction ¶
HasTransaction check if a transaction exists in the ledger
func (*Ledger) IsTxInTrunk ¶
IsTxInTrunk check if a transaction is in trunk by transaction ID
func (*Ledger) IsValidTx ¶
func (l *Ledger) IsValidTx(idx int, tx *pb.Transaction, block *pb.InternalBlock) bool
IsValidTx valid transactions of coinbase in block
func (*Ledger) QueryBlock ¶
func (l *Ledger) QueryBlock(blockid []byte) (*pb.InternalBlock, error)
QueryBlock query a block by blockID in the ledger
func (*Ledger) QueryBlockByHeight ¶
func (l *Ledger) QueryBlockByHeight(height int64) (*pb.InternalBlock, error)
QueryBlockByHeight query block by height
func (*Ledger) QueryBlockByTxid ¶
func (l *Ledger) QueryBlockByTxid(txid []byte) (*pb.InternalBlock, error)
QueryBlockByTxid query block by txid after it has confirmed
func (*Ledger) QueryBlockHeader ¶
func (l *Ledger) QueryBlockHeader(blockid []byte) (*pb.InternalBlock, error)
QueryBlockHeader query a block by blockID in the ledger and return only block header
func (*Ledger) QueryBlockHeaderByHeight ¶ added in v1.0.2
func (l *Ledger) QueryBlockHeaderByHeight(height int64) (*pb.InternalBlock, error)
QueryBlockHeaderByHeight query block header by height
func (*Ledger) QueryTransaction ¶
func (l *Ledger) QueryTransaction(txid []byte) (*pb.Transaction, error)
QueryTransaction query a transaction in the ledger and return it if exist
func (*Ledger) ReadBallotTable ¶
func (l *Ledger) ReadBallotTable(user string, table *protos.CandidateRatio) error
读治理代币表
func (*Ledger) RemoveBlocks ¶
func (*Ledger) RevokeVote ¶
撤销投票写表
func (*Ledger) SavePendingBlock ¶
func (l *Ledger) SavePendingBlock(block *pb.InternalBlock) error
SavePendingBlock put block into pending table
func (*Ledger) SetMeta ¶
func (l *Ledger) SetMeta(meta *pb.LedgerMeta)
func (*Ledger) UpdateBlockChainData ¶
func (l *Ledger) UpdateBlockChainData(txid string, ptxid string, publickey string, sign string, height int64) error
UpdateBlockChainData modify tx which txid is txid
func (*Ledger) VerifyBlock ¶
VerifyBlock verify block
func (*Ledger) VoteCandidateTable ¶
投票写表
func (*Ledger) WriteCandidateTable ¶
func (l *Ledger) WriteCandidateTable(batch kvdb.Batch, user string, Args map[string]string, height int64) error
提案写表
func (*Ledger) WriteFreezeTable ¶
func (l *Ledger) WriteFreezeTable(batch kvdb.Batch, amount string, user string, tx *pb.Transaction) error
写入冻结表
func (*Ledger) WriteReCandidateTable ¶
撤销提案写表
func (*Ledger) WriteThawTable ¶
func (l *Ledger) WriteThawTable(batch kvdb.Batch, cliAmount string, user string, tx *pb.Transaction) error
申请解冻
type LedgerCtx ¶
type LedgerCtx struct { // 基础上下文 xctx.BaseCtx // 运行环境配置 EnvCfg *xconf.EnvConf // 账本配置 LedgerCfg *lconf.XLedgerConf // 链名 BCName string }
账本运行上下文环境
type Predistribution ¶
func PredistributionTranslator ¶
func PredistributionTranslator(predistribution []struct { Address string `json:"address"` Quota string `json:"quota"` }) []Predistribution
type RootConfig ¶
type RootConfig struct { Version string `json:"version"` Crypto string `json:"crypto"` Kvengine string `json:"kvengine"` Consensus struct { Type string `json:"type"` Miner string `json:"miner"` } `json:"consensus"` Predistribution []struct { Address string `json:"address"` Quota string `json:"quota"` } // max block size in MB MaxBlockSize string `json:"maxblocksize"` Period string `json:"period"` NoFee bool `json:"nofee"` Award string `json:"award"` AwardDecay struct { HeightGap int64 `json:"height_gap"` Ratio float64 `json:"ratio"` } `json:"award_decay"` GasPrice struct { CpuRate int64 `json:"cpu_rate"` MemRate int64 `json:"mem_rate"` DiskRate int64 `json:"disk_rate"` XfeeRate int64 `json:"xfee_rate"` } `json:"gas_price"` Decimals string `json:"decimals"` GenesisConsensus map[string]interface{} `json:"genesis_consensus"` ReservedContracts []InvokeRequest `json:"reserved_contracts"` ReservedWhitelist struct { Account string `json:"account"` } `json:"reserved_whitelist"` ForbiddenContract InvokeRequest `json:"forbidden_contract"` // NewAccountResourceAmount the amount of creating a new contract account NewAccountResourceAmount int64 `json:"new_account_resource_amount"` // IrreversibleSlideWindow IrreversibleSlideWindow string `json:"irreversibleslidewindow"` // GroupChainContract GroupChainContract InvokeRequest `json:"group_chain_contract"` TransferFeeAmount int64 `json:"transfer_fee_amount"` //转账手续费 NominatePercent int64 `json:"nominate_percent"` // tdpos共识提名候选人时需要质押全网代币总量的最小比例 }
RootConfig genesis block configure
func (*RootConfig) GetCryptoType ¶
func (rc *RootConfig) GetCryptoType() string
func (*RootConfig) GetForbiddenContract ¶
func (rc *RootConfig) GetForbiddenContract() ([]*protos.InvokeRequest, error)
func (*RootConfig) GetGasPrice ¶
func (rc *RootConfig) GetGasPrice() *protos.GasPrice
GetGasPrice get gas rate for different resource(cpu, mem, disk and xfee)
func (*RootConfig) GetGenesisConsensus ¶
func (rc *RootConfig) GetGenesisConsensus() (map[string]interface{}, error)
GetGenesisConsensus get consensus config of genesis block
func (*RootConfig) GetGroupChainContract ¶
func (rc *RootConfig) GetGroupChainContract() ([]*protos.InvokeRequest, error)
func (*RootConfig) GetIrreversibleSlideWindow ¶
func (rc *RootConfig) GetIrreversibleSlideWindow() int64
GetIrreversibleSlideWindow get irreversible slide window
func (*RootConfig) GetMaxBlockSizeInByte ¶
func (rc *RootConfig) GetMaxBlockSizeInByte() (n int64)
GetMaxBlockSizeInByte get max block size in Byte
func (*RootConfig) GetNewAccountResourceAmount ¶
func (rc *RootConfig) GetNewAccountResourceAmount() int64
GetNewAccountResourceAmount get the resource amount of new an account
func (*RootConfig) GetNominatePercent ¶
func (rc *RootConfig) GetNominatePercent() int64
func (*RootConfig) GetPredistribution ¶
func (rc *RootConfig) GetPredistribution() []Predistribution
GetPredistribution return predistribution
func (*RootConfig) GetReservedContract ¶
func (rc *RootConfig) GetReservedContract() ([]*protos.InvokeRequest, error)
GetReservedContract get default contract config of genesis block
func (*RootConfig) GetReservedWhitelistAccount ¶
func (rc *RootConfig) GetReservedWhitelistAccount() string
GetReservedWhitelistAccount return reserved whitelist account
func (*RootConfig) GetTransferFeeAmount ¶
func (rc *RootConfig) GetTransferFeeAmount() int64
添加获取手续费的函数