Documentation ¶
Index ¶
- Constants
- Variables
- type BlockAnalysis
- type GetProducer
- type HistoryConfig
- type IStore
- type LevelDbStore
- func (store *LevelDbStore) Close()
- func (store *LevelDbStore) DelRecord(block *types.Block)
- func (store *LevelDbStore) ExistRecord(block *types.Block) (bool, error)
- func (store *LevelDbStore) GetRawTransaction(txHash *crypto.Hash) ([]byte, error)
- func (store *LevelDbStore) GetReceiveTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (store *LevelDbStore) GetSendTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (store *LevelDbStore) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
- func (store *LevelDbStore) InsertRecord(block *types.Block)
- type MongogDbStore
- func (store *MongogDbStore) Close()
- func (store *MongogDbStore) DelRecord(block *types.Block)
- func (store *MongogDbStore) ExistRecord(block *types.Block) (bool, error)
- func (store *MongogDbStore) GetRawTransaction(txHash *crypto.Hash) ([]byte, error)
- func (store *MongogDbStore) GetReceiveTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (store *MongogDbStore) GetSendTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (store *MongogDbStore) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
- func (store *MongogDbStore) InsertRecord(block *types.Block)
- type PbftProof
- type RpcBlock
- type RpcBlockHeader
- type RpcTransaction
- type SoloProof
- type TraceApi
- func (traceApi *TraceApi) DecodeTrasnaction(bytes common.Bytes) (*RpcTransaction, error)
- func (traceApi *TraceApi) GetRawTransaction(txHash *crypto.Hash) (string, error)
- func (traceApi *TraceApi) GetReceiveTransactionByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (traceApi *TraceApi) GetSendTransactionByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
- func (traceApi *TraceApi) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
- func (traceApi *TraceApi) Rebuild(from, end int) error
- type TraceService
- func (traceService *TraceService) Api() []app.API
- func (traceService *TraceService) CommandFlags() ([]cli.Command, []cli.Flag)
- func (traceService *TraceService) DefaultConfig(netType params.NetType) *HistoryConfig
- func (traceService *TraceService) Init(executeContext *app.ExecuteContext) error
- func (traceService *TraceService) Name() string
- func (traceService *TraceService) P2pMessages() map[int]interface{}
- func (traceService *TraceService) Receive(context actor.Context)
- func (traceService *TraceService) Start(executeContext *app.ExecuteContext) error
- func (traceService *TraceService) Stop(executeContext *app.ExecuteContext) error
- type ViewBlock
- type ViewBlockHeader
- type ViewTransaction
Constants ¶
const ( TX_PREFIX = "TX" TX_SEND_HISTORY_PREFIX = "SEND_TXHISTORY" TX_RECEIVE_HISTORY_PREFIX = "RECEIVE_TXHISTORY" )
const (
MODULENAME = "trace"
)
Variables ¶
var ( ErrTxNotFound = errors.New("tx not found") ErrBlockNotFound = errors.New("block not found") ErrUnSupportDbType = errors.New("not support persistence type") )
var ( DefaultHistoryConfig = &HistoryConfig{ Enable: false, DbType: "leveldb", Url: "mongodb://localhost:27017", } EnableTraceFlag = cli.BoolFlag{ Name: "enableTrace", Usage: "is trace enable flag", } DefaultDbName = "dump-drep" )
var (
HistoryDirFlag = cli.StringFlag{
Name: "historydir",
Usage: "directory to save history data",
Value: "",
}
)
Functions ¶
This section is empty.
Types ¶
type BlockAnalysis ¶
type BlockAnalysis struct { Config HistoryConfig // contains filtered or unexported fields }
func NewBlockAnalysis ¶
func NewBlockAnalysis(config HistoryConfig, consensusService *service.ConsensusService, trieStore dbinterface.KeyValueStore, getBlock func(uint64) (*types.Block, error)) *BlockAnalysis
func (*BlockAnalysis) Close ¶
func (blockAnalysis *BlockAnalysis) Close() error
func (*BlockAnalysis) Rebuild ¶
func (blockAnalysis *BlockAnalysis) Rebuild(from, end int) error
type GetProducer ¶
type GetProducer func(root []byte, num int) ([]crypto.CommonAddress, error)
type HistoryConfig ¶
type HistoryConfig struct { HistoryDir string `json:"historydir"` Url string `json:"url"` DbType string `json:"dbtype"` Enable bool `json:"enable"` }
HistoryConfig used to condig history data dir and db message
type IStore ¶
type IStore interface { ExistRecord(block *types.Block) (bool, error) InsertRecord(block *types.Block) DelRecord(block *types.Block) GetRawTransaction(txHash *crypto.Hash) ([]byte, error) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error) GetSendTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction GetReceiveTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction Close() }
IStore determine the interface to be implementation for storage
type LevelDbStore ¶
type LevelDbStore struct {
// contains filtered or unexported fields
}
LevelDbStore used to save data to level db, there are 3 kinds of prefix in db. "TX" for transaction collection, format "TX" + hash "SEND_TXHISTORY" for transaction group by sender addr, format "SEND_TXHISTORY" + addr + hash "RECEIVE_TXHISTORY" for transaction group by receive addr format "RECEIVE_TXHISTORY" + addr + hash
func NewLevelDbStore ¶
func NewLevelDbStore(path string, getProducer GetProducer, consensusMode string) (*LevelDbStore, error)
func (*LevelDbStore) Close ¶
func (store *LevelDbStore) Close()
func (*LevelDbStore) DelRecord ¶
func (store *LevelDbStore) DelRecord(block *types.Block)
func (*LevelDbStore) ExistRecord ¶
func (store *LevelDbStore) ExistRecord(block *types.Block) (bool, error)
func (*LevelDbStore) GetRawTransaction ¶
func (store *LevelDbStore) GetRawTransaction(txHash *crypto.Hash) ([]byte, error)
func (*LevelDbStore) GetReceiveTransactionsByAddr ¶
func (store *LevelDbStore) GetReceiveTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
func (*LevelDbStore) GetSendTransactionsByAddr ¶
func (store *LevelDbStore) GetSendTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
func (*LevelDbStore) GetTransaction ¶
func (store *LevelDbStore) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
func (*LevelDbStore) InsertRecord ¶
func (store *LevelDbStore) InsertRecord(block *types.Block)
InsertRecord check block ,if tx exist, save to to history and send history , if to is not nil, save tx receive history
type MongogDbStore ¶
type MongogDbStore struct {
// contains filtered or unexported fields
}
MongogDbStore used to save tx in mongo db, db name is "drep", col name is "tx"
func NewMongoDbStore ¶
func NewMongoDbStore(url string, getProducer GetProducer, consensusMode string, dbName string) (*MongogDbStore, error)
NewMongoDbStore open a new db from url, if db not exist, auto create
func (*MongogDbStore) Close ¶
func (store *MongogDbStore) Close()
Close disconnect db connection NOTICE Disconnect very slow, please wait
func (*MongogDbStore) DelRecord ¶
func (store *MongogDbStore) DelRecord(block *types.Block)
func (*MongogDbStore) ExistRecord ¶
func (store *MongogDbStore) ExistRecord(block *types.Block) (bool, error)
func (*MongogDbStore) GetRawTransaction ¶
func (store *MongogDbStore) GetRawTransaction(txHash *crypto.Hash) ([]byte, error)
func (*MongogDbStore) GetReceiveTransactionsByAddr ¶
func (store *MongogDbStore) GetReceiveTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
func (*MongogDbStore) GetSendTransactionsByAddr ¶
func (store *MongogDbStore) GetSendTransactionsByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
func (*MongogDbStore) GetTransaction ¶
func (store *MongogDbStore) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
func (*MongogDbStore) InsertRecord ¶
func (store *MongogDbStore) InsertRecord(block *types.Block)
type PbftProof ¶
func NewPbftProof ¶
func NewPbftProof() *PbftProof
type RpcBlock ¶
type RpcBlockHeader ¶
type RpcBlockHeader struct { ChainId types.ChainIdType Version int32 PreviousHash string GasLimit string GasUsed string Height uint64 Timestamp uint64 StateRoot string TxRoot string LeaderPubKey string MinorPubKeys []string Hash string }
func (*RpcBlockHeader) FromBlockHeader ¶
func (rpcBlockHeader *RpcBlockHeader) FromBlockHeader(header *types.BlockHeader)
func (*RpcBlockHeader) ToHeader ¶
func (rpcBlockHeader *RpcBlockHeader) ToHeader() *types.BlockHeader
type RpcTransaction ¶
type RpcTransaction struct { Hash crypto.Hash From crypto.CommonAddress types.TransactionData `bson:",inline"` Sig common.Bytes }
func (*RpcTransaction) FromTx ¶
func (rpcTransaction *RpcTransaction) FromTx(tx *types.Transaction) *RpcTransaction
func (*RpcTransaction) ToTx ¶
func (rpcTx *RpcTransaction) ToTx() *types.Transaction
type TraceApi ¶
type TraceApi struct {
// contains filtered or unexported fields
}
name: history record interface usage: Query transaction address and other information (need to open the record module) prefix:trace
func (*TraceApi) DecodeTrasnaction ¶
func (traceApi *TraceApi) DecodeTrasnaction(bytes common.Bytes) (*RpcTransaction, error)
name: decodeTrasnaction usage: De parsing transaction byte information into transaction details params: 1. Transaction byte information return: transaction details example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_decodeTrasnaction","params":["0x02a7ae20007923a30bbfbcb998a6534d56b313e68c8e0c594a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002011102011003030000bc9889d00b004120eba14c77eab7a154833ff14832d8769cfc0b30db288445d6a83ef2fe337aa09042f8174a593543c4acabe7fadf1ad5fceea9c835682cb9dbea3f1d8fec181fb9"], "id": 3}' -H "Content-Type:application/json" response: { "jsonrpc": "2.0", "id": 3, "result": { "Hash": "0x00001c9b8c8fdb1f53faf02321f76253704123e2b56cce065852bab93e526ae2", "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "Version": 1, "Nonce": 530215, "Type": 0, "To": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Amount": "0x111", "GasPrice": "0x110", "GasLimit": "0x30000", "Timestamp": 1560356382, "Data": null, "Sig": "0x20eba14c77eab7a154833ff14832d8769cfc0b30db288445d6a83ef2fe337aa09042f8174a593543c4acabe7fadf1ad5fceea9c835682cb9dbea3f1d8fec181fb9" } }
func (*TraceApi) GetRawTransaction ¶
name: getRawTransaction usage: Query transaction bytes according to transaction hash params: 1. transaction hash return: transaction byte code example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_getRawTransaction","params":["0x00001c9b8c8fdb1f53faf02321f76253704123e2b56cce065852bab93e526ae2"], "id": 3}' -H "Content-Type:application/json" response: { "jsonrpc": "2.0", "id": 3, "result": "0x02a7ae20007923a30bbfbcb998a6534d56b313e68c8e0c594a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002011102011003030000bc9889d00b004120eba14c77eab7a154833ff14832d8769cfc0b30db288445d6a83ef2fe337aa09042f8174a593543c4acabe7fadf1ad5fceea9c835682cb9dbea3f1d8fec181fb9" }
func (*TraceApi) GetReceiveTransactionByAddr ¶
func (traceApi *TraceApi) GetReceiveTransactionByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
name: getReceiveTransactionByAd usage: Query the transaction accepted by the address and support paging params: 1. addr 2. Page number (from 1) 3. page size return: transaction list example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_getReceiveTransactionByAddr","params":["DREP3ebcbe7cb440dd8c52940a2963472380afbb56c5",1,10], "id": 3}' -H "Content-Type:application/json" response: { "jsonrpc": "2.0", "id": 3, "result": [ { "Hash": "0x3d3e7da272a5128bec6fd7ad10d8557b08e0fb9de4af6753641e29740eb7054e", "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "Version": 1, "Nonce": 553770, "Type": 0, "To": "0x3ebcbe7cb440dd8c52940a2963472380afbb56c5", "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Amount": "0xde0b6b3a7640000", "GasPrice": "0x12c", "GasLimit": "0x7530", "Timestamp": 1560403673, "Data": null, "Sig": "0x1f073cd3f2621abe15ef949b27c7d0a16d69a64aaa9e95973b9c94de2d7b8f4b103928988478d2f248ae7a9dc6a156d12d300adc5e9059decc037a67e94fe0c3a2" } ] }
func (*TraceApi) GetSendTransactionByAddr ¶
func (traceApi *TraceApi) GetSendTransactionByAddr(addr *crypto.CommonAddress, pageIndex, pageSize int) []*RpcTransaction
name: getSendTransactionByAddr usage: Query the transaction sent from the address according to the address, and pagination is supported params: 1. address 2. Page number (from 1) 3. Page size return: Transaction list example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_getSendTransactionByAddr","params":["DREP7923a30bbfbcb998a6534d56b313e68c8e0c594a",1,10], "id": 3}' -H "Content-Type:application/json" response: { "jsonrpc": "2.0", "id": 3, "result": [ { "Hash": "0x00001c9b8c8fdb1f53faf02321f76253704123e2b56cce065852bab93e526ae2", "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "Version": 1, "Nonce": 530215, "Type": 0, "To": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Amount": "0x111", "GasPrice": "0x110", "GasLimit": "0x30000", "Timestamp": 1560356382, "Data": null, "Sig": "0x20eba14c77eab7a154833ff14832d8769cfc0b30db288445d6a83ef2fe337aa09042f8174a593543c4acabe7fadf1ad5fceea9c835682cb9dbea3f1d8fec181fb9" } ] }
func (*TraceApi) GetTransaction ¶
func (traceApi *TraceApi) GetTransaction(txHash *crypto.Hash) (*RpcTransaction, error)
name: getTransaction usage: Query transaction details according to transaction hash params: 1. transaction hash return: Transaction details example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_getTransaction","params":["0x00001c9b8c8fdb1f53faf02321f76253704123e2b56cce065852bab93e526ae2"], "id": 3}' -H "Content-Type:application/json" response: { "jsonrpc": "2.0", "id": 3, "result": { "Hash": "0x00001c9b8c8fdb1f53faf02321f76253704123e2b56cce065852bab93e526ae2", "From": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "Version": 1, "Nonce": 530215, "Type": 0, "To": "0x7923a30bbfbcb998a6534d56b313e68c8e0c594a", "ChainId": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Amount": "0x111", "GasPrice": "0x110", "GasLimit": "0x30000", "Timestamp": 1560356382, "Data": null, "Sig": "0x20eba14c77eab7a154833ff14832d8769cfc0b30db288445d6a83ef2fe337aa09042f8174a593543c4acabe7fadf1ad5fceea9c835682cb9dbea3f1d8fec181fb9" } }
func (*TraceApi) Rebuild ¶
name: rebuild usage: Reconstructing block records in trace params: 1. Start block (included) 2. Termination block (not included) return: example: curl http://localhost:10085 -X POST --data '{"jsonrpc":"2.0","method":"trace_rebuild","params":[1,10], "id": 3}' -H "Content-Type:application/json" response: {"jsonrpc":"2.0","id":3,"result":null}
type TraceService ¶
type TraceService struct { Config *HistoryConfig ChainService chainService.ChainServiceInterface `service:"chain"` ConsensusService *consensusService.ConsensusService `service:"consensus"` DatabaseService *database.DatabaseService `service:"database"` // contains filtered or unexported fields }
HistoryService use to record tx data for query support get transaction by hash support get transaction history of sender address support get transaction history of sender receiver
func (*TraceService) Api ¶
func (traceService *TraceService) Api() []app.API
func (*TraceService) CommandFlags ¶
func (traceService *TraceService) CommandFlags() ([]cli.Command, []cli.Flag)
func (*TraceService) DefaultConfig ¶
func (traceService *TraceService) DefaultConfig(netType params.NetType) *HistoryConfig
func (*TraceService) Init ¶
func (traceService *TraceService) Init(executeContext *app.ExecuteContext) error
Init used to create connection to storage(leveldb and mongo)
func (*TraceService) Name ¶
func (traceService *TraceService) Name() string
func (*TraceService) P2pMessages ¶
func (traceService *TraceService) P2pMessages() map[int]interface{}
func (*TraceService) Receive ¶
func (traceService *TraceService) Receive(context actor.Context)
func (*TraceService) Start ¶
func (traceService *TraceService) Start(executeContext *app.ExecuteContext) error
func (*TraceService) Stop ¶
func (traceService *TraceService) Stop(executeContext *app.ExecuteContext) error
type ViewBlock ¶
type ViewBlockHeader ¶
type ViewBlockHeader struct { Id string `bson:"_id"` ChainId types.ChainIdType Version int32 PreviousHash string GasLimit uint64 GasUsed uint64 Height uint64 Timestamp uint64 StateRoot string TxRoot string Hash string }
func (*ViewBlockHeader) From ¶
func (viewBlockHeader *ViewBlockHeader) From(block *types.Block) *ViewBlockHeader
type ViewTransaction ¶
type ViewTransaction struct { Id string `bson:"_id"` Hash string From string Version int32 Nonce uint64 //交易序列号 Type int To string ChainId types.ChainIdType Amount string GasPrice uint64 GasLimit uint64 Timestamp uint64 Data string //hex Sig string Height uint64 }
func (*ViewTransaction) FromTx ¶
func (rpcTransaction *ViewTransaction) FromTx(tx *types.Transaction) *ViewTransaction