chain

package
v0.0.0-...-4dde864 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODULENAME = "chain"
)

Variables

View Source
var (
	RootChain          types.ChainIdType
	DefaultChainConfig = &ChainConfig{
		RemotePort:  55556,
		ChainId:     RootChain,
		GenesisAddr: params.HoleAddress,
	}
)
View Source
var (
	MetaDataPrefix   = []byte("metaData_")
	ChainStatePrefix = []byte("chainState_")
	BlockPrefix      = []byte("block_")
	BlockNodePrefix  = []byte("blockNode_")
)
View Source
var (
	ErrInvalidateTimestamp       = errors.New("timestamp equals parent's")
	ErrInvalidateBlockNumber     = errors.New("invalid block number")
	ErrBlockNotFound             = errors.New("block not exist")
	ErrTxIndexOutOfRange         = errors.New("tx index out of range")
	ErrReachGasLimit             = errors.New("gasRemained limit reached")
	ErrInvalidateBlockMultisig   = errors.New("verify multisig error")
	ErrUnsupportTxType           = errors.New("not support transaction type")
	ErrNegativeAmount            = errors.New("negative amount in tx")
	ErrExceedGasLimit            = errors.New("gasRemained limit in tx has exceed block limit")
	ErrNonceTooHigh              = errors.New("nonce too high")
	ErrNonceTooLow               = errors.New("nonce too low")
	ErrTxPool                    = errors.New("transaction pool full")
	ErrInitStateFail             = errors.New("initChainState")
	ErrNotMathcedStateRoot       = errors.New("state root not matched")
	ErrGasUsed                   = errors.New("gasRemained used not matched")
	ErrChainId                   = errors.New("chainId not matched")
	ErrVersion                   = errors.New("version not matched")
	ErrPreHash                   = errors.New("previous hash not matched")
	ErrBlockExsist               = errors.New("already have block")
	ErrBalance                   = errors.New("not enough balance")
	ErrGas                       = errors.New("not enough gasRemained")
	ErrInsufficientBalanceForGas = errors.New("insufficient balance to pay for gasRemained")
	ErrOrphanBlockExsist         = errors.New("already have block (orphan)")
	ErrGenesisPkNotFound         = errors.New("genesisi pubkey not found")
	ErrBlockProducerNotFound     = errors.New("block producer not found")
	ErrNotSupportRenameAlias     = errors.New("not suppport rename alias")
	ErrTooShortAlias             = errors.New("alias too short")
	ErrTooLongAlias              = errors.New("alias too long")
	ErrUnsupportAliasChar        = errors.New("alias only support number and letter")
	ErrReceiptRoot               = errors.New("receipt root not match")

	ErrNoStorage   = errors.New("no account storage found")
	ErrKeyNotFound = errors.New("key not found")
	ErrKeyUnSpport = errors.New("unsupport")
	ErrOutOfGas    = errors.New("out of gas")
)

Functions

func CheckAlias

func CheckAlias(alias []byte) error

Types

type AliasTransactionProcessor

type AliasTransactionProcessor struct {
}

func (*AliasTransactionProcessor) ExecuteTransaction

func (aliasTransactionProcessor *AliasTransactionProcessor) ExecuteTransaction(context *ExecuteTransactionContext) *types.ExecuteTransactionResult

5 160000 640 6 80000 320 7 40000 160 8 20000 80 9 10000 40 10 5000 20 11 2500 10

type AliasTxSelector

type AliasTxSelector struct {
}

func (*AliasTxSelector) Select

func (liasTxSelector *AliasTxSelector) Select(tx *types.Transaction) bool

type BlockExecuteContext

type BlockExecuteContext struct {
	TrieStore store.StoreInterface
	Gp        *GasPool
	DbStore   *ChainStore
	Block     *types.Block
	GasUsed   *big.Int
	GasFee    *big.Int
	Logs      []*types.Log
	Receipts  types.Receipts
}

func NewBlockExecuteContext

func NewBlockExecuteContext(trieStore store.StoreInterface, gp *GasPool, dbStore *ChainStore, block *types.Block) *BlockExecuteContext

func (*BlockExecuteContext) AddGasFee

func (blockExecuteContext *BlockExecuteContext) AddGasFee(fee *big.Int)

func (*BlockExecuteContext) AddGasUsed

func (blockExecuteContext *BlockExecuteContext) AddGasUsed(gas *big.Int)

type BlockIndex

type BlockIndex struct {
	sync.RWMutex
	Index map[crypto.Hash]*types.BlockNode
	Dirty map[*types.BlockNode]struct{}
}

BlockIndex provides facilities for keeping track of an in-memory Index of the block chain. Although the name block chain suggests a single chain of blocks, it is actually a tree-shaped structure where any node can have multiple children. However, there can only be one active branch which does indeed form a chain from the tip all the way back to the genesis block.

