mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 22:13:47 +00:00
Added sypnosis/help + clean code
This commit is contained in:
parent
a6f014c2c9
commit
1865f28131
5 changed files with 26 additions and 25 deletions
|
|
@ -19,7 +19,9 @@ type ChainWatchCommand struct {
|
||||||
|
|
||||||
// Help implements the cli.Command interface
|
// Help implements the cli.Command interface
|
||||||
func (c *ChainWatchCommand) Help() string {
|
func (c *ChainWatchCommand) Help() string {
|
||||||
return ``
|
return `Usage: bor chain watch
|
||||||
|
|
||||||
|
This command is used to view the chainHead, reorg and fork events in real-time`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChainWatchCommand) Flags() *flagset.Flagset {
|
func (c *ChainWatchCommand) Flags() *flagset.Flagset {
|
||||||
|
|
@ -30,7 +32,19 @@ func (c *ChainWatchCommand) Flags() *flagset.Flagset {
|
||||||
|
|
||||||
// Synopsis implements the cli.Command interface
|
// Synopsis implements the cli.Command interface
|
||||||
func (c *ChainWatchCommand) Synopsis() string {
|
func (c *ChainWatchCommand) Synopsis() string {
|
||||||
return ""
|
return "Watch the chainHead, reorg and fork events in real-time"
|
||||||
|
}
|
||||||
|
|
||||||
|
func printEvent(msg *proto.ChainWatchResponse) string {
|
||||||
|
var out string
|
||||||
|
if msg.Type == core.Chain2HeadCanonicalEvent {
|
||||||
|
out = fmt.Sprintf("Block Added : %v", msg.Newchain)
|
||||||
|
} else if msg.Type == core.Chain2HeadForkEvent {
|
||||||
|
out = fmt.Sprintf("New Fork Block : %v", msg.Newchain)
|
||||||
|
} else if msg.Type == core.Chain2HeadReorgEvent {
|
||||||
|
out = fmt.Sprintf("Reorg Detected \nAdded : %v \nRemoved : %v", msg.Newchain, msg.Oldchain)
|
||||||
|
}
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run implements the cli.Command interface
|
// Run implements the cli.Command interface
|
||||||
|
|
@ -68,23 +82,7 @@ func (c *ChainWatchCommand) Run(args []string) int {
|
||||||
c.UI.Output(err.Error())
|
c.UI.Output(err.Error())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if msg.Type == core.Chain2HeadCanonicalEvent {
|
c.UI.Output(printEvent(msg))
|
||||||
out := fmt.Sprintf("Block Added : %v", msg.Newchain)
|
|
||||||
c.UI.Output(out)
|
|
||||||
} else if msg.Type == core.Chain2HeadForkEvent {
|
|
||||||
out := fmt.Sprintf("New Fork Block : %v", msg.Newchain)
|
|
||||||
c.UI.Output(out)
|
|
||||||
} else if msg.Type == core.Chain2HeadReorgEvent {
|
|
||||||
c.UI.Output("Reorg Detected")
|
|
||||||
|
|
||||||
out := fmt.Sprintf("Added : %v", msg.Newchain)
|
|
||||||
c.UI.Output(out)
|
|
||||||
|
|
||||||
out = fmt.Sprintf("Removed : %v", msg.Oldchain)
|
|
||||||
c.UI.Output(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Println(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,6 @@ func ConvertBlockToBlockStub(blocks []*types.Block) []*proto.BlockStub {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error {
|
func (s *Server) ChainWatch(req *proto.ChainWatchRequest, reply proto.Bor_ChainWatchServer) error {
|
||||||
// 1. start the feed to the blockchain events
|
|
||||||
// 2. for each event send a proto.ChainWatchResponse
|
|
||||||
|
|
||||||
chain2HeadChanSize := 10
|
chain2HeadChanSize := 10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1643,7 +1643,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
||||||
Type: "head",
|
Type: Chain2HeadCanonicalEvent,
|
||||||
NewChain: []*types.Block{block},
|
NewChain: []*types.Block{block},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1653,7 +1653,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||||
bc.chainSideFeed.Send(ChainSideEvent{Block: block})
|
bc.chainSideFeed.Send(ChainSideEvent{Block: block})
|
||||||
|
|
||||||
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
||||||
Type: "fork",
|
Type: Chain2HeadForkEvent,
|
||||||
NewChain: []*types.Block{block},
|
NewChain: []*types.Block{block},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -1751,7 +1751,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
|
||||||
bc.chainHeadFeed.Send(ChainHeadEvent{lastCanon})
|
bc.chainHeadFeed.Send(ChainHeadEvent{lastCanon})
|
||||||
|
|
||||||
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
||||||
Type: "head",
|
Type: Chain2HeadCanonicalEvent,
|
||||||
NewChain: []*types.Block{lastCanon},
|
NewChain: []*types.Block{lastCanon},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -2281,7 +2281,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
|
||||||
if len(oldChain) > 0 && len(newChain) > 0 {
|
if len(oldChain) > 0 && len(newChain) > 0 {
|
||||||
|
|
||||||
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
bc.chain2HeadFeed.Send(Chain2HeadEvent{
|
||||||
Type: "reorg",
|
Type: Chain2HeadReorgEvent,
|
||||||
NewChain: newChain,
|
NewChain: newChain,
|
||||||
OldChain: oldChain,
|
OldChain: oldChain,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,6 @@
|
||||||
|
|
||||||
- [```account import```](./account_import.md)
|
- [```account import```](./account_import.md)
|
||||||
|
|
||||||
|
- [```chain watch```](./chain_watch.md)
|
||||||
|
|
||||||
- [```version```](./version.md)
|
- [```version```](./version.md)
|
||||||
|
|
|
||||||
3
docs/cli/chain_watch.md
Normal file
3
docs/cli/chain_watch.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Chain watch
|
||||||
|
|
||||||
|
The ```chain watch``` command is used to view the chainHead, reorg and fork events in real-time.
|
||||||
Loading…
Reference in a new issue