gui.go 13.9 KB
Newer Older
F
Felix Lange 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301  USA

O
obscuren 已提交
18
package main
O
obscuren 已提交
19

O
obscuren 已提交
20 21
import "C"

O
obscuren 已提交
22
import (
O
obscuren 已提交
23
	"bytes"
O
obscuren 已提交
24
	"encoding/json"
O
obscuren 已提交
25
	"fmt"
O
obscuren 已提交
26
	"math/big"
O
obscuren 已提交
27
	"path"
O
obscuren 已提交
28
	"runtime"
O
obscuren 已提交
29 30 31
	"strconv"
	"strings"
	"time"
O
Removed  
obscuren 已提交
32

33
	"github.com/ethereum/go-ethereum"
O
obscuren 已提交
34
	"github.com/ethereum/go-ethereum/chain"
35 36
	"github.com/ethereum/go-ethereum/ethdb"
	"github.com/ethereum/go-ethereum/ethutil"
O
obscuren 已提交
37
	"github.com/ethereum/go-ethereum/logger"
O
obscuren 已提交
38
	"github.com/ethereum/go-ethereum/miner"
O
obscuren 已提交
39
	"github.com/ethereum/go-ethereum/wire"
O
obscuren 已提交
40
	"github.com/ethereum/go-ethereum/xeth"
O
obscuren 已提交
41
	"gopkg.in/qml.v1"
O
obscuren 已提交
42 43
)

O
obscuren 已提交
44
/*
O
obscuren 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
func LoadExtension(path string) (uintptr, error) {
	lib, err := ffi.NewLibrary(path)
	if err != nil {
		return 0, err
	}

	so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
	if err != nil {
		return 0, err
	}

	ptr := so()

		err = lib.Close()
		if err != nil {
			return 0, err
		}

	return ptr.Interface().(uintptr), nil
}
O
obscuren 已提交
65
*/
O
obscuren 已提交
66

O
obscuren 已提交
67
var guilogger = logger.NewLogger("GUI")
68

O
obscuren 已提交
69
type Gui struct {
70 71 72
	// The main application window
	win *qml.Window
	// QML Engine
O
obscuren 已提交
73 74
	engine    *qml.Engine
	component *qml.Common
75
	qmlDone   bool
76 77
	// The ethereum interface
	eth *eth.Ethereum
O
obscuren 已提交
78

79
	// The public Ethereum library
O
obscuren 已提交
80
	uiLib *UiLib
O
obscuren 已提交
81 82 83

	txDb *ethdb.LDBDatabase

O
obscuren 已提交
84
	logLevel logger.LogLevel
Z
go fmt  
zelig 已提交
85
	open     bool
Z
zelig 已提交
86

O
obscuren 已提交
87
	pipe *xeth.JSXEth
O
obscuren 已提交
88

Z
zelig 已提交
89
	Session        string
O
obscuren 已提交
90
	clientIdentity *wire.SimpleClientIdentity
Z
zelig 已提交
91
	config         *ethutil.ConfigManager
M
Maran 已提交
92

O
obscuren 已提交
93 94
	plugins map[string]plugin

O
obscuren 已提交
95
	miner  *miner.Miner
O
obscuren 已提交
96
	stdLog logger.LogSystem
O
obscuren 已提交
97 98
}

99
// Create GUI, but doesn't start it
O
obscuren 已提交
100
func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *wire.SimpleClientIdentity, session string, logLevel int) *Gui {
O
obscuren 已提交
101 102 103 104
	db, err := ethdb.NewLDBDatabase("tx_database")
	if err != nil {
		panic(err)
	}
O
obscuren 已提交
105

O
obscuren 已提交
106
	pipe := xeth.NewJSXEth(ethereum)
O
obscuren 已提交
107
	gui := &Gui{eth: ethereum, txDb: db, pipe: pipe, logLevel: logger.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config, plugins: make(map[string]plugin)}
O
obscuren 已提交
108
	data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "plugins.json"))