func NewBlockIndex

func NewBlockIndex() *BlockIndex

newBlockIndex returns a new empty instance of a block Index. The Index will be dynamically populated as block nodes are loaded from the database and manually added.

func (*BlockIndex) AddNode

func (bi *BlockIndex) AddNode(node *types.BlockNode)

AddNode adds the provided node to the block Index and marks it as Dirty. Duplicate entries are not checked so it is up to caller to avoid adding them.

This function is safe for concurrent access.

func (*BlockIndex) ClearNode

func (bi *BlockIndex) ClearNode(node *types.BlockNode)

func (*BlockIndex) FlushToDB

func (bi *BlockIndex) FlushToDB(storeBlockNodeFunc func(node *types.BlockNode) error) error

FlushToDB writes all dirty block nodes to the database. If all writes succeed, this clears the dirty set.

func (*BlockIndex) HaveBlock

func (bi *BlockIndex) HaveBlock(hash *crypto.Hash) bool

HaveBlock returns whether or not the block Index contains the provided hash.

This function is safe for concurrent access.

func (*BlockIndex) LookupNode

func (bi *BlockIndex) LookupNode(hash *crypto.Hash) *types.BlockNode

LookupNode returns the block node identified by the provided hash. It will return nil if there is no entry for the hash.

This function is safe for concurrent access.

func (*BlockIndex) NodeStatus

func (bi *BlockIndex) NodeStatus(node *types.BlockNode) types.BlockStatus

NodeStatus provides concurrent-safe access to the status field of a node.

This function is safe for concurrent access.

func (*BlockIndex) SetStatusFlags

func (bi *BlockIndex) SetStatusFlags(node *types.BlockNode, flags types.BlockStatus)

SetStatusFlags flips the provided status flags on the block node to on, regardless of whether they were on or off previously. This does not unset any flags currently on.

This function is safe for concurrent access.

func (*BlockIndex) UnsetStatusFlags

func (bi *BlockIndex) UnsetStatusFlags(node *types.BlockNode, flags types.BlockStatus)

UnsetStatusFlags flips the provided status flags on the block node to off, regardless of whether they were on or off previously.

This function is safe for concurrent access.

type BlockValidators

type BlockValidators []IBlockValidator

func (BlockValidators) SelectByType

func (blockValidators BlockValidators) SelectByType(t reflect.Type) IBlockValidator

type CancelCandidateTransactionProcessor

type CancelCandidateTransactionProcessor struct {
}

func (*CancelCandidateTransactionProcessor) ExecuteTransaction

type CancelCandidateTxSelector

type CancelCandidateTxSelector struct {
}

func (*CancelCandidateTxSelector) Select

func (StakeTxSelector *CancelCandidateTxSelector) Select(tx *types.Transaction) bool

type CancelVoteTransactionProcessor

type CancelVoteTransactionProcessor struct {
}

func (*CancelVoteTransactionProcessor) ExecuteTransaction

type CancelVoteTxSelector

type CancelVoteTxSelector struct {
}

func (*CancelVoteTxSelector) Select

func (CancelStakeTxSelector *CancelVoteTxSelector) Select(tx *types.Transaction) bool

type CandidateTransactionProcessor

type CandidateTransactionProcessor struct {
}

func (*CandidateTransactionProcessor) ExecuteTransaction

type CandidateTxSelector

type CandidateTxSelector struct {
}

func (*CandidateTxSelector) Select

func (StakeTxSelector *CandidateTxSelector) Select(tx *types.Transaction) bool

type ChainApi

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

name: 链接口 usage: 用于获取区块信息 prefix:chain

func NewChainApi

func NewChainApi(store dbinterface.KeyValueStore, chainView *ChainView, dbQuery *ChainStore) *ChainApi

func (*ChainApi) GetAddressByAlias

func (chain *ChainApi) GetAddressByAlias(alias string) (*crypto.CommonAddress, error)
 name: getAddressByAlias
 usage: 根据别名获取别名对应的地址
 params:
	1. 待查询地别名
 return: 别名对应的地址
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getAddressByAlias","params":["tom"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"0x8a8e541ddd1272d53729164c70197221a3c27486"}

func (*ChainApi) GetAliasByAddress

func (chain *ChainApi) GetAliasByAddress(addr *crypto.CommonAddress) string
 name: getAliasByAddress
 usage: 根据地址获取地址对应的别名
 params:
	1. 待查询地址
 return: 地址别名
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getAliasByAddress","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
	{"jsonrpc":"2.0","id":3,"result":"tom"}

func (*ChainApi) GetBalance

func (chain *ChainApi) GetBalance(addr crypto.CommonAddress) string
 name: getBalance
 usage: 查询地址余额
 params:
	1. 待查询地址
 return: 地址中的账号余额
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getBalance","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":9987999999999984000000}

func (*ChainApi) GetBlock

