|
14 | 14 | // You should have received a copy of the GNU Lesser General Public License |
15 | 15 | // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | | -package core |
| 17 | +// Package version implements reading of build version information. |
| 18 | +package version |
18 | 19 |
|
19 | 20 | import ( |
20 | 21 | "fmt" |
21 | | - "runtime" |
22 | 22 | "runtime/debug" |
23 | 23 | "strings" |
24 | 24 |
|
25 | | - "github.com/ethereum/go-ethereum/core/types" |
26 | 25 | "github.com/ethereum/go-ethereum/params" |
27 | 26 | ) |
28 | 27 |
|
29 | 28 | const ourPath = "github.com/ethereum/go-ethereum" // Path to our module |
30 | 29 |
|
31 | | -// summarizeBadBlock returns a string summarizing the bad block and other |
32 | | -// relevant information. |
33 | | -func summarizeBadBlock(block *types.Block, receipts []*types.Receipt, config *params.ChainConfig, err error) string { |
34 | | - var receiptString string |
35 | | - for i, receipt := range receipts { |
36 | | - receiptString += fmt.Sprintf("\n %d: cumulative: %v gas: %v contract: %v status: %v tx: %v logs: %v bloom: %x state: %x", |
37 | | - i, receipt.CumulativeGasUsed, receipt.GasUsed, receipt.ContractAddress.Hex(), |
38 | | - receipt.Status, receipt.TxHash.Hex(), receipt.Logs, receipt.Bloom, receipt.PostState) |
39 | | - } |
40 | | - version, vcs := runtimeInfo() |
41 | | - platform := fmt.Sprintf("%s %s %s %s", version, runtime.Version(), runtime.GOARCH, runtime.GOOS) |
42 | | - if vcs != "" { |
43 | | - vcs = fmt.Sprintf("\nVCS: %s", vcs) |
44 | | - } |
45 | | - return fmt.Sprintf(` |
46 | | -########## BAD BLOCK ######### |
47 | | -Block: %v (%#x) |
48 | | -Error: %v |
49 | | -Platform: %v%v |
50 | | -Chain config: %#v |
51 | | -Receipts: %v |
52 | | -############################## |
53 | | -`, block.Number(), block.Hash(), err, platform, vcs, config, receiptString) |
54 | | -} |
55 | | - |
56 | 30 | // runtimeInfo returns build and platform information about the current binary. |
57 | 31 | // |
58 | 32 | // If the package that is currently executing is a prefixed by our go-ethereum |
59 | 33 | // module path, it will print out commit and date VCS information. Otherwise, |
60 | 34 | // it will assume it's imported by a third-party and will return the imported |
61 | 35 | // version and whether it was replaced by another module. |
62 | | -func runtimeInfo() (string, string) { |
63 | | - var ( |
64 | | - version = params.VersionWithMeta |
65 | | - vcs = "" |
66 | | - buildInfo, ok = debug.ReadBuildInfo() |
67 | | - ) |
68 | | - if ok { |
69 | | - version = versionInfo(buildInfo) |
70 | | - if status, ok := vcsInfo(buildInfo); ok { |
71 | | - modified := "" |
72 | | - if status.modified { |
73 | | - modified = " (dirty)" |
74 | | - } |
75 | | - vcs = status.revision + "-" + status.time + modified |
| 36 | +func Info() (version, vcs string) { |
| 37 | + version = params.VersionWithMeta |
| 38 | + buildInfo, ok := debug.ReadBuildInfo() |
| 39 | + if !ok { |
| 40 | + return version, "" |
| 41 | + } |
| 42 | + version = versionInfo(buildInfo) |
| 43 | + if status, ok := vcsInfo(buildInfo); ok { |
| 44 | + modified := "" |
| 45 | + if status.modified { |
| 46 | + modified = " (dirty)" |
76 | 47 | } |
| 48 | + vcs = status.revision + "-" + status.time + modified |
77 | 49 | } |
78 | 50 | return version, vcs |
79 | 51 | } |
80 | 52 |
|
| 53 | +type gitStatus struct { |
| 54 | + revision string |
| 55 | + time string |
| 56 | + modified bool |
| 57 | +} |
| 58 | + |
81 | 59 | // versionInfo returns version information for the currently executing |
82 | 60 | // implementation. |
83 | 61 | // |
@@ -113,36 +91,6 @@ func versionInfo(info *debug.BuildInfo) string { |
113 | 91 | return version |
114 | 92 | } |
115 | 93 |
|
116 | | -type status struct { |
117 | | - revision string |
118 | | - time string |
119 | | - modified bool |
120 | | -} |
121 | | - |
122 | | -// vcsInfo returns VCS information of the build. |
123 | | -func vcsInfo(info *debug.BuildInfo) (s status, ok bool) { |
124 | | - for _, v := range info.Settings { |
125 | | - switch v.Key { |
126 | | - case "vcs.revision": |
127 | | - if len(v.Value) < 8 { |
128 | | - s.revision = v.Value |
129 | | - } else { |
130 | | - s.revision = v.Value[:8] |
131 | | - } |
132 | | - case "vcs.modified": |
133 | | - if v.Value == "true" { |
134 | | - s.modified = true |
135 | | - } |
136 | | - case "vcs.time": |
137 | | - s.time = v.Value |
138 | | - } |
139 | | - } |
140 | | - if s.revision != "" && s.time != "" { |
141 | | - ok = true |
142 | | - } |
143 | | - return |
144 | | -} |
145 | | - |
146 | 94 | // findModule returns the module at path. |
147 | 95 | func findModule(info *debug.BuildInfo, path string) *debug.Module { |
148 | 96 | if info.Path == ourPath { |
|
0 commit comments