O
obscuren 已提交
109 110 111
	json.Unmarshal([]byte(data), &gui.plugins)

	return gui
O
obscuren 已提交
112 113
}

O
Cleanup  
obscuren 已提交
114
func (gui *Gui) Start(assetPath string) {
O
obscuren 已提交
115

O
Cleanup  
obscuren 已提交
116
	defer gui.txDb.Close()
O
obscuren 已提交
117

118 119
	// Register ethereum functions
	qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{
O
obscuren 已提交
120
		Init: func(p *xeth.JSBlock, obj qml.Object) { p.Number = 0; p.Hash = "" },
O
obscuren 已提交
121
	}, {
O
obscuren 已提交
122
		Init: func(p *xeth.JSTransaction, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" },
123
	}, {
O
obscuren 已提交
124
		Init: func(p *xeth.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" },
O
obscuren 已提交
125
	}})
126
	// Create a new QML engine
O
Cleanup  
obscuren 已提交
127 128
	gui.engine = qml.NewEngine()
	context := gui.engine.Context()
129
	gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath)
130 131

	// Expose the eth library and the ui library to QML
132 133
	context.SetVar("gui", gui)
	context.SetVar("eth", gui.uiLib)
J
Jarrad Hope 已提交
134

O
obscuren 已提交
135 136 137 138 139 140 141 142 143
	/*
		vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
		fmt.Printf("Fetched vec with addr: %#x\n", vec)
		if errr != nil {
			fmt.Println(errr)
		} else {
			context.SetVar("vec", (unsafe.Pointer)(vec))
		}
	*/
O
obscuren 已提交
144

145
	// Load the main QML interface
146
	data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
O
obscuren 已提交
147 148

	var win *qml.Window
149
	var err error
Z
zelig 已提交
150
	var addlog = false
O
obscuren 已提交
151 152
	if len(data) == 0 {
		win, err = gui.showKeyImport(context)
153
	} else {
O
obscuren 已提交
154
		win, err = gui.showWallet(context)
Z
zelig 已提交
155
		addlog = true
156
	}
O
obscuren 已提交
157
	if err != nil {
O
obscuren 已提交
158
		guilogger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err)
159

O
obscuren 已提交
160 161 162
		panic(err)
	}

O
obscuren 已提交
163
	guilogger.Infoln("Starting GUI")
Z
zelig 已提交
164
	gui.open = true
165
	win.Show()
O
obscuren 已提交
166

O
obscuren 已提交
167
	// only add the gui guilogger after window is shown otherwise slider wont be shown
Z
zelig 已提交
168
	if addlog {
O
obscuren 已提交
169
		logger.AddLogSystem(gui)
Z
zelig 已提交
170
	}
O
obscuren 已提交
171
	win.Wait()
O
obscuren 已提交
172

O
obscuren 已提交
173 174
	// need to silence gui guilogger after window closed otherwise logsystem hangs (but do not save loglevel)
	gui.logLevel = logger.Silence
Z
zelig 已提交
175 176 177 178 179
	gui.open = false
}

func (gui *Gui) Stop() {
	if gui.open {
O
obscuren 已提交
180
		gui.logLevel = logger.Silence
Z
zelig 已提交
181 182 183
		gui.open = false
		gui.win.Hide()
	}
184

185
	gui.uiLib.jsEngine.Stop()
186

O
obscuren 已提交
187
	guilogger.Infoln("Stopped")
O
obscuren 已提交
188
}
O
obscuren 已提交
189

O
obscuren 已提交
190
func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
O
obscuren 已提交
191
	component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/main.qml"))
O
obscuren 已提交
192 193
	if err != nil {
		return nil, err
194
	}
O
obscuren 已提交
195

196
	gui.win = gui.createWindow(component)
O
obscuren 已提交
197

Z
zelig 已提交
198
	gui.update()
O
obscuren 已提交
199

200 201 202 203 204 205
	return gui.win, nil
}