func (chain *ChainApi) GetBlock(height uint64) (*types.Block, error)
 name: getblock
 usage: 用于获取区块信息
 params:
	1. height  usage: 当前区块高度
 return: 区块明细信息
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getBlock","params":[1], "id": 3}' -H "Content-Type:application/json"
 response:
{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "Hash": "0xcfa283a5b591da5a15971bf62fffae87e649bcf749776f4c83ffe50e65920f8e",
    "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "Version": 1,
    "PreviousHash": "0x1717b4b9f740cebeb2659886122a29c0876ed906dd05370319fee4ecf219b1e9",
    "GasLimit": 180000000,
    "GasUsed": 0,
    "Height": 1,
    "Timestamp": 1559272779,
    "StateRoot": "0xd7bd5b3af4f2f1fb3d484743052c2e911f9fb7b04131660912244347508f16a9",
    "TxRoot": "0x",
    "LeaderAddress": "0x0374bf9c8ea268b5548686685dda4a74fc95903ca7c440e5b187a718b595c1f374",
    "MinorAddresses": [
      "0x0374bf9c8ea268b5548686685dda4a74fc95903ca7c440e5b187a718b595c1f374",
      "0x02f11cfd138eaaaba5f8c0a7f1f2791bdabd0b0c404734dceac820aa9b683bfb1a",
      "0x03949aad279a32536ce20f0957c9c6ba592532ea70e5f174332bed4c94382354e3",
      "0x0263bc5628fa7033727d14b5d6714ac7d6a5d34bc5db994a896f54499f12db9b0b"
    ],
    "Txs": [

    ]
  }
}

func (*ChainApi) GetBlockGasInfo

func (chain *ChainApi) GetBlockGasInfo() string
 name: getBlockGasInfo
 usage: 获取gas相关信息
 params:
	1. 无
 return: 系统需要的gas最小值、最大值;和当前块被设置的最大gas值
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getBlockGasInfo","params":[], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":193005}

func (*ChainApi) GetByteCode

func (chain *ChainApi) GetByteCode(addr *crypto.CommonAddress) hexutil.Bytes
 name: getByteCode
 usage: 根据地址获取bytecode
 params:
	1. 地址
 return: bytecode
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getByteCode","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"0x00"}

func (*ChainApi) GetCancelCreditDetails

func (chain *ChainApi) GetCancelCreditDetails(addr *crypto.CommonAddress) string
 name: GetCancelCreditDetails
 usage: 获取所有退票请求的细节
 params:
	1. 地址
 return: bytecode
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getCancelCreditDetails","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"{\"0x300fc5a14e578be28c64627c0e7e321771c58cd4\":\"0x3641100\"}"}

func (*ChainApi) GetCandidateAddrs

func (chain *ChainApi) GetCandidateAddrs() string
 name: GetCandidateAddrs
 usage: 获取所有候选节点地址和对应的信任值
 params:
	1. 地址
 return:  []
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getCandidateAddrs","params":[""], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"{\"0x300fc5a14e578be28c64627c0e7e321771c58cd4\":\"0x3641100\"}"}

func (*ChainApi) GetChangeCycle

func (chain *ChainApi) GetChangeCycle() (int, error)
 name: getChangeCycle
 usage: 获取出块节点换届周期
 params:
	无
 return:  换届周期
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getChangeCycle","params":"", "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"{100}"}

func (*ChainApi) GetCreditDetails

func (chain *ChainApi) GetCreditDetails(addr *crypto.CommonAddress) string
 name: getVoteCreditDetails
 usage: 根据地址获取stake 所有细节信息
 params:
	1. 地址
 return: bytecode
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getCreditDetails","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"[{\"Addr\":\"0xd05d5f324ada3c418e14cd6b497f2f36d60ba607\",\"HeghtValues\":[{\"CreditHeight\":1329,\"CreditValue\":\"0x11135\"}]}]"}

func (*ChainApi) GetInterestRate

func (chain *ChainApi) GetInterestRate() (string, error)
 name: getInterestRate
 usage: 获取3个月内、3-6个月、6-12个月、12个月以上的利率
 params:
	无
 return:  年华后三个月利息, 年华后六个月利息, 一年期利息, 一年以上期利息
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getInterestRate","params":"", "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"{\"ThreeMonthRate\":4,\"SixMonthRate\":12,\"OneYearRate\":25,\"MoreOneYearRate\":51}"}

func (*ChainApi) GetInterset

func (chain *ChainApi) GetInterset(txHash crypto.Hash) []*types.IntersetDetail
 name: getInterset
 usage: 根据txhash获取退质押或者投票利息信息
 params:
	1. txhash
 return: {}
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getInterset","params":["0x7d9dd32ca192e765ff2abd7c5f8931cc3f77f8f47d2d52170c7804c2ca2c5dd9"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":""}

func (*ChainApi) GetLogs

