chain

package
v0.0.0-...-a173fca Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: LGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODULENAME = "chain"
)

Variables

View Source
var (
	DefaultChainConfigMainnet = &ChainConfig{
		RemotePort:  params.RemotePortMainnet,
		ChainId:     types.ChainIdType(params.RootChain),
		GenesisAddr: params.HoleAddress,
	}

	DefaultChainConfigTestnet = &ChainConfig{
		RemotePort:  params.RemotePortTestnet,
		ChainId:     types.ChainIdType(params.RootChain),
		GenesisAddr: params.HoleAddress,
	}
)
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 gas of block")
	ErrTxUnSupport = errors.New("unsupported transaction type")
)

Functions

This section is empty.

Types

type BlockValidators

type BlockValidators []IBlockValidator

func (BlockValidators) SelectByType

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

type ChainApi

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

name: Block chain API usage: Used to obtain block information prefix:chain

func NewChainApi

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

func (*ChainApi) GetAddressByAlias

func (chain *ChainApi) GetAddressByAlias(alias string) (*crypto.CommonAddress, error)
 name: getAddressByAlias
 usage: Gets the address corresponding to the alias based on the alias
 params:
	1. Alias to be queried
 return: The address corresponding to the alias
 example: curl http://localhost:10085 -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: Gets the alias corresponding to the address according to the address
 params:
	1. address
 return: Address the alias
 example: curl http://localhost:10085 -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) GetAvgPrice

func (chain *ChainApi) GetAvgPrice(height uint64) (*big.Int, error)

func (*ChainApi) GetBalance

func (chain *ChainApi) GetBalance(addr crypto.CommonAddress) string
 name: getBalance
 usage: Query address balance
 params:
	1. Query address
 return: The account balance in the address
 example: curl http://localhost:10085 -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: Used to obtain block information
 params:
	1. height  usage: Current block height
 return: Block detail information
 example: curl http://localhost:10085 -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":{
        "Header":{
            "ChainId":0,
            "Version":1,
            "PreviousHash":"0x1fbae528a8eed0f09201bfd2c7e52fef66f5f35619e9868cd6d02dabac60e4e6",
            "GasLimit":18000000,
            "GasUsed":0,
            "Height":1,
            "Timestamp":1592365562,
            "StateRoot":"UpMnHA5WmmTxU4T4jFQvpt6bFwigN+fg1Jx0fSD91MA=",
            "TxRoot":null,
            "ReceiptRoot":"0x0000000000000000000000000000000000000000000000000000000000000000",
            "Bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
        },
        "Data":{
            "TxCount":0,
            "TxList":null
        },
        "Proof":{
            "Type":0,
            "Evidence":"MEUCIQDIZnsow/WbAmQ7jJ21EcVxzQkKA33LJfw8anhzkNjBzAIgMexycsYJlYEv0rbPvleoAx1iahzUx6FrMNZhh8uq6Lg="
        }
    }
}

func (*ChainApi) GetBlockGasInfo

func (chain *ChainApi) GetBlockGasInfo() string
 name: getBlockGasInfo
 usage: Obtain gas related information
 params:
	1. 无
 return: Gas minimum value and maximum value required by the system; And the maximum gas value that the current block is set to
 example: curl http://localhost:10085 -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: Get bytecode by address
 params:
	1. address
 return: bytecode
 example: curl http://localhost:10085 -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) GetCancelCreditDetailByTXHash

func (chain *ChainApi) GetCancelCreditDetailByTXHash(txHash crypto.Hash) []*types.CancelCreditDetail
 name: getCancelCreditDetailByTXHash
 usage: Get the back pledge or back vote information according to txhash
 params:
	1. txhash
 return: {}
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"chain_getCancelCreditDetailByTXHash","params":["0x7d9dd32ca192e765ff2abd7c5f8931cc3f77f8f47d2d52170c7804c2ca2c5dd9"], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":[]}

func (*ChainApi) GetCancelCreditDetails