// The done handler will be called by QML when all views have been loaded
func (gui *Gui) Done() {
	gui.qmlDone = true
O
obscuren 已提交
206 207
}

O
obscuren 已提交
208 209 210
func (gui *Gui) ImportKey(filePath string) {
}

O
obscuren 已提交
211
func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) {
Z
zelig 已提交
212
	context.SetVar("lib", gui)
O
obscuren 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226
	component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/first_run.qml"))
	if err != nil {
		return nil, err
	}
	return gui.createWindow(component), nil
}

func (gui *Gui) createWindow(comp qml.Object) *qml.Window {
	win := comp.CreateWindow(nil)

	gui.win = win
	gui.uiLib.win = win

	return gui.win
O
obscuren 已提交
227
}
Z
zelig 已提交
228 229 230 231

func (gui *Gui) ImportAndSetPrivKey(secret string) bool {
	err := gui.eth.KeyManager().InitFromString(gui.Session, 0, secret)
	if err != nil {
O
obscuren 已提交
232
		guilogger.Errorln("unable to import: ", err)
Z
zelig 已提交
233 234
		return false
	}
O
obscuren 已提交
235
	guilogger.Errorln("successfully imported: ", err)
Z
zelig 已提交
236 237 238 239 240 241
	return true
}

func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) {
	err := gui.eth.KeyManager().Init(gui.Session, 0, true)
	if err != nil {
O
obscuren 已提交
242
		guilogger.Errorln("unable to create key: ", err)
Z
zelig 已提交
243 244 245 246 247
		return "", "", "", ""
	}
	return gui.eth.KeyManager().KeyPair().AsStrings()
}

O
obscuren 已提交
248 249 250 251
func (gui *Gui) setInitialChainManager() {
	sBlk := gui.eth.ChainManager().LastBlockHash
	blk := gui.eth.ChainManager().GetBlock(sBlk)
	for ; blk != nil; blk = gui.eth.ChainManager().GetBlock(sBlk) {
M
Maran 已提交
252
		sBlk = blk.PrevHash
Z
zelig 已提交
253
		addr := gui.address()
254 255 256

		// Loop through all transactions to see if we missed any while being offline
		for _, tx := range blk.Transactions() {
Z
zelig 已提交
257
			if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 {
258 259 260 261 262 263 264
				if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil {
					gui.txDb.Put(tx.Hash(), tx.RlpEncode())
				}

			}
		}

M
Maran 已提交
265
		gui.processBlock(blk, true)
266 267 268
	}
}

O
obscuren 已提交
269 270 271 272 273
type address struct {
	Name, Address string
}

func (gui *Gui) loadAddressBook() {
274 275
	view := gui.getObjectByName("infoView")
	view.Call("clearAddress")
O
obscuren 已提交
276

O
obscuren 已提交
277
	nameReg := gui.pipe.World().Config().Get("NameReg")
O
obscuren 已提交
278
	if nameReg != nil {
O
obscuren 已提交
279
		nameReg.EachStorage(func(name string, value *ethutil.Value) {
280
			if name[0] != 0 {
O
obscuren 已提交
281
				value.Decode()
282 283

				view.Call("addAddress", struct{ Name, Address string }{name, ethutil.Bytes2Hex(value.Bytes())})
284
			}
285 286
		})
	}
O
obscuren 已提交
287 288
}