func (chain *ChainApi) GetLogs(txHash crypto.Hash) []*types.Log
 name: getLogs
 usage: 根据txhash获取交易log信息
 params:
	1. txhash
 return: []log
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getLogs","params":["0x7d9dd32ca192e765ff2abd7c5f8931cc3f77f8f47d2d52170c7804c2ca2c5dd9"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":""}

func (*ChainApi) GetMaxHeight

func (chain *ChainApi) GetMaxHeight() uint64
 name: getMaxHeight
 usage: 用于获取当前最高区块
 params:
	1. 无
 return: 当前最高区块高度数值
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getMaxHeight","params":[], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":193005}

func (*ChainApi) GetNonce

func (chain *ChainApi) GetNonce(addr crypto.CommonAddress) uint64
 name: getNonce
 usage: 查询地址在链上的nonce
 params:
	1. 待查询地址
 return: 链上nonce
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getNonce","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":0}

func (*ChainApi) GetReceipt

func (chain *ChainApi) GetReceipt(txHash crypto.Hash) *types.Receipt
 name: getReceipt
 usage: 根据txhash获取receipt信息
 params:
	1. txhash
 return: receipt
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getReceipt","params":["0x7d9dd32ca192e765ff2abd7c5f8931cc3f77f8f47d2d52170c7804c2ca2c5dd9"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":""}

func (*ChainApi) GetReputation

func (chain *ChainApi) GetReputation(addr crypto.CommonAddress) *big.Int
 name: getNonce
 usage: 查询地址的名誉值
 params:
	1. 待查询地址
 return: 地址对应的名誉值
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getReputation","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":1}

func (*ChainApi) GetTransactionByBlockHeightAndIndex

func (chain *ChainApi) GetTransactionByBlockHeightAndIndex(height uint64, index int) (*types.Transaction, error)
 name: getTransactionByBlockHeightAndIndex
 usage: 获取区块中特定序列的交易
 params:
	1. 区块高度
    2. 交易序列
 return: 交易信息
 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"chain_getTransactionByBlockHeightAndIndex","params":[10000,1], "id": 3}' -H "Content-Type:application/json"
 response:
   {
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "Hash": "0xfa5c34114ff459b4c97e7cd268c507c0ccfcfc89d3ccdcf71e96402f9899d040",
    "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a",
    "Version": 1,
    "Nonce": 15632,
    "Type": 0,
    "To": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a",
    "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "Amount": "0x111",
    "GasPrice": "0x110",
    "GasLimit": "0x30000",
    "Timestamp": 1559322808,
    "Data": null,
    "Sig": "0x20f25b86c4bf73aa4fa0bcb01e2f5731de3a3917c8861d1ce0574a8d8331aedcf001e678000f6afc95d35a53ef623a2055fce687f85c2fd752dc455ab6db802b1f"
  }
}

type ChainBlockValidator

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

func NewChainBlockValidator

func NewChainBlockValidator(chainService *ChainService) *ChainBlockValidator

func (*ChainBlockValidator) ExecuteBlock

func (chainBlockValidator *ChainBlockValidator) ExecuteBlock(context *BlockExecuteContext) error

func (*ChainBlockValidator) RouteTransaction

func (chainBlockValidator *ChainBlockValidator) RouteTransaction(context *BlockExecuteContext, gasPool *GasPool, tx *types.Transaction) (*types.Receipt, uint64, error)

func (*ChainBlockValidator) VerifyBody

func (chainBlockValidator *ChainBlockValidator) VerifyBody(block *types.Block) error

func (*ChainBlockValidator) VerifyHeader

func (chainBlockValidator *ChainBlockValidator) VerifyHeader(header, parent *types.BlockHeader) error

type ChainConfig

type ChainConfig struct {
	RemotePort  int                  `json:"remoteport"`
	RootChain   types.ChainIdType    `json:"rootChain,omitempty"`
	ChainId     types.ChainIdType    `json:"chainId,omitempty"`
	GenesisAddr crypto.CommonAddress `json:"genesisaddr"`
}

type ChainService

type ChainService struct {
	RpcService      *rpc2.RpcService          `service:"rpc"`
	DatabaseService *database.DatabaseService `service:"database"`

	Config *ChainConfig
	// contains filtered or unexported fields
}

xxx

func (*ChainService) AcceptBlock

func (chainService *ChainService) AcceptBlock(block *types.Block) (inMainChain bool, err error)

func (*ChainService) AddBlockValidator

func (chainService *ChainService) AddBlockValidator(validator IBlockValidator)

func (*ChainService) AddGenesisProcess

func (chainService *ChainService) AddGenesisProcess(validator IGenesisProcess)

func (*ChainService) AddTransactionValidator

func (chainService *ChainService) AddTransactionValidator(selector ITransactionSelector, validator ITransactionValidator)

func (*ChainService) Api

func (chainService *ChainService) Api() []app.API