func (chain *ChainApi) GetCancelCreditDetails(addr *crypto.CommonAddress) string
 name: GetCancelCreditDetails
 usage: Get the details of all refund requests
 params:
	1. address
 return: bytecode
 example: curl http://localhost:10085 -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":"{\"DREP300fc5a14e578be28c64627c0e7e321771c58cd4\":\"0x3641100\"}"}

func (*ChainApi) GetCandidateAddrs

func (chain *ChainApi) GetCandidateAddrs() string
 name: GetCandidateAddrs
 usage: Gets the addresses of all candidate nodes and the corresponding trust values
 params:
	1. address
 return:  []
 example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"chain_getCandidateAddrs","params":[""], "id": 3}' -H "Content-Type:application/json"
 response:
   {"jsonrpc":"2.0","id":3,"result":"{\"DREP300fc5a14e578be28c64627c0e7e321771c58cd4\":\"0x3641100\"}"}

func (*ChainApi) GetChangeCycle

func (chain *ChainApi) GetChangeCycle() (int, error)
 name: getChangeCycle
 usage: Gets the transition period of the out - of - block node
 params:
	none
 return:  Transition period
 example: curl http://localhost:10085 -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: getCreditDetails
 usage: Get all the details of the stake according to the address
 params:
	1. address
 return: bytecode
 example: curl http://localhost:10085 -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\":\"DREPd05d5f324ada3c418e14cd6b497f2f36d60ba607\",\"HeightValues\":[{\"CreditHeight\":1329,\"CreditValue\":\"0x11135\"}]}]"}

func (*ChainApi) GetLogs

func (chain *ChainApi) GetLogs(txHash crypto.Hash) []*types.Log
 name: getLogs
 usage: Get the transaction log information based on txhash
 params:
	1. txhash
 return: []log
 example: curl http://localhost:10085 -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: To get the current highest block
 params:
	1. 无
 return: Current maximum block height value
 example: curl http://localhost:10085 -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: Query the nonce whose address is on the chain
 params:
	1. Query address
 return: nonce
 example: curl http://localhost:10085 -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: Get the receipt information based on txhash
 params:
	1. txhash
 return: receipt
 example: curl http://localhost:10085 -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: GetReputation
 usage: Query the reputation value of the address
 params:
	1.  Query address
 return: The reputation value corresponding to the address
 example: curl http://localhost:10085 -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) GetReward

func (chain *ChainApi) GetReward(addr *crypto.CommonAddress) (int, error)
 name: getReward
 usage: Gets the transition period of the out - of - block node
 params:
	none
 return:  Transition period
 example: curl http://localhost:10085 -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) GetTransactionByBlockHeightAndIndex

func (chain *ChainApi) GetTransactionByBlockHeightAndIndex(height uint64, index int) (*types.Transaction, error)
 name: getTransactionByBlockHeightAndIndex
 usage: Gets a particular sequence of transactions in a block
 params:
	1. block height
    2. Transaction sequence
 return: transaction
 example: curl http://localhost:10085 -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 *block.BlockExecuteContext) error

func (*ChainBlockValidator) RouteTransaction

func (chainBlockValidator *ChainBlockValidator) RouteTransaction(context *block.BlockExecuteContext, gasPool *utils.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  uint16               `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) 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(netType params.NetType) *ChainConfig

DefaultConfig -> config

func (*ChainService) DeriveMerkleRoot

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

func (*ChainService) DeriveReceiptRoot

func (chainService *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() *block.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

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() *block.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 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 GenesisConfig

type GenesisConfig struct {
	Preminer []*Preminer
	Miners   []*types.Producer
}
var DefaultGenesisConfigMainnet GenesisConfig
var DefaultGenesisConfigTestnet GenesisConfig

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 *block.BlockExecuteContext) error
}

type IGenesisProcess

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

Process genesis contract

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 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) CheckCancelCandidateType

func (trieQuery *TrieQuery) CheckCancelCandidateType(tx *types.Transaction) 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