O
obscuren 已提交
289
func (gui *Gui) insertTransaction(window string, tx *chain.Transaction) {
O
obscuren 已提交
290
	pipe := xeth.New(gui.eth)
O
obscuren 已提交
291
	nameReg := pipe.World().Config().Get("NameReg")
Z
zelig 已提交
292
	addr := gui.address()
O
obscuren 已提交
293

O
obscuren 已提交
294 295 296 297 298 299 300 301
	var inout string
	if bytes.Compare(tx.Sender(), addr) == 0 {
		inout = "send"
	} else {
		inout = "recv"
	}

	var (
O
obscuren 已提交
302
		ptx  = xeth.NewJSTx(tx, pipe.World().State())
O
obscuren 已提交
303 304 305 306 307 308
		send = nameReg.Storage(tx.Sender())
		rec  = nameReg.Storage(tx.Recipient)
		s, r string
	)

	if tx.CreatesContract() {
O
obscuren 已提交
309
		rec = nameReg.Storage(tx.CreationAddress(pipe.World().State()))
O
obscuren 已提交
310 311 312 313 314 315 316 317 318 319 320
	}

	if send.Len() != 0 {
		s = strings.Trim(send.Str(), "\x00")
	} else {
		s = ethutil.Bytes2Hex(tx.Sender())
	}
	if rec.Len() != 0 {
		r = strings.Trim(rec.Str(), "\x00")
	} else {
		if tx.CreatesContract() {
O
obscuren 已提交
321
			r = ethutil.Bytes2Hex(tx.CreationAddress(pipe.World().State()))
O
obscuren 已提交
322
		} else {
O
obscuren 已提交
323
			r = ethutil.Bytes2Hex(tx.Recipient)
O
obscuren 已提交
324
		}
O
obscuren 已提交
325 326 327 328
	}
	ptx.Sender = s
	ptx.Address = r

329
	if window == "post" {
O
obscuren 已提交
330
		//gui.getObjectByName("transactionView").Call("addTx", ptx, inout)
331 332 333
	} else {
		gui.getObjectByName("pendingTxView").Call("addTx", ptx, inout)
	}
O
obscuren 已提交
334
}
O
obscuren 已提交
335

O
obscuren 已提交
336
func (gui *Gui) readPreviousTransactions() {
O
obscuren 已提交
337
	it := gui.txDb.NewIterator()
O
obscuren 已提交
338
	for it.Next() {
O
obscuren 已提交
339
		tx := chain.NewTransactionFromBytes(it.Value())
O
obscuren 已提交
340 341

		gui.insertTransaction("post", tx)
O
obscuren 已提交
342

O
obscuren 已提交
343 344 345 346
	}
	it.Release()
}

O
obscuren 已提交
347
func (gui *Gui) processBlock(block *chain.Block, initial bool) {
O
obscuren 已提交
348
	name := strings.Trim(gui.pipe.World().Config().Get("NameReg").Storage(block.Coinbase).Str(), "\x00")
O
obscuren 已提交
349
	b := xeth.NewJSBlock(block)
350 351
	b.Name = name

352
	gui.getObjectByName("chainView").Call("addBlock", b, initial)
O
obscuren 已提交
353 354
}

355 356 357 358
func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
	var str string
	if unconfirmedFunds != nil {
		pos := "+"
O
obscuren 已提交
359
		if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 {
360 361 362 363 364 365 366 367 368 369 370
			pos = "-"
		}
		val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds)))
		str = fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(amount), pos, val)
	} else {
		str = fmt.Sprintf("%v", ethutil.CurrencyToString(amount))
	}

	gui.win.Root().Call("setWalletValue", str)
}

O
obscuren 已提交
371 372 373 374
func (self *Gui) getObjectByName(objectName string) qml.Object {
	return self.win.Root().ObjectByName(objectName)
}

O
obscuren 已提交
375
// Simple go routine function that updates the list of peers in the GUI
O
Cleanup  
obscuren 已提交
376
func (gui *Gui) update() {
377 378 379 380 381 382
	// We have to wait for qml to be done loading all the windows.
	for !gui.qmlDone {
		time.Sleep(500 * time.Millisecond)
	}

	go func() {
O
obscuren 已提交
383
		go gui.setInitialChainManager()
384 385 386 387
		gui.loadAddressBook()
		gui.setPeerInfo()
		gui.readPreviousTransactions()
	}()
388

O
obscuren 已提交
389
	for _, plugin := range gui.plugins {
O
obscuren 已提交
390
		guilogger.Infoln("Loading plugin ", plugin.Name)
O
obscuren 已提交
391

O
obscuren 已提交
392 393 394
		gui.win.Root().Call("addPlugin", plugin.Path, "")
	}

O
obscuren 已提交
395
	peerUpdateTicker := time.NewTicker(5 * time.Second)
O
obscuren 已提交
396
	generalUpdateTicker := time.NewTicker(500 * time.Millisecond)
O
obscuren 已提交
397
	statsUpdateTicker := time.NewTicker(5 * time.Second)
M
Maran 已提交
398

O
obscuren 已提交
399
	state := gui.eth.BlockManager().TransState()
O
obscuren 已提交
400

O
Cleanup  
obscuren 已提交
401
	unconfirmedFunds := new(big.Int)
O
obscuren 已提交
402
	gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance())))
