Documentation
¶
Index ¶
- Constants
- Variables
- type BlockMgr
- func (blockMgr *BlockMgr) Api() []app.API
- func (blockMgr *BlockMgr) BroadcastBlock(msgType int32, block *types.Block, isLocal bool)
- func (blockMgr *BlockMgr) BroadcastTx(msgType int32, tx *types.Transaction, isLocal bool)
- func (blockMgr *BlockMgr) CommandFlags() ([]cli.Command, []cli.Flag)
- func (blockMgr *BlockMgr) DefaultConfig() *BlockMgrConfig
- func (blockMgr *BlockMgr) GenerateTemplate(trieStore store.StoreInterface, leaderAddr crypto.CommonAddress, ...) (*types.Block, *big.Int, error)
- func (blockMgr *BlockMgr) GetBestPeerInfo() types.PeerInfoInterface
- func (blockMgr *BlockMgr) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
- func (blockMgr *BlockMgr) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
- func (blockMgr *BlockMgr) GetTransactionCount(addr *crypto.CommonAddress) uint64
- func (blockMgr *BlockMgr) GetTxInPool(hash string) (*types.Transaction, error)
- func (blockMgr *BlockMgr) HandleBlockReqMsg(peer types.PeerInfoInterface, req *types.BlockReq)
- func (blockMgr *BlockMgr) HandleBlockRespMsg(peer types.PeerInfoInterface, rsp *types.BlockResp)
- func (blockMgr *BlockMgr) Init(executeContext *app.ExecuteContext) error
- func (blockMgr *BlockMgr) Name() string
- func (blockMgr *BlockMgr) NewTxFeed() *event.Feed
- func (blockMgr *BlockMgr) SendTransaction(tx *types.Transaction, islocal bool) error
- func (blockMgr *BlockMgr) Start(executeContext *app.ExecuteContext) error
- func (blockMgr *BlockMgr) Stop(executeContext *app.ExecuteContext) error
- func (blockMgr *BlockMgr) SubscribeSyncBlockEvent(subchan chan event.SyncBlockEvent) event.Subscription
- type BlockMgrApi
- func (blockMgrApi *BlockMgrApi) GasPrice() (*big.Int, error)
- func (blockMgrApi *BlockMgrApi) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
- func (blockMgrApi *BlockMgrApi) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
- func (blockMgrApi *BlockMgrApi) GetTransactionCount(addr *crypto.CommonAddress) uint64
- func (blockMgrApi *BlockMgrApi) GetTxInPool(hash string) (*types.Transaction, error)
- func (blockMgrApi *BlockMgrApi) SendRawTransaction(txbytes common.Bytes) (string, error)
- type BlockMgrConfig
- type IBlockBlockGenerator
- type IBlockMgr
- type IBlockMgrPool
- type IBlockNotify
- type ISendMessage
- type Oracle
- type OracleConfig
- type TemplateBlockValidator
- func (chainBlockValidator *TemplateBlockValidator) ExecuteBlock(context *chain.BlockExecuteContext, blockInterval int) error
- func (chainBlockValidator *TemplateBlockValidator) RouteTransaction(context *chain.BlockExecuteContext, gasPool *chain.GasPool, ...) (*types.Receipt, uint64, error)
- func (chainBlockValidator *TemplateBlockValidator) VerifyBody(block *types.Block) error
- func (chainBlockValidator *TemplateBlockValidator) VerifyHeader(header, parent *types.BlockHeader) error
Constants ¶
View Source
const DefaultGasPrice = params.GWei
View Source
const (
MODULENAME = "blockmgr"
)
Variables ¶
View Source
var ( DefaultOracleConfig = OracleConfig{ Blocks: 20, Default: 30000, Percentile: 60, MaxPrice: big.NewInt(500 * params.GWei).Uint64(), } DefaultChainConfig = &BlockMgrConfig{ GasPrice: DefaultOracleConfig, JournalFile: "txpool/txs", } )
View Source
var ( ErrBlockNotFound = errors.New("block not exist") ErrTxIndexOutOfRange = errors.New("tx index out of range") ErrReachGasLimit = errors.New("gas limit reached") ErrOverFlowMaxMsgSize = errors.New("msg exceed max size") ErrEnoughPeer = errors.New("peer exceed max peers") ErrNotContinueHeader = errors.New("non contiguous header") ErrFindAncesstorTimeout = errors.New("findAncestor timeout") ErrGetHeaderHashTimeout = errors.New("get header hash timeout") ErrGetBlockTimeout = errors.New("fetch blocks timeout") ErrReqStateTimeout = errors.New("req state timeout") ErrDecodeMsg = errors.New("fail to decode p2p msg") ErrMsgType = errors.New("not expected msg type") ErrNegativeAmount = errors.New("negative amount in tx") ErrExceedGasLimit = errors.New("gas limit in tx has exceed block limit") ErrBalance = errors.New("not enough balance") ErrNotSupportRenameAlias = errors.New("not suppport rename alias") ErrNoCommonAncesstor = errors.New("no common ancesstor") )
Functions ¶
This section is empty.
Types ¶
type BlockMgr ¶
type BlockMgr struct { ChainService chain.ChainServiceInterface `service:"chain"` RpcService *rpc2.RpcService `service:"rpc"` P2pServer p2pService.P2P `service:"p2p"` DatabaseService *database.DatabaseService `service:"database"` Config *BlockMgrConfig // contains filtered or unexported fields }
func NewBlockMgr ¶
func NewBlockMgr(config *BlockMgrConfig, homeDir string, cs chain.ChainServiceInterface, p2pservice p2pService.P2P) *BlockMgr
func (*BlockMgr) BroadcastBlock ¶
func (*BlockMgr) BroadcastTx ¶
func (blockMgr *BlockMgr) BroadcastTx(msgType int32, tx *types.Transaction, isLocal bool)
func (*BlockMgr) CommandFlags ¶
func (blockMgr *BlockMgr) CommandFlags() ([]cli.Command, []cli.Flag)
func (*BlockMgr) DefaultConfig ¶
func (blockMgr *BlockMgr) DefaultConfig() *BlockMgrConfig
func (*BlockMgr) GenerateTemplate ¶
func (*BlockMgr) GetBestPeerInfo ¶
func (blockMgr *BlockMgr) GetBestPeerInfo() types.PeerInfoInterface
func (*BlockMgr) GetPoolMiniPendingNonce ¶
func (blockMgr *BlockMgr) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
func (*BlockMgr) GetPoolTransactions ¶
func (blockMgr *BlockMgr) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
func (*BlockMgr) GetTransactionCount ¶
func (blockMgr *BlockMgr) GetTransactionCount(addr *crypto.CommonAddress) uint64
func (*BlockMgr) GetTxInPool ¶
func (blockMgr *BlockMgr) GetTxInPool(hash string) (*types.Transaction, error)
func (*BlockMgr) HandleBlockReqMsg ¶
func (blockMgr *BlockMgr) HandleBlockReqMsg(peer types.PeerInfoInterface, req *types.BlockReq)
func (*BlockMgr) HandleBlockRespMsg ¶
func (blockMgr *BlockMgr) HandleBlockRespMsg(peer types.PeerInfoInterface, rsp *types.BlockResp)
func (*BlockMgr) SendTransaction ¶
func (blockMgr *BlockMgr) SendTransaction(tx *types.Transaction, islocal bool) error
func (*BlockMgr) SubscribeSyncBlockEvent ¶
func (blockMgr *BlockMgr) SubscribeSyncBlockEvent(subchan chan event.SyncBlockEvent) event.Subscription
type BlockMgrApi ¶
type BlockMgrApi struct {
// contains filtered or unexported fields
}
name: 区块 usage: 用于处理区块链偏上层逻辑 prefix:blockMgr
func (*BlockMgrApi) GasPrice ¶
func (blockMgrApi *BlockMgrApi) GasPrice() (*big.Int, error)
name: gasPrice usage: 获取系统的给出的gasprice建议值 params: 1. 待查询地址 return: 价格和是否错误信息 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_gasPrice","params":[], "id": 3}' -H "Content-Type:application/json" response:
func (*BlockMgrApi) GetPoolMiniPendingNonce ¶
func (blockMgrApi *BlockMgrApi) GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64
func (*BlockMgrApi) GetPoolTransactions ¶
func (blockMgrApi *BlockMgrApi) GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions
name: GetPoolTransactions usage: 获取交易池中的交易信息. params: 1. 待查询地址 return: 交易池中所有交易 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_getPoolTransactions","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json" response:
func (*BlockMgrApi) GetTransactionCount ¶
func (blockMgrApi *BlockMgrApi) GetTransactionCount(addr *crypto.CommonAddress) uint64
name: GetTransactionCount usage: 获取地址发出的交易总数 params: 1. 待查询地址 return: 交易池中所有交易 example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_getTransactionCount","params":["0x8a8e541ddd1272d53729164c70197221a3c27486"], "id": 3}' -H "Content-Type:application/json" response:
func (*BlockMgrApi) GetTxInPool ¶
func (blockMgrApi *BlockMgrApi) GetTxInPool(hash string) (*types.Transaction, error)
name: GetTxInPool usage: 查询交易是否在交易池,如果在,返回交易 params: 1. 发起转账的地址 return: 交易完整信息 example: curl -H "Content-Type: application/json" -X post --data '{"jsonrpc":"2.0","method":"blockmgr_getTxInPool","params":["0x3ebcbe7cb440dd8c52940a2963472380afbb56c5"],"id":1}' http://127.0.0.1:15645 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" } }
func (*BlockMgrApi) SendRawTransaction ¶
func (blockMgrApi *BlockMgrApi) SendRawTransaction(txbytes common.Bytes) (string, error)
name: sendRawTransaction usage: 发送已签名的交易. params: 1. 已签名的交易 return: 交易hash example: curl http://localhost:15645 -X POST --data '{"jsonrpc":"2.0","method":"blockmgr_sendRawTransaction","params":["0x40a287b6d30b05313131317a4120dd8c23c40910d038fa43b2f8932d3681cbe5ee3079b6e9de0bea6e8e6b2a867a561aa26e1cd6b62aa0422a043186b593b784bf80845c3fd5a7fbfe62e61d8564"], "id": 3}' -H "Content-Type:application/json" response: {"jsonrpc":"2.0","id":1,"result":"0xf30e858667fa63bc57ae395c3f57ede9bb3ad4969d12f4bce51d900fb5931538"}
type BlockMgrConfig ¶
type BlockMgrConfig struct { GasPrice OracleConfig `json:"gasprice"` JournalFile string `json:"journalFile"` }
type IBlockBlockGenerator ¶
type IBlockBlockGenerator interface { //generate block template GenerateTemplate(trieStore store.StoreInterface, leaderAddr crypto.CommonAddress, blockInterval int) (*types.Block, *big.Int, error) }
type IBlockMgr ¶
type IBlockMgr interface { app.Service IBlockMgrPool IBlockBlockGenerator IBlockNotify ISendMessage }
type IBlockMgrPool ¶
type IBlockMgrPool interface { //query tx pool message GetTransactionCount(addr *crypto.CommonAddress) uint64 GetPoolTransactions(addr *crypto.CommonAddress) []types.Transactions GetPoolMiniPendingNonce(addr *crypto.CommonAddress) uint64 GetTxInPool(hash string) (*types.Transaction, error) }
type IBlockNotify ¶
type IBlockNotify interface { //notify SubscribeSyncBlockEvent(subchan chan event.SyncBlockEvent) event.Subscription NewTxFeed() *event.Feed }
type ISendMessage ¶
type Oracle ¶
type Oracle struct {
// contains filtered or unexported fields
}
Oracle recommends gas prices based on the content of recent blocks. Suitable for both light and full clients.
func NewOracle ¶
func NewOracle(chainService xxx.ChainServiceInterface, params OracleConfig) *Oracle
NewOracle returns a new oracle.
type OracleConfig ¶
type TemplateBlockValidator ¶
type TemplateBlockValidator struct {
// contains filtered or unexported fields
}
func NewTemplateBlockValidator ¶
func NewTemplateBlockValidator(chain chain.ChainServiceInterface) *TemplateBlockValidator
func (*TemplateBlockValidator) ExecuteBlock ¶
func (chainBlockValidator *TemplateBlockValidator) ExecuteBlock(context *chain.BlockExecuteContext, blockInterval int) error
func (*TemplateBlockValidator) RouteTransaction ¶
func (chainBlockValidator *TemplateBlockValidator) RouteTransaction(context *chain.BlockExecuteContext, gasPool *chain.GasPool, tx *types.Transaction) (*types.Receipt, uint64, error)
func (*TemplateBlockValidator) VerifyBody ¶
func (chainBlockValidator *TemplateBlockValidator) VerifyBody(block *types.Block) error
func (*TemplateBlockValidator) VerifyHeader ¶
func (chainBlockValidator *TemplateBlockValidator) VerifyHeader(header, parent *types.BlockHeader) error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.