示例#1
0
// Simple go routine function that updates the list of peers in the GUI
func (gui *Gui) update() {
	peerUpdateTicker := time.NewTicker(5 * time.Second)
	generalUpdateTicker := time.NewTicker(500 * time.Millisecond)
	statsUpdateTicker := time.NewTicker(5 * time.Second)

	lastBlockLabel := gui.getObjectByName("lastBlockLabel")
	//miningLabel := gui.getObjectByName("miningLabel")

	events := gui.eth.EventMux().Subscribe(
		core.ChainEvent{},
		core.TxPreEvent{},
		core.TxPostEvent{},
	)

	defer events.Unsubscribe()
	for {
		select {
		case ev, isopen := <-events.Chan():
			if !isopen {
				return
			}
			switch ev := ev.(type) {
			case core.ChainEvent:
				gui.processBlock(ev.Block, false)
			case core.TxPreEvent:
				gui.insertTransaction("pre", ev.Tx)

			case core.TxPostEvent:
				gui.getObjectByName("pendingTxView").Call("removeTx", xeth.NewTx(ev.Tx))
			}

		case <-peerUpdateTicker.C:
			gui.setPeerInfo()

		case <-generalUpdateTicker.C:
			statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String()
			lastBlockLabel.Set("text", statusText)
			//miningLabel.Set("text", strconv.FormatInt(gui.uiLib.Miner().HashRate(), 10))
		case <-statsUpdateTicker.C:
			gui.setStatsPane()
		}
	}
}
示例#2
0
func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
	var inout string
	from, _ := tx.From()
	if gui.eth.AccountManager().HasAccount(common.Hex2Bytes(from.Hex())) {
		inout = "send"
	} else {
		inout = "recv"
	}

	ptx := xeth.NewTx(tx)
	ptx.Sender = from.Hex()
	if to := tx.To(); to != nil {
		ptx.Address = to.Hex()
	}

	if window == "post" {
		//gui.getObjectByName("transactionView").Call("addTx", ptx, inout)
	} else {
		gui.getObjectByName("pendingTxView").Call("addTx", ptx, inout)
	}
}