O
obscuren 已提交
403 404

	lastBlockLabel := gui.getObjectByName("lastBlockLabel")
O
obscuren 已提交
405
	miningLabel := gui.getObjectByName("miningLabel")
O
obscuren 已提交
406

F
Felix Lange 已提交
407 408 409
	events := gui.eth.EventMux().Subscribe(
		eth.ChainSyncEvent{},
		eth.PeerListEvent{},
O
obscuren 已提交
410 411 412
		chain.NewBlockEvent{},
		chain.TxPreEvent{},
		chain.TxPostEvent{},
O
obscuren 已提交
413
		miner.Event{},
F
Felix Lange 已提交
414 415 416 417 418
	)

	// nameReg := gui.pipe.World().Config().Get("NameReg")
	// mux.Subscribe("object:"+string(nameReg.Address()), objectChan)

Z
zelig 已提交
419
	go func() {
F
Felix Lange 已提交
420
		defer events.Unsubscribe()
Z
zelig 已提交
421 422
		for {
			select {
F
Felix Lange 已提交
423 424 425
			case ev, isopen := <-events.Chan():
				if !isopen {
					return
Z
zelig 已提交
426
				}
F
Felix Lange 已提交
427
				switch ev := ev.(type) {
O
obscuren 已提交
428
				case chain.NewBlockEvent:
F
Felix Lange 已提交
429 430
					gui.processBlock(ev.Block, false)
					if bytes.Compare(ev.Block.Coinbase, gui.address()) == 0 {
O
obscuren 已提交
431
						gui.setWalletValue(gui.eth.BlockManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
F
Felix Lange 已提交
432
					}
O
obscuren 已提交
433

O
obscuren 已提交
434
				case chain.TxPreEvent:
F
Felix Lange 已提交
435
					tx := ev.Tx
436
					object := state.GetAccount(gui.address())
O
Cleanup  
obscuren 已提交
437

438 439 440 441 442
					if bytes.Compare(tx.Sender(), gui.address()) == 0 {
						unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
					} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
						unconfirmedFunds.Add(unconfirmedFunds, tx.Value)
					}
443

444 445
					gui.setWalletValue(object.Balance(), unconfirmedFunds)
					gui.insertTransaction("pre", tx)
O
obscuren 已提交
446

O
obscuren 已提交
447
				case chain.TxPostEvent:
448 449
					tx := ev.Tx
					object := state.GetAccount(gui.address())
O
obscuren 已提交
450

451 452
					if bytes.Compare(tx.Sender(), gui.address()) == 0 {
						object.SubAmount(tx.Value)
O
obscuren 已提交
453

O
obscuren 已提交
454
						//gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "send")
455 456 457
						gui.txDb.Put(tx.Hash(), tx.RlpEncode())
					} else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
						object.AddAmount(tx.Value)
F
Felix Lange 已提交
458

O
obscuren 已提交
459
						//gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "recv")
460
						gui.txDb.Put(tx.Hash(), tx.RlpEncode())
Z
zelig 已提交
461
					}
462

463 464 465
					gui.setWalletValue(object.Balance(), nil)
					state.UpdateStateObject(object)

F
Felix Lange 已提交
466 467 468 469 470
				// case object:
				// 	gui.loadAddressBook()

				case eth.PeerListEvent:
					gui.setPeerInfo()
O
Cleanup  
obscuren 已提交
471

O
obscuren 已提交
472 473
				case miner.Event:
					if ev.Type == miner.Started {
F
Felix Lange 已提交
474 475 476 477
						gui.miner = ev.Miner
					} else {
						gui.miner = nil
					}
Z
zelig 已提交
478
				}
Z
zelig 已提交
479 480

			case <-peerUpdateTicker.C:
Z
zelig 已提交
481
				gui.setPeerInfo()
Z
zelig 已提交
482
			case <-generalUpdateTicker.C:
O
obscuren 已提交
483
				statusText := "#" + gui.eth.ChainManager().CurrentBlock.Number.String()
O
obscuren 已提交
484 485
				lastBlockLabel.Set("text", statusText)

Z
zelig 已提交
486 487
				if gui.miner != nil {
					pow := gui.miner.GetPow()
O
obscuren 已提交
488
					miningLabel.Set("text", "Mining @ "+strconv.FormatInt(pow.GetHashrate(), 10)+"Khash")
M
Maran 已提交
489
				}
O
obscuren 已提交
490

O
obscuren 已提交
491 492 493 494 495 496
				blockLength := gui.eth.BlockPool().BlocksProcessed
				chainLength := gui.eth.BlockPool().ChainLength

				var (
					pct      float64 = 1.0 / float64(chainLength) * float64(blockLength)
					dlWidget         = gui.win.Root().ObjectByName("downloadIndicator")
O
obscuren 已提交
497
					dlLabel          = gui.win.Root().ObjectByName("downloadLabel")
O
obscuren 已提交
498
				)
O
obscuren 已提交
499

O
obscuren 已提交
500 501
				dlWidget.Set("value", pct)
				dlLabel.Set("text", fmt.Sprintf("%d / %d", blockLength, chainLength))
O
obscuren 已提交
502

O
obscuren 已提交
503 504
			case <-statsUpdateTicker.C:
				gui.setStatsPane()
O
obscuren 已提交
505 506
			}
		}