func (*ChainService) BestChain

func (chainService *ChainService) BestChain() *ChainView

func (*ChainService) BlockExists

func (chainService *ChainService) BlockExists(blockHash *crypto.Hash) bool

func (*ChainService) BlockValidator

func (chainService *ChainService) BlockValidator() BlockValidators

func (*ChainService) CalcGasLimit

func (chainService *ChainService) CalcGasLimit(parent *types.BlockHeader, gasFloor, gasCeil uint64) *big.Int

180000000/360

func (*ChainService) ChainID

func (chainService *ChainService) ChainID() types.ChainIdType

func (*ChainService) CommandFlags

func (chainService *ChainService) CommandFlags() ([]cli.Command, []cli.Flag)

func (*ChainService) DefaultConfig

func (chainService *ChainService) DefaultConfig() *ChainConfig

Config

func (*ChainService) DeriveMerkleRoot

func (cs *ChainService) DeriveMerkleRoot(txs []*types.Transaction) []byte

func (*ChainService) DeriveReceiptRoot

func (cs *ChainService) DeriveReceiptRoot(receipts []*types.Receipt) crypto.Hash

func (*ChainService) DetachBlockFeed

func (chainService *ChainService) DetachBlockFeed() *event.Feed

func (*ChainService) GetBlockByHash

func (chainService *ChainService) GetBlockByHash(hash *crypto.Hash) (*types.Block, error)

func (*ChainService) GetBlockByHeight

func (chainService *ChainService) GetBlockByHeight(number uint64) (*types.Block, error)

func (*ChainService) GetBlockHeaderByHash

func (chainService *ChainService) GetBlockHeaderByHash(hash *crypto.Hash) (*types.BlockHeader, error)

func (*ChainService) GetBlockHeaderByHeight

func (chainService *ChainService) GetBlockHeaderByHeight(number uint64) (*types.BlockHeader, error)

func (*ChainService) GetConfig

func (chainService *ChainService) GetConfig() *ChainConfig

func (*ChainService) GetCurrentHeader

func (chainService *ChainService) GetCurrentHeader() *types.BlockHeader

func (*ChainService) GetDatabaseService

func (chainService *ChainService) GetDatabaseService() *database.DatabaseService

func (*ChainService) GetGenisiBlock

func (chainService *ChainService) GetGenisiBlock(biosAddress crypto.CommonAddress) (*types.Block, error)

func (*ChainService) GetHeader

func (chainService *ChainService) GetHeader(hash crypto.Hash, number uint64) *types.BlockHeader

func (*ChainService) GetHighestBlock

func (chainService *ChainService) GetHighestBlock() (*types.Block, error)

func (*ChainService) GetLogsFeed

func (chainService *ChainService) GetLogsFeed() *event.Feed

func (*ChainService) GetOrphanRoot

func (b *ChainService) GetOrphanRoot(hash *crypto.Hash) *crypto.Hash

GetOrphanRoot returns the head of the chain for the provided hash from the map of orphan blocks.

This function is safe for concurrent access.

func (*ChainService) GetRMLogsFeed

func (chainService *ChainService) GetRMLogsFeed() *event.Feed

func (*ChainService) Index

func (chainService *ChainService) Index() *BlockIndex

func (*ChainService) Init

func (chainService *ChainService) Init(executeContext *app.ExecuteContext) error

func (*ChainService) InitStates

func (chainService *ChainService) InitStates() error

TODO improves the performan

func (*ChainService) IsKnownOrphan

func (b *ChainService) IsKnownOrphan(hash *crypto.Hash) bool

IsKnownOrphan returns whether the passed hash is currently a known orphan. Keep in mind that only a limited number of orphans are held onto for a limited amount of time, so this function must not be used as an absolute way to test if a block is an orphan block. A full block (as opposed to just its hash) must be passed to ProcessBlock for that purpose. However, calling ProcessBlock with an orphan that already exists results in an error, so this function provides a mechanism for a caller to intelligently detect *recent* duplicate orphans and react accordingly.

This function is safe for concurrent access.

func (*ChainService) Name

func (chainService *ChainService) Name() string

func (*ChainService) NewBlockFeed

func (chainService *ChainService) NewBlockFeed() *event.Feed

func (*ChainService) ProcessBlock

func (chainService *ChainService) ProcessBlock(block *types.Block) (bool, bool, error)

func (*ChainService) ProcessGenesisBlock

func (chainService *ChainService) ProcessGenesisBlock(biosAddr crypto.CommonAddress) (*types.Block, error)

func (*ChainService) RootChain

func (chainService *ChainService) RootChain() types.ChainIdType

func (*ChainService) Start

func (chainService *ChainService) Start(executeContext *app.ExecuteContext) error

func (*ChainService) Stop

func (chainService *ChainService) Stop(executeContext *app.ExecuteContext) error

