forked from seeleteam/go-seele
-
Notifications
You must be signed in to change notification settings - Fork 0
/
txmanage.go
68 lines (61 loc) · 1.69 KB
/
txmanage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//////////////////////////////////////////////
//This is a tool for analysis all information
//1. trasactions: sent, processed, pending
//2. ...
//3. ...
//////////////////////////////////////////////
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
// var (
// //txs already sent
// txSent int
// //txs already in block
// txBlock int
// //txs pending
// txPool int
// )
var txAnalysisCmd = &cobra.Command{
Use: "txAnalysis",
Short: "check whether any tx gets lost. RUN ONLY AFTER TPS = 0",
Long: `For Example:
tool.exe txAnalysis`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Have you stopped sendtx and TPS = 0 (y/n)?")
confirm := askForConfirmation()
if confirm == true {
initClient()
//get the txs already minned on blockchain:
for {
var height uint64
var counter uint64
var txCount int
txCount = 0
var blockTxCount int
for clientIndex := range clientList {
if err := clientList[clientIndex].Call(&height, "seele_getBlockHeight"); err != nil {
panic(fmt.Sprintf("failed to get the block height: %s", err))
}
fmt.Printf("block height %d\n", height)
counter = 1
// get the tx count up to current block height
for counter <= height {
blockTxCount = 0
if err := clientList[clientIndex].Call(&blockTxCount, "txpool_getBlockTransactionCount", "", counter); err != nil {
panic(fmt.Sprintf("failed to get the block tx count: %s\n", err))
}
txCount += blockTxCount - 1 //first tx is reward to miner
counter++
}
}
//fmt.Printf("Tx Sent: %d\n", txTotal)
fmt.Printf("Tx Processed: %d\n", txCount)
}
}
},
}
func init() {
rootCmd.AddCommand(txAnalysisCmd)
}