Z
zelig 已提交
507
	}()
O
obscuren 已提交
508 509
}

O
obscuren 已提交
510 511 512 513 514
func (gui *Gui) setStatsPane() {
	var memStats runtime.MemStats
	runtime.ReadMemStats(&memStats)

	statsPane := gui.getObjectByName("statsPane")
O
bump  
obscuren 已提交
515
	statsPane.Set("text", fmt.Sprintf(`###### Mist 0.6.8 (%s) #######
O
obscuren 已提交
516 517

eth %d (p2p = %d)
O
obscuren 已提交
518 519 520 521 522 523 524 525 526 527

CPU:        # %d
Goroutines: # %d
CGoCalls:   # %d

Alloc:      %d
Heap Alloc: %d

CGNext:     %x
NumGC:      %d
O
obscuren 已提交
528 529 530
`, runtime.Version(),
		eth.ProtocolVersion, eth.P2PVersion,
		runtime.NumCPU, runtime.NumGoroutine(), runtime.NumCgoCall(),
O
obscuren 已提交
531 532 533 534 535
		memStats.Alloc, memStats.HeapAlloc,
		memStats.NextGC, memStats.NumGC,
	))
}

O
obscuren 已提交
536 537
func (gui *Gui) setPeerInfo() {
	gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers))
M
Maran 已提交
538 539

	gui.win.Root().Call("resetPeers")
O
obscuren 已提交
540
	for _, peer := range gui.pipe.Peers() {
M
Maran 已提交
541 542
		gui.win.Root().Call("addPeer", peer)
	}
O
obscuren 已提交
543 544
}

Z
zelig 已提交
545 546 547 548 549 550 551
func (gui *Gui) privateKey() string {
	return ethutil.Bytes2Hex(gui.eth.KeyManager().PrivateKey())
}

func (gui *Gui) address() []byte {
	return gui.eth.KeyManager().Address()
}