func (*ChainService) TransactionValidators

func (chainService *ChainService) TransactionValidators() map[ITransactionSelector]ITransactionValidator

type ChainServiceInterface

type ChainServiceInterface interface {
	app.Service
	ChainID() types.ChainIdType
	DeriveMerkleRoot(txs []*types.Transaction) []byte
	DeriveReceiptRoot(receipts []*types.Receipt) crypto.Hash
	GetBlockByHash(hash *crypto.Hash) (*types.Block, error)
	GetBlockByHeight(number uint64) (*types.Block, error)

	//DefaultChainConfig
	GetBlockHeaderByHash(hash *crypto.Hash) (*types.BlockHeader, error)
	GetBlockHeaderByHeight(number uint64) (*types.BlockHeader, error)

	GetHeader(hash crypto.Hash, number uint64) *types.BlockHeader
	GetCurrentHeader() *types.BlockHeader
	GetHighestBlock() (*types.Block, error)
	RootChain() types.ChainIdType
	BestChain() *ChainView
	CalcGasLimit(parent *types.BlockHeader, gasFloor, gasCeil uint64) *big.Int
	ProcessBlock(block *types.Block) (bool, bool, error)
	NewBlockFeed() *event.Feed
	GetLogsFeed() *event.Feed
	GetRMLogsFeed() *event.Feed
	BlockExists(blockHash *crypto.Hash) bool
	Index() *BlockIndex
	BlockValidator() BlockValidators
	AddBlockValidator(validator IBlockValidator)
	TransactionValidators() map[ITransactionSelector]ITransactionValidator
	AddTransactionValidator(selector ITransactionSelector, validator ITransactionValidator)
	AddGenesisProcess(validator IGenesisProcess)
	GetConfig() *ChainConfig
	DetachBlockFeed() *event.Feed
}

type ChainState

type ChainState struct {
	types.BestState
	// contains filtered or unexported fields
}

type ChainStore

type ChainStore struct {
	dbinterface.KeyValueStore
}

func (*ChainStore) BlockNodeCount

func (chainStore *ChainStore) BlockNodeCount() int64

func (*ChainStore) BlockNodeIterator

func (chainStore *ChainStore) BlockNodeIterator(handle func(*types.BlockHeader, types.BlockStatus) error) error

func (*ChainStore) DeleteReceipts

func (chainStore *ChainStore) DeleteReceipts(blockHash crypto.Hash) error

func (*ChainStore) GetBlock

func (chainStore *ChainStore) GetBlock(hash *crypto.Hash) (*types.Block, error)

func (*ChainStore) GetBlockHeader

func (chainStore *ChainStore) GetBlockHeader(hash *crypto.Hash) (*types.BlockHeader, error)

func (*ChainStore) GetBlockNode

func (chainStore *ChainStore) GetBlockNode(hash *crypto.Hash, height uint64) (*types.BlockHeader, types.BlockStatus, error)

func (*ChainStore) GetReceipt

func (chainStore *ChainStore) GetReceipt(txHash crypto.Hash) *types.Receipt

func (*ChainStore) GetReceipts

func (chainStore *ChainStore) GetReceipts(blockHash crypto.Hash) []*types.Receipt

func (*ChainStore) HasBlock

func (chainStore *ChainStore) HasBlock(hash *crypto.Hash) bool

func (*ChainStore) PutBlock

func (chainStore *ChainStore) PutBlock(block *types.Block) error

func (*ChainStore) PutBlockNode

func (chainStore *ChainStore) PutBlockNode(blockNode *types.BlockNode) error

func (*ChainStore) PutReceipt

func (chainStore *ChainStore) PutReceipt(txHash crypto.Hash, receipt *types.Receipt) error

func (*ChainStore) PutReceipts

func (chainStore *ChainStore) PutReceipts(blockHash crypto.Hash, receipts []*types.Receipt) error

func (*ChainStore) RollBack

func (chainStore *ChainStore) RollBack(height uint64, hash *crypto.Hash) (error, int64)

type ChainView

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

chainView provides a flat view of a specific branch of the block chain from its tip back to the genesis block and provides various convenience functions for comparing chains.

For example, assume a block chain with a side chain as depicted below:

genesis -> 1 -> 2 -> 3 -> 4  -> 5 ->  6  -> 7  -> 8
                      \-> 4a -> 5a -> 6a

The chain view for the branch ending in 6a consists of:

genesis -> 1 -> 2 -> 3 -> 4a -> 5a -> 6a

func NewChainView

func NewChainView(tip *types.BlockNode) *ChainView

newChainView returns a new chain view for the given tip block node. Passing nil as the tip will result in a chain view that is not initialized. The tip can be updated at any time via the setTip function.

func (*ChainView) Contains

func (c *ChainView) Contains(node *types.BlockNode) bool

Contains returns whether or not the chain view contains the passed block node.

This function is safe for concurrent access.

func (*ChainView) Equals

func (c *ChainView) Equals(other *ChainView) bool

Equals returns whether or not two chain views are the same. Uninitialized views (tip set to nil) are considered equal.

This function is safe for concurrent access.

func (*ChainView) FindFork

func (c *ChainView) FindFork(node *types.BlockNode) *types.BlockNode

FindFork returns the final common block between the provided node and the the chain view. It will return nil if there is no common block.

For example, assume a block chain with a side chain as depicted below:

genesis -> 1 -> 2 -> ... -> 5 -> 6  -> 7  -> 8
                             \-> 6a -> 7a

Further, assume the view is for the longer chain depicted above. That is to say it consists of:

genesis -> 1 -> 2 -> ... -> 5 -> 6 -> 7 -> 8.

Invoking this function with block node 7a would return block node 5 while invoking it with block node 7 would return itself since it is already part of the branch formed by the view.

This function is safe for concurrent access.

func (*ChainView) Genesis

func (c *ChainView) Genesis() *types.BlockNode

Genesis returns the genesis block for the chain view.

This function is safe for concurrent access.

func (*ChainView) Height

func (c *ChainView) Height() uint64

Height returns the height of the tip of the chain view. It will return -1 if there is no tip (which only happens if the chain view has not been initialized).

This function is safe for concurrent access.

func (*ChainView) Next

func (c *ChainView) Next(node *types.BlockNode) *types.BlockNode

Next returns the successor to the provided node for the chain view. It will return nil if there is no successfor or the provided node is not part of the view.

For example, assume a block chain with a side chain as depicted below:

genesis -> 1 -> 2 -> 3 -> 4  -> 5 ->  6  -> 7  -> 8
                      \-> 4a -> 5a -> 6a

Further, assume the view is for the longer chain depicted above. That is to say it consists of:

genesis -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8

Invoking this function with block node 5 would return block node 6 while invoking it with block node 5a would return nil since that node is not part of the view.

This function is safe for concurrent access.

func (*ChainView) NodeByHeight

func (c *ChainView) NodeByHeight(height uint64) *types.BlockNode

NodeByHeight returns the block node at the specified height. Nil will be returned if the height does not exist.

This function is safe for concurrent access.

func (*ChainView) SetTip

func (c *ChainView) SetTip(node *types.BlockNode)

SetTip sets the chain view to use the provided block node as the current tip and ensures the view is consistent by populating it with the nodes obtained by walking backwards all the way to genesis block as necessary. Further calls will only perform the minimum work needed, so switching between chain tips is efficient.

This function is safe for concurrent access.

func (*ChainView) Tip

func (c *ChainView) Tip() *types.BlockNode

Tip returns the current tip block node for the chain view. It will return nil if there is no tip.

This function is safe for concurrent access.

type ExecuteTransactionContext

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

func NewExecuteTransactionContext

func NewExecuteTransactionContext(blockContext *BlockExecuteContext, chainstore store.StoreInterface, gasPool *GasPool, from *crypto.CommonAddress, tx *types.Transaction) *ExecuteTransactionContext

func (*ExecuteTransactionContext) Data

func (context *ExecuteTransactionContext) Data() []byte

func (*ExecuteTransactionContext) From

func (*ExecuteTransactionContext) GasPrice

func (context *ExecuteTransactionContext) GasPrice() *big.Int

func (*ExecuteTransactionContext) GasRemained

func (context *ExecuteTransactionContext) GasRemained() uint64

func (*ExecuteTransactionContext) GasUsed

func (context *ExecuteTransactionContext) GasUsed() uint64

gasRemained returns the amount of gasRemained used up by the state transition.

func (*ExecuteTransactionContext) Gp

func (context *ExecuteTransactionContext) Gp() *GasPool

func (*ExecuteTransactionContext) Header

func (context *ExecuteTransactionContext) Header() *types.BlockHeader

func (*ExecuteTransactionContext) InitialGas

func (context *ExecuteTransactionContext) InitialGas() uint64

func (*ExecuteTransactionContext) PreCheck

func (context *ExecuteTransactionContext) PreCheck() error

func (*ExecuteTransactionContext) RefundCoin

func (context *ExecuteTransactionContext) RefundCoin() error

func (*ExecuteTransactionContext) RefundGas

func (context *ExecuteTransactionContext) RefundGas(refundGas uint64)

func (*ExecuteTransactionContext) To

func (*ExecuteTransactionContext) TrieStore

func (context *ExecuteTransactionContext) TrieStore() store.StoreInterface

func (*ExecuteTransactionContext) Tx

func (*ExecuteTransactionContext) UseGas

func (context *ExecuteTransactionContext) UseGas(amount uint64) error

func (*ExecuteTransactionContext) Value

func (context *ExecuteTransactionContext) Value() *big.Int

type GasPool

type GasPool uint64

GasPool tracks the amount of gasRemained available during execution of the transactions in a block. The zero value is a pool with zero gasRemained available.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

AddGas makes gasRemained available for execution.

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

Gas returns the amount of gasRemained remaining in the pool.

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error

SubGas deducts the given amount from the pool if enough gasRemained is available and returns an error otherwise.

type GenesisContext

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

GenesisContext used to deliver config information through all genesis processor

func NewGenesisContext

func NewGenesisContext(genesisContent *json.RawMessage, store store.StoreInterface) (*GenesisContext, error)

func (GenesisContext) Config

func (g GenesisContext) Config() map[string]json.RawMessage

func (GenesisContext) Store

type IBlockValidator

type IBlockValidator interface {
	VerifyHeader(header, parent *types.BlockHeader) error

	VerifyBody(block *types.Block) error

	ExecuteBlock(context *BlockExecuteContext) error
}

type IGenesisProcess

type IGenesisProcess interface {
	Genesis(context *GenesisContext) error
}

Process genesis contract

type ITransactionSelector

type ITransactionSelector interface {
	Select(tx *types.Transaction) bool
}

type ITransactionValidator

type ITransactionValidator interface {
	ExecuteTransaction(context *ExecuteTransactionContext) *types.ExecuteTransactionResult
}

type Preminer

type Preminer struct {
	Addr  crypto.CommonAddress
	Value big.Int
}

type PreminerGenesisProcessor

type PreminerGenesisProcessor struct {
}

func NewPreminerGenesisProcessor

func NewPreminerGenesisProcessor() *PreminerGenesisProcessor

func (*PreminerGenesisProcessor) Genesis

func (NewPreminerGenesisProcessor *PreminerGenesisProcessor) Genesis(context *GenesisContext) error

type StakeTransactionProcessor

type StakeTransactionProcessor struct {
}

func (*StakeTransactionProcessor) ExecuteTransaction

func (processor *StakeTransactionProcessor) ExecuteTransaction(context *ExecuteTransactionContext) *types.ExecuteTransactionResult

type StakeTxSelector

type StakeTxSelector struct {
}

func (*StakeTxSelector) Select

func (StakeTxSelector *StakeTxSelector) Select(tx *types.Transaction) bool

type TransferTransactionProcessor

type TransferTransactionProcessor struct {
}

func (*TransferTransactionProcessor) ExecuteTransaction

func (transferTransactionProcessor *TransferTransactionProcessor) ExecuteTransaction(context *ExecuteTransactionContext) *types.ExecuteTransactionResult

type TransferTxSelector

type TransferTxSelector struct {
}

***************** transfer *******************

func (*TransferTxSelector) Select

func (transferTxSelector *TransferTxSelector) Select(tx *types.Transaction) bool

type TrieQuery

type TrieQuery struct {
	dbinterface.KeyValueStore
	// contains filtered or unexported fields
}

func NewTrieQuery

func NewTrieQuery(store dbinterface.KeyValueStore, root []byte) (*TrieQuery, error)

func (*TrieQuery) AliasExist

func (trieQuery *TrieQuery) AliasExist(alias string) bool

func (*TrieQuery) AliasGet

func (trieQuery *TrieQuery) AliasGet(alias string) (*crypto.CommonAddress, error)

func (*TrieQuery) Get

func (trieQuery *TrieQuery) Get(key []byte) ([]byte, error)

func (*TrieQuery) GetBalance

func (trieQuery *TrieQuery) GetBalance(addr *crypto.CommonAddress) *big.Int

func (*TrieQuery) GetByteCode

func (trieQuery *TrieQuery) GetByteCode(addr *crypto.CommonAddress) []byte

func (*TrieQuery) GetCancelCreditDetails

func (trieQuery *TrieQuery) GetCancelCreditDetails(addr *crypto.CommonAddress) string

func (*TrieQuery) GetCandidateAddrs

func (trieQuery *TrieQuery) GetCandidateAddrs() string

func (*TrieQuery) GetCodeHash

func (trieQuery *TrieQuery) GetCodeHash(addr *crypto.CommonAddress) crypto.Hash

func (*TrieQuery) GetNonce

func (trieQuery *TrieQuery) GetNonce(addr *crypto.CommonAddress) uint64

func (*TrieQuery) GetReputation

func (trieQuery *TrieQuery) GetReputation(addr *crypto.CommonAddress) *big.Int

func (*TrieQuery) GetStorage

func (trieQuery *TrieQuery) GetStorage(addr *crypto.CommonAddress) (types.Storage, error)

func (*TrieQuery) GetStorageAlias

func (trieQuery *TrieQuery) GetStorageAlias(addr *crypto.CommonAddress) string

func (*TrieQuery) GetVoteCreditDetails

func (trieQuery *TrieQuery) GetVoteCreditDetails(addr *crypto.CommonAddress) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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