From 1f2547b8a7cfe100f64428d20f4bcf95eb9ecc5c Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 22 Mar 2014 01:02:24 +0100 Subject: Major re-organisation. The Ethereum node and Gui are now separated. --- ethereal/ui/gui.go | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 ethereal/ui/gui.go (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go new file mode 100644 index 000000000..c8f4bedab --- /dev/null +++ b/ethereal/ui/gui.go @@ -0,0 +1,218 @@ +package ethui + +import ( + "bytes" + "encoding/hex" + "fmt" + "github.com/ethereum/eth-go" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethdb" + "github.com/ethereum/eth-go/ethutil" + "github.com/niemeyer/qml" + "math/big" + "strings" +) + +// Block interface exposed to QML +type Block struct { + Number int + Hash string +} + +type Tx struct { + Value, Hash, Address string +} + +func NewTxFromTransaction(tx *ethchain.Transaction) *Tx { + hash := hex.EncodeToString(tx.Hash()) + sender := hex.EncodeToString(tx.Recipient) + + return &Tx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender} +} + +// Creates a new QML Block from a chain block +func NewBlockFromBlock(block *ethchain.Block) *Block { + info := block.BlockInfo() + hash := hex.EncodeToString(block.Hash()) + + return &Block{Number: int(info.Number), Hash: hash} +} + +type Gui struct { + // The main application window + win *qml.Window + // QML Engine + engine *qml.Engine + component *qml.Common + // The ethereum interface + eth *eth.Ethereum + + // The public Ethereum library + lib *EthLib + + txDb *ethdb.LDBDatabase + + addr []byte +} + +// Create GUI, but doesn't start it +func New(ethereum *eth.Ethereum) *Gui { + lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} + db, err := ethdb.NewLDBDatabase("tx_database") + if err != nil { + panic(err) + } + + key := ethutil.Config.Db.GetKeys()[0] + addr := key.Address() + + ethereum.StateManager().WatchAddr(addr) + + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr} +} + +func (ui *Gui) Start() { + defer ui.txDb.Close() + + // Register ethereum functions + qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ + Init: func(p *Block, obj qml.Object) { p.Number = 0; p.Hash = "" }, + }, { + Init: func(p *Tx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, + }}) + + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.1")) + ethutil.Config.Log.Infoln("[GUI] Starting GUI") + // Create a new QML engine + ui.engine = qml.NewEngine() + context := ui.engine.Context() + + // Expose the eth library and the ui library to QML + context.SetVar("eth", ui.lib) + context.SetVar("ui", &UiLib{engine: ui.engine, eth: ui.eth}) + + // Load the main QML interface + component, err := ui.engine.LoadFile(AssetPath("qml/wallet.qml")) + if err != nil { + panic(err) + } + ui.engine.LoadFile(AssetPath("qml/transactions.qml")) + + ui.win = component.CreateWindow(nil) + + // Register the ui as a block processor + //ui.eth.BlockManager.SecondaryBlockProcessor = ui + //ui.eth.TxPool.SecondaryProcessor = ui + + // Add the ui as a log system so we can log directly to the UGI + ethutil.Config.Log.AddLogSystem(ui) + + // Loads previous blocks + go ui.setInitialBlockChain() + go ui.readPreviousTransactions() + go ui.update() + + ui.win.Show() + ui.win.Wait() + + ui.eth.Stop() +} + +func (ui *Gui) setInitialBlockChain() { + // Load previous 10 blocks + chain := ui.eth.BlockChain().GetChain(ui.eth.BlockChain().CurrentBlock.Hash(), 10) + for _, block := range chain { + ui.ProcessBlock(block) + } + +} + +func (ui *Gui) readPreviousTransactions() { + it := ui.txDb.Db().NewIterator(nil, nil) + for it.Next() { + tx := ethchain.NewTransactionFromBytes(it.Value()) + + ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + } + it.Release() +} + +func (ui *Gui) ProcessBlock(block *ethchain.Block) { + ui.win.Root().Call("addBlock", NewBlockFromBlock(block)) +} + +// Simple go routine function that updates the list of peers in the GUI +func (ui *Gui) update() { + txChan := make(chan ethchain.TxMsg, 1) + ui.eth.TxPool().Subscribe(txChan) + + account := ui.eth.StateManager().GetAddrState(ui.addr).Account + unconfirmedFunds := new(big.Int) + ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) + for { + select { + case txMsg := <-txChan: + tx := txMsg.Tx + + if txMsg.Type == ethchain.TxPre { + if bytes.Compare(tx.Sender(), ui.addr) == 0 { + ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + ui.txDb.Put(tx.Hash(), tx.RlpEncode()) + + ui.eth.StateManager().GetAddrState(ui.addr).Nonce += 1 + unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) + } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { + ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + ui.txDb.Put(tx.Hash(), tx.RlpEncode()) + + unconfirmedFunds.Add(unconfirmedFunds, tx.Value) + } + + pos := "+" + if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { + pos = "-" + } + val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) + str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(account.Amount), pos, val) + + ui.win.Root().Call("setWalletValue", str) + } else { + amount := account.Amount + if bytes.Compare(tx.Sender(), ui.addr) == 0 { + amount.Sub(account.Amount, tx.Value) + } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { + amount.Add(account.Amount, tx.Value) + } + + ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(amount))) + } + } + + /* + accountAmount := ui.eth.BlockManager.GetAddrState(ui.addr).Account.Amount + ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", accountAmount)) + + ui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", ui.eth.Peers().Len(), ui.eth.MaxPeers)) + + time.Sleep(1 * time.Second) + */ + + } +} + +// Logging functions that log directly to the GUI interface +func (ui *Gui) Println(v ...interface{}) { + str := strings.TrimRight(fmt.Sprintln(v...), "\n") + lines := strings.Split(str, "\n") + for _, line := range lines { + ui.win.Root().Call("addLog", line) + } +} + +func (ui *Gui) Printf(format string, v ...interface{}) { + str := strings.TrimRight(fmt.Sprintf(format, v...), "\n") + lines := strings.Split(str, "\n") + for _, line := range lines { + ui.win.Root().Call("addLog", line) + } +} -- cgit v1.2.3 From 49c710bf442940b3abc68123964b56b211b92c12 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 27 Mar 2014 17:14:04 +0700 Subject: assetPath configurable on command line for ethereal GUI - solves the problem of non-standard installs - add AssetPath to config as string var - introduced UiLib constructor which falls back to defaultAssetPath (earlier behaviour) if no assetPath is set - defaultAssetPath now internal concern of UiLib - gui.Start(assetPath) argument passed from ethereal main() as set Init() in config.go - informative log message if wallet.qml fails to open --- ethereal/ui/gui.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index c8f4bedab..89736ac29 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -53,6 +53,7 @@ type Gui struct { txDb *ethdb.LDBDatabase addr []byte + } // Create GUI, but doesn't start it @@ -71,7 +72,7 @@ func New(ethereum *eth.Ethereum) *Gui { return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr} } -func (ui *Gui) Start() { +func (ui *Gui) Start(assetPath string) { defer ui.txDb.Close() // Register ethereum functions @@ -89,14 +90,16 @@ func (ui *Gui) Start() { // Expose the eth library and the ui library to QML context.SetVar("eth", ui.lib) - context.SetVar("ui", &UiLib{engine: ui.engine, eth: ui.eth}) + uiLib := NewUiLib(ui.engine, ui.eth, assetPath) + context.SetVar("ui", uiLib) // Load the main QML interface - component, err := ui.engine.LoadFile(AssetPath("qml/wallet.qml")) + component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) if err != nil { + ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") panic(err) } - ui.engine.LoadFile(AssetPath("qml/transactions.qml")) + ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml")) ui.win = component.CreateWindow(nil) -- cgit v1.2.3 From e2bf5d1270b1dc33f308ab134e7e7d3f4f64b7d4 Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 10 Apr 2014 14:53:12 -0400 Subject: Implemented key importing/generation for the GUI --- ethereal/ui/gui.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 89736ac29..6184baee6 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -53,7 +53,6 @@ type Gui struct { txDb *ethdb.LDBDatabase addr []byte - } // Create GUI, but doesn't start it @@ -64,10 +63,16 @@ func New(ethereum *eth.Ethereum) *Gui { panic(err) } - key := ethutil.Config.Db.GetKeys()[0] - addr := key.Address() + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + // On first run we won't have any keys yet, so this would crash. + // Therefor we check if we are ready to actually start this process + var addr []byte + if len(data) > 0 { + key := ethutil.Config.Db.GetKeys()[0] + addr = key.Address() - ethereum.StateManager().WatchAddr(addr) + ethereum.StateManager().WatchAddr(addr) + } return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr} } @@ -94,9 +99,18 @@ func (ui *Gui) Start(assetPath string) { context.SetVar("ui", uiLib) // Load the main QML interface - component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) + data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + var err error + var component qml.Object + firstRun := len(data) == 0 + + if firstRun { + component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) + } else { + component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) + } if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") + ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") panic(err) } ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml")) @@ -111,9 +125,11 @@ func (ui *Gui) Start(assetPath string) { ethutil.Config.Log.AddLogSystem(ui) // Loads previous blocks - go ui.setInitialBlockChain() - go ui.readPreviousTransactions() - go ui.update() + if firstRun == false { + go ui.setInitialBlockChain() + go ui.readPreviousTransactions() + go ui.update() + } ui.win.Show() ui.win.Wait() -- cgit v1.2.3 From 3238894a3ba4767773849eabb7c0892554d32874 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 11 Apr 2014 12:50:31 -0400 Subject: Added wip debugger --- ethereal/ui/gui.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 89736ac29..32e7edbdc 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -53,7 +53,6 @@ type Gui struct { txDb *ethdb.LDBDatabase addr []byte - } // Create GUI, but doesn't start it @@ -96,12 +95,13 @@ func (ui *Gui) Start(assetPath string) { // Load the main QML interface component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") + ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") panic(err) } ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml")) ui.win = component.CreateWindow(nil) + uiLib.win = ui.win // Register the ui as a block processor //ui.eth.BlockManager.SecondaryBlockProcessor = ui -- cgit v1.2.3 From ab8d96258ea11c828a149dde176fe8e2efce0294 Mon Sep 17 00:00:00 2001 From: Maran Date: Fri, 11 Apr 2014 17:05:02 -0400 Subject: Added isContract to gui --- ethereal/ui/gui.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index fa4a5c833..c09c5954f 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -21,13 +21,15 @@ type Block struct { type Tx struct { Value, Hash, Address string + Contract bool } func NewTxFromTransaction(tx *ethchain.Transaction) *Tx { hash := hex.EncodeToString(tx.Hash()) sender := hex.EncodeToString(tx.Recipient) + isContract := len(tx.Data) > 0 - return &Tx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender} + return &Tx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} } // Creates a new QML Block from a chain block -- cgit v1.2.3 From ce43a9500f38bae426eef6c3c9d33e006c32c26d Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 12 Apr 2014 00:12:10 -0400 Subject: Debug steps --- ethereal/ui/gui.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index fa4a5c833..d6510bbb6 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -113,10 +113,12 @@ func (ui *Gui) Start(assetPath string) { ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") panic(err) } - ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml")) ui.win = component.CreateWindow(nil) uiLib.win = ui.win + db := &Debugger{ui.win, make(chan bool)} + ui.lib.Db = db + uiLib.Db = db // Register the ui as a block processor //ui.eth.BlockManager.SecondaryBlockProcessor = ui -- cgit v1.2.3 From 1cd7d4456b80c38f343cb54a624408c28c5acb13 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 16 Apr 2014 04:08:25 +0200 Subject: Updated to use new state object --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 1065b716e..fd29c4820 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -170,7 +170,7 @@ func (ui *Gui) update() { txChan := make(chan ethchain.TxMsg, 1) ui.eth.TxPool().Subscribe(txChan) - account := ui.eth.StateManager().GetAddrState(ui.addr).Account + account := ui.eth.StateManager().GetAddrState(ui.addr).Object unconfirmedFunds := new(big.Int) ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) for { -- cgit v1.2.3 From b962779a1318138e08c6e84a537fdbc6c9ebfd97 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 23 Apr 2014 11:51:48 +0200 Subject: Minor update and fixes to the gui and console --- ethereal/ui/gui.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index fd29c4820..0e5d57c93 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -113,6 +113,7 @@ func (ui *Gui) Start(assetPath string) { } if err != nil { ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") + panic(err) } -- cgit v1.2.3 From bb72347acf8a82d1c20e8aae25c84e5dc75903dd Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 24 Apr 2014 00:01:22 +0200 Subject: Minor fixes and sample coin "improvements" --- ethereal/ui/gui.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 0e5d57c93..80498d718 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethutil" - "github.com/niemeyer/qml" + "github.com/go-qml/qml" "math/big" "strings" ) @@ -24,6 +24,18 @@ type Tx struct { Contract bool } +type Key struct { + Address string +} + +type KeyRing struct { + Keys []interface{} +} + +func NewKeyRing(keys []interface{}) *KeyRing { + return &KeyRing{Keys: keys} +} + func NewTxFromTransaction(tx *ethchain.Transaction) *Tx { hash := hex.EncodeToString(tx.Hash()) sender := hex.EncodeToString(tx.Recipient) -- cgit v1.2.3 From e16fd323e800297602a60b7a0e7b7897a55d2fa0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 26 Apr 2014 01:47:04 +0200 Subject: Leverage the new watch & address:changed functionality --- ethereal/ui/gui.go | 52 ++++++---------------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 80498d718..d3a179496 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -2,7 +2,6 @@ package ethui import ( "bytes" - "encoding/hex" "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" @@ -13,45 +12,6 @@ import ( "strings" ) -// Block interface exposed to QML -type Block struct { - Number int - Hash string -} - -type Tx struct { - Value, Hash, Address string - Contract bool -} - -type Key struct { - Address string -} - -type KeyRing struct { - Keys []interface{} -} - -func NewKeyRing(keys []interface{}) *KeyRing { - return &KeyRing{Keys: keys} -} - -func NewTxFromTransaction(tx *ethchain.Transaction) *Tx { - hash := hex.EncodeToString(tx.Hash()) - sender := hex.EncodeToString(tx.Recipient) - isContract := len(tx.Data) > 0 - - return &Tx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} -} - -// Creates a new QML Block from a chain block -func NewBlockFromBlock(block *ethchain.Block) *Block { - info := block.BlockInfo() - hash := hex.EncodeToString(block.Hash()) - - return &Block{Number: int(info.Number), Hash: hash} -} - type Gui struct { // The main application window win *qml.Window @@ -96,9 +56,9 @@ func (ui *Gui) Start(assetPath string) { // Register ethereum functions qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ - Init: func(p *Block, obj qml.Object) { p.Number = 0; p.Hash = "" }, + Init: func(p *QBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, }, { - Init: func(p *Tx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, + Init: func(p *QTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.1")) @@ -169,13 +129,13 @@ func (ui *Gui) readPreviousTransactions() { for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) - ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + ui.win.Root().Call("addTx", NewQTx(tx)) } it.Release() } func (ui *Gui) ProcessBlock(block *ethchain.Block) { - ui.win.Root().Call("addBlock", NewBlockFromBlock(block)) + ui.win.Root().Call("addBlock", NewQBlock(block)) } // Simple go routine function that updates the list of peers in the GUI @@ -193,13 +153,13 @@ func (ui *Gui) update() { if txMsg.Type == ethchain.TxPre { if bytes.Compare(tx.Sender(), ui.addr) == 0 { - ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + ui.win.Root().Call("addTx", NewQTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) ui.eth.StateManager().GetAddrState(ui.addr).Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { - ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) + ui.win.Root().Call("addTx", NewQTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) -- cgit v1.2.3 From 0e8ca84b67465c0211a0cb46fc7bb6b9c4988dfd Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 16:52:48 +0200 Subject: Updated version number --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index d3a179496..8ec09459b 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -61,7 +61,7 @@ func (ui *Gui) Start(assetPath string) { Init: func(p *QTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.1")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2")) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine ui.engine = qml.NewEngine() -- cgit v1.2.3 From da7828f336cb323c78810d2963f8353787c03077 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Apr 2014 17:13:12 +0200 Subject: Fixed tx nonce --- ethereal/ui/gui.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8ec09459b..c821fa824 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -146,17 +146,20 @@ func (ui *Gui) update() { account := ui.eth.StateManager().GetAddrState(ui.addr).Object unconfirmedFunds := new(big.Int) ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) + + addrState := ui.eth.StateManager().GetAddrState(ui.addr) + for { select { case txMsg := <-txChan: tx := txMsg.Tx if txMsg.Type == ethchain.TxPre { - if bytes.Compare(tx.Sender(), ui.addr) == 0 { + if bytes.Compare(tx.Sender(), ui.addr) == 0 && addrState.Nonce <= tx.Nonce { ui.win.Root().Call("addTx", NewQTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) - ui.eth.StateManager().GetAddrState(ui.addr).Nonce += 1 + addrState.Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { ui.win.Root().Call("addTx", NewQTx(tx)) -- cgit v1.2.3 From 5a692b9f2bf265251b6f1faf171f55489b65b3de Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 2 May 2014 12:08:15 +0200 Subject: Moved API --- ethereal/ui/gui.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index c821fa824..8e6433207 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -7,6 +7,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" "strings" @@ -56,9 +57,9 @@ func (ui *Gui) Start(assetPath string) { // Register ethereum functions qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ - Init: func(p *QBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, + Init: func(p *utils.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, }, { - Init: func(p *QTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, + Init: func(p *utils.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2")) @@ -129,13 +130,13 @@ func (ui *Gui) readPreviousTransactions() { for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) - ui.win.Root().Call("addTx", NewQTx(tx)) + ui.win.Root().Call("addTx", utils.NewPTx(tx)) } it.Release() } func (ui *Gui) ProcessBlock(block *ethchain.Block) { - ui.win.Root().Call("addBlock", NewQBlock(block)) + ui.win.Root().Call("addBlock", utils.NewPBlock(block)) } // Simple go routine function that updates the list of peers in the GUI @@ -156,13 +157,13 @@ func (ui *Gui) update() { if txMsg.Type == ethchain.TxPre { if bytes.Compare(tx.Sender(), ui.addr) == 0 && addrState.Nonce <= tx.Nonce { - ui.win.Root().Call("addTx", NewQTx(tx)) + ui.win.Root().Call("addTx", utils.NewPTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) addrState.Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { - ui.win.Root().Call("addTx", NewQTx(tx)) + ui.win.Root().Call("addTx", utils.NewPTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) -- cgit v1.2.3 From ed64434dcc10347ad9846182ece2d71238138de9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 2 May 2014 13:55:58 +0200 Subject: Moved public interface --- ethereal/ui/gui.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8e6433207..522c081a3 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -6,8 +6,8 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethdb" + "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" "strings" @@ -57,9 +57,9 @@ func (ui *Gui) Start(assetPath string) { // Register ethereum functions qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ - Init: func(p *utils.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, + Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, }, { - Init: func(p *utils.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, + Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2")) @@ -130,13 +130,13 @@ func (ui *Gui) readPreviousTransactions() { for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) - ui.win.Root().Call("addTx", utils.NewPTx(tx)) + ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) } it.Release() } func (ui *Gui) ProcessBlock(block *ethchain.Block) { - ui.win.Root().Call("addBlock", utils.NewPBlock(block)) + ui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) } // Simple go routine function that updates the list of peers in the GUI @@ -157,13 +157,13 @@ func (ui *Gui) update() { if txMsg.Type == ethchain.TxPre { if bytes.Compare(tx.Sender(), ui.addr) == 0 && addrState.Nonce <= tx.Nonce { - ui.win.Root().Call("addTx", utils.NewPTx(tx)) + ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) addrState.Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { - ui.win.Root().Call("addTx", utils.NewPTx(tx)) + ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) -- cgit v1.2.3 From f59f515defa5735c59b3bae8a44844678adf1a2d Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 8 May 2014 18:24:28 +0200 Subject: Cleanup --- ethereal/ui/gui.go | 141 +++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 68 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 522c081a3..39da5f246 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -28,6 +28,8 @@ type Gui struct { txDb *ethdb.LDBDatabase addr []byte + + pub *ethpub.PEthereum } // Create GUI, but doesn't start it @@ -46,14 +48,16 @@ func New(ethereum *eth.Ethereum) *Gui { key := ethutil.Config.Db.GetKeys()[0] addr = key.Address() - ethereum.StateManager().WatchAddr(addr) + //ethereum.StateManager().WatchAddr(addr) } - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr} + pub := ethpub.NewPEthereum(ethereum.StateManager(), ethereum.BlockChain(), ethereum.TxPool()) + + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub} } -func (ui *Gui) Start(assetPath string) { - defer ui.txDb.Close() +func (gui *Gui) Start(assetPath string) { + defer gui.txDb.Close() // Register ethereum functions qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ @@ -65,12 +69,12 @@ func (ui *Gui) Start(assetPath string) { ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2")) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine - ui.engine = qml.NewEngine() - context := ui.engine.Context() + gui.engine = qml.NewEngine() + context := gui.engine.Context() // Expose the eth library and the ui library to QML - context.SetVar("eth", ui.lib) - uiLib := NewUiLib(ui.engine, ui.eth, assetPath) + context.SetVar("eth", gui) + uiLib := NewUiLib(gui.engine, gui.eth, assetPath) context.SetVar("ui", uiLib) // Load the main QML interface @@ -80,9 +84,9 @@ func (ui *Gui) Start(assetPath string) { firstRun := len(data) == 0 if firstRun { - component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) + component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) } else { - component, err = ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) + component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) } if err != nil { ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") @@ -90,65 +94,60 @@ func (ui *Gui) Start(assetPath string) { panic(err) } - ui.win = component.CreateWindow(nil) - uiLib.win = ui.win - db := &Debugger{ui.win, make(chan bool)} - ui.lib.Db = db + gui.win = component.CreateWindow(nil) + uiLib.win = gui.win + db := &Debugger{gui.win, make(chan bool)} + gui.lib.Db = db uiLib.Db = db - // Register the ui as a block processor - //ui.eth.BlockManager.SecondaryBlockProcessor = ui - //ui.eth.TxPool.SecondaryProcessor = ui - // Add the ui as a log system so we can log directly to the UGI - ethutil.Config.Log.AddLogSystem(ui) + ethutil.Config.Log.AddLogSystem(gui) // Loads previous blocks if firstRun == false { - go ui.setInitialBlockChain() - go ui.readPreviousTransactions() - go ui.update() + go gui.setInitialBlockChain() + go gui.readPreviousTransactions() + go gui.update() } - ui.win.Show() - ui.win.Wait() + gui.win.Show() + gui.win.Wait() - ui.eth.Stop() + gui.eth.Stop() } -func (ui *Gui) setInitialBlockChain() { +func (gui *Gui) setInitialBlockChain() { // Load previous 10 blocks - chain := ui.eth.BlockChain().GetChain(ui.eth.BlockChain().CurrentBlock.Hash(), 10) + chain := gui.eth.BlockChain().GetChain(gui.eth.BlockChain().CurrentBlock.Hash(), 10) for _, block := range chain { - ui.ProcessBlock(block) + gui.processBlock(block) } } -func (ui *Gui) readPreviousTransactions() { - it := ui.txDb.Db().NewIterator(nil, nil) +func (gui *Gui) readPreviousTransactions() { + it := gui.txDb.Db().NewIterator(nil, nil) for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) - ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) } it.Release() } -func (ui *Gui) ProcessBlock(block *ethchain.Block) { - ui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) +func (gui *Gui) processBlock(block *ethchain.Block) { + gui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) } // Simple go routine function that updates the list of peers in the GUI -func (ui *Gui) update() { +func (gui *Gui) update() { txChan := make(chan ethchain.TxMsg, 1) - ui.eth.TxPool().Subscribe(txChan) + gui.eth.TxPool().Subscribe(txChan) - account := ui.eth.StateManager().GetAddrState(ui.addr).Object - unconfirmedFunds := new(big.Int) - ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) + state := gui.eth.StateManager().TransState() - addrState := ui.eth.StateManager().GetAddrState(ui.addr) + unconfirmedFunds := new(big.Int) + gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetStateObject(gui.addr).Amount))) for { select { @@ -156,15 +155,19 @@ func (ui *Gui) update() { tx := txMsg.Tx if txMsg.Type == ethchain.TxPre { - if bytes.Compare(tx.Sender(), ui.addr) == 0 && addrState.Nonce <= tx.Nonce { - ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) - ui.txDb.Put(tx.Hash(), tx.RlpEncode()) + object := state.GetStateObject(gui.addr) + + if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce { + gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + gui.txDb.Put(tx.Hash(), tx.RlpEncode()) + + object.Nonce += 1 + state.SetStateObject(object) - addrState.Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) - } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { - ui.win.Root().Call("addTx", ethpub.NewPTx(tx)) - ui.txDb.Put(tx.Hash(), tx.RlpEncode()) + } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { + gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + gui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) } @@ -174,46 +177,48 @@ func (ui *Gui) update() { pos = "-" } val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) - str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(account.Amount), pos, val) + str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(object.Amount), pos, val) - ui.win.Root().Call("setWalletValue", str) + gui.win.Root().Call("setWalletValue", str) } else { - amount := account.Amount - if bytes.Compare(tx.Sender(), ui.addr) == 0 { - amount.Sub(account.Amount, tx.Value) - } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { - amount.Add(account.Amount, tx.Value) + object := state.GetStateObject(gui.addr) + if bytes.Compare(tx.Sender(), gui.addr) == 0 { + object.SubAmount(tx.Value) + } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { + object.AddAmount(tx.Value) } - ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(amount))) + gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(object.Amount))) + + state.SetStateObject(object) } } - - /* - accountAmount := ui.eth.BlockManager.GetAddrState(ui.addr).Account.Amount - ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", accountAmount)) - - ui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", ui.eth.Peers().Len(), ui.eth.MaxPeers)) - - time.Sleep(1 * time.Second) - */ - } } // Logging functions that log directly to the GUI interface -func (ui *Gui) Println(v ...interface{}) { +func (gui *Gui) Println(v ...interface{}) { str := strings.TrimRight(fmt.Sprintln(v...), "\n") lines := strings.Split(str, "\n") for _, line := range lines { - ui.win.Root().Call("addLog", line) + gui.win.Root().Call("addLog", line) } } -func (ui *Gui) Printf(format string, v ...interface{}) { +func (gui *Gui) Printf(format string, v ...interface{}) { str := strings.TrimRight(fmt.Sprintf(format, v...), "\n") lines := strings.Split(str, "\n") for _, line := range lines { - ui.win.Root().Call("addLog", line) + gui.win.Root().Call("addLog", line) } } + +func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { + keyPair := ethutil.Config.Db.GetKeys()[0] + + return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) +} + +func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { + return gui.Transact(recipient, value, gas, gasPrice, data) +} -- cgit v1.2.3 From 1471585af082632b33eae5bf489d0ae0b277b369 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 01:57:10 +0200 Subject: Moved Ext app js to its own dir --- ethereal/ui/gui.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 39da5f246..25f6e2fed 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "github.com/obscuren/mutan" "math/big" "strings" ) @@ -220,5 +221,9 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. } func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - return gui.Transact(recipient, value, gas, gasPrice, data) + keyPair := ethutil.Config.Db.GetKeys()[0] + + mainInput, initInput := mutan.PreProcess(data) + + return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput) } -- cgit v1.2.3 From 109395daaaac5882fcefac7577d464051c11a841 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 02:02:59 +0200 Subject: Bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 25f6e2fed..92c6e9389 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -67,7 +67,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC2")) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() -- cgit v1.2.3 From 23fc50c61b99735263eb682eb992c174eceea632 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 16:22:57 +0200 Subject: Upgraded to new mutan --- ethereal/ui/gui.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 92c6e9389..46bfa0133 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -67,7 +67,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC2")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC3")) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() @@ -223,7 +223,7 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.Config.Db.GetKeys()[0] - mainInput, initInput := mutan.PreProcess(data) + mainInput, initInput := mutan.PreParse(data) return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput) } -- cgit v1.2.3 From c43ea30e75fb0308b9cdf56070dd84d133013b51 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 12 May 2014 13:56:29 +0200 Subject: Refactored some code and fixed #37 --- ethereal/ui/gui.go | 107 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 83 insertions(+), 24 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 46bfa0133..65c87c4c2 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -24,7 +24,8 @@ type Gui struct { eth *eth.Ethereum // The public Ethereum library - lib *EthLib + lib *EthLib + uiLib *UiLib txDb *ethdb.LDBDatabase @@ -75,19 +76,55 @@ func (gui *Gui) Start(assetPath string) { // Expose the eth library and the ui library to QML context.SetVar("eth", gui) - uiLib := NewUiLib(gui.engine, gui.eth, assetPath) - context.SetVar("ui", uiLib) + gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath) + context.SetVar("ui", gui.uiLib) // Load the main QML interface data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - var err error - var component qml.Object - firstRun := len(data) == 0 + /* + var err error + var component qml.Object + firstRun := len(data) == 0 + + if firstRun { + component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) + } else { + component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) + } + if err != nil { + ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") + + panic(err) + } + + gui.win = component.CreateWindow(nil) + uiLib.win = gui.win + db := &Debugger{gui.win, make(chan bool)} + gui.lib.Db = db + uiLib.Db = db + + // Add the ui as a log system so we can log directly to the UGI + ethutil.Config.Log.AddLogSystem(gui) + + // Loads previous blocks + if firstRun == false { + go gui.setInitialBlockChain() + go gui.readPreviousTransactions() + go gui.update() + } - if firstRun { - component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) + gui.win.Show() + gui.win.Wait() + + gui.eth.Stop() + */ + + var win *qml.Window + var err error + if len(data) == 0 { + win, err = gui.showKeyImport(context) } else { - component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) + win, err = gui.showWallet(context) } if err != nil { ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") @@ -95,26 +132,48 @@ func (gui *Gui) Start(assetPath string) { panic(err) } - gui.win = component.CreateWindow(nil) - uiLib.win = gui.win - db := &Debugger{gui.win, make(chan bool)} - gui.lib.Db = db - uiLib.Db = db + win.Show() + win.Wait() + + gui.eth.Stop() +} + +func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { + component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/wallet.qml")) + if err != nil { + return nil, err + } - // Add the ui as a log system so we can log directly to the UGI - ethutil.Config.Log.AddLogSystem(gui) + win := gui.createWindow(component) - // Loads previous blocks - if firstRun == false { - go gui.setInitialBlockChain() - go gui.readPreviousTransactions() - go gui.update() + go gui.setInitialBlockChain() + go gui.readPreviousTransactions() + go gui.update() + + return win, nil +} + +func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) { + context.SetVar("lib", gui.lib) + component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/first_run.qml")) + if err != nil { + return nil, err } - gui.win.Show() - gui.win.Wait() + return gui.createWindow(component), nil +} - gui.eth.Stop() +func (gui *Gui) createWindow(comp qml.Object) *qml.Window { + win := comp.CreateWindow(nil) + + gui.win = win + gui.uiLib.win = win + + db := &Debugger{gui.win, make(chan bool)} + gui.lib.Db = db + gui.uiLib.Db = db + + return gui.win } func (gui *Gui) setInitialBlockChain() { -- cgit v1.2.3 From 8c9e6746ce741c5bc2d70f308acc955dace67e01 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 May 2014 11:59:03 +0200 Subject: Fixed wallet crash for new account. Fixes #38 --- ethereal/ui/gui.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 65c87c4c2..c1fda47f4 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -207,7 +207,7 @@ func (gui *Gui) update() { state := gui.eth.StateManager().TransState() unconfirmedFunds := new(big.Int) - gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetStateObject(gui.addr).Amount))) + gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.addr).Amount))) for { select { @@ -215,7 +215,7 @@ func (gui *Gui) update() { tx := txMsg.Tx if txMsg.Type == ethchain.TxPre { - object := state.GetStateObject(gui.addr) + object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce { gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) @@ -241,7 +241,7 @@ func (gui *Gui) update() { gui.win.Root().Call("setWalletValue", str) } else { - object := state.GetStateObject(gui.addr) + object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 { object.SubAmount(tx.Value) } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { -- cgit v1.2.3 From 03371b74d7b169c0ad6ccf8868bc97c7fe85169d Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 May 2014 12:42:01 +0200 Subject: Public ethereum interface uses EthManager --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index c1fda47f4..3393b1101 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -53,7 +53,7 @@ func New(ethereum *eth.Ethereum) *Gui { //ethereum.StateManager().WatchAddr(addr) } - pub := ethpub.NewPEthereum(ethereum.StateManager(), ethereum.BlockChain(), ethereum.TxPool()) + pub := ethpub.NewPEthereum(ethereum) return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub} } -- cgit v1.2.3 From 9caf53f8c63cb30a174d2b33ef85176c8f6f8204 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 May 2014 16:37:15 +0200 Subject: Bumped --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 3393b1101..7f84272d6 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -68,7 +68,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC3")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC4")) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() -- cgit v1.2.3 From f18ec51cb3959cc662bfc7b84314cd1d3b1541b5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 May 2014 13:55:08 +0200 Subject: Switched to new keyring methods --- ethereal/ui/gui.go | 49 ++++--------------------------------------------- 1 file changed, 4 insertions(+), 45 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7f84272d6..396447a81 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -42,15 +42,11 @@ func New(ethereum *eth.Ethereum) *Gui { panic(err) } - data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) // On first run we won't have any keys yet, so this would crash. // Therefor we check if we are ready to actually start this process var addr []byte - if len(data) > 0 { - key := ethutil.Config.Db.GetKeys()[0] - addr = key.Address() - - //ethereum.StateManager().WatchAddr(addr) + if ethutil.GetKeyRing().Len() != 0 { + addr = ethutil.GetKeyRing().Get(0).Address() } pub := ethpub.NewPEthereum(ethereum) @@ -81,43 +77,6 @@ func (gui *Gui) Start(assetPath string) { // Load the main QML interface data, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - /* - var err error - var component qml.Object - firstRun := len(data) == 0 - - if firstRun { - component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/first_run.qml")) - } else { - component, err = gui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml")) - } - if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") - - panic(err) - } - - gui.win = component.CreateWindow(nil) - uiLib.win = gui.win - db := &Debugger{gui.win, make(chan bool)} - gui.lib.Db = db - uiLib.Db = db - - // Add the ui as a log system so we can log directly to the UGI - ethutil.Config.Log.AddLogSystem(gui) - - // Loads previous blocks - if firstRun == false { - go gui.setInitialBlockChain() - go gui.readPreviousTransactions() - go gui.update() - } - - gui.win.Show() - gui.win.Wait() - - gui.eth.Stop() - */ var win *qml.Window var err error @@ -274,13 +233,13 @@ func (gui *Gui) Printf(format string, v ...interface{}) { } func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.Config.Db.GetKeys()[0] + keyPair := ethutil.GetKeyRing().Get(0) return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) } func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.Config.Db.GetKeys()[0] + keyPair := ethutil.GetKeyRing().Get(0) mainInput, initInput := mutan.PreParse(data) -- cgit v1.2.3 From 9a057021c3bb7b73843677b7abefc7763f34e39e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 May 2014 14:57:05 +0200 Subject: Update wallet value for coinbase rewards. Implements #44 & #43 --- ethereal/ui/gui.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 396447a81..d6d65cc0b 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -158,8 +158,29 @@ func (gui *Gui) processBlock(block *ethchain.Block) { gui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) } +func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { + var str string + if unconfirmedFunds != nil { + pos := "+" + if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { + 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) +} + // Simple go routine function that updates the list of peers in the GUI func (gui *Gui) update() { + blockChan := make(chan ethutil.React, 1) + reactor := gui.eth.Reactor() + + reactor.Subscribe("newBlock", blockChan) + txChan := make(chan ethchain.TxMsg, 1) gui.eth.TxPool().Subscribe(txChan) @@ -170,6 +191,12 @@ func (gui *Gui) update() { for { select { + case b := <-blockChan: + block := b.Resource.(*ethchain.Block) + if bytes.Compare(block.Coinbase, gui.addr) == 0 { + gui.setWalletValue(gui.eth.StateManager().ProcState().GetAccount(gui.addr).Amount, nil) + } + case txMsg := <-txChan: tx := txMsg.Tx @@ -191,14 +218,7 @@ func (gui *Gui) update() { unconfirmedFunds.Add(unconfirmedFunds, tx.Value) } - pos := "+" - if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { - pos = "-" - } - val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) - str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(object.Amount), pos, val) - - gui.win.Root().Call("setWalletValue", str) + gui.setWalletValue(object.Amount, unconfirmedFunds) } else { object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 { @@ -207,7 +227,7 @@ func (gui *Gui) update() { object.AddAmount(tx.Value) } - gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(object.Amount))) + gui.setWalletValue(object.Amount, nil) state.SetStateObject(object) } -- cgit v1.2.3 From a73ae8727d38391c6975a9fa149043e6c69a2f30 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 May 2014 21:34:01 +0200 Subject: Bumped version --- ethereal/ui/gui.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index d6d65cc0b..aa0364998 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -55,6 +55,8 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { + const version = "0.5.0 RC6" + defer gui.txDb.Close() // Register ethereum functions @@ -64,7 +66,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.5.0 RC4")) + ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() -- cgit v1.2.3 From 3a2bddc160ece4dcb6d2d5bcc85091d244e774c0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 15 May 2014 14:06:06 +0200 Subject: Refactored to reactor. Fixes #42 --- ethereal/ui/gui.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index aa0364998..c4cc1373f 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -178,13 +178,14 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { // Simple go routine function that updates the list of peers in the GUI func (gui *Gui) update() { - blockChan := make(chan ethutil.React, 1) reactor := gui.eth.Reactor() - reactor.Subscribe("newBlock", blockChan) + blockChan := make(chan ethutil.React, 1) + txChan := make(chan ethutil.React, 1) - txChan := make(chan ethchain.TxMsg, 1) - gui.eth.TxPool().Subscribe(txChan) + reactor.Subscribe("newBlock", blockChan) + reactor.Subscribe("newTx:pre", txChan) + reactor.Subscribe("newTx:post", txChan) state := gui.eth.StateManager().TransState() @@ -200,9 +201,9 @@ func (gui *Gui) update() { } case txMsg := <-txChan: - tx := txMsg.Tx + tx := txMsg.Resource.(*ethchain.Transaction) - if txMsg.Type == ethchain.TxPre { + if txMsg.Event == "newTx:pre" { object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce { -- cgit v1.2.3 From 770808ce0d44cadfedbe01694c836be2eaf0e82c Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 17 May 2014 15:15:46 +0200 Subject: Readline repl for linux & osx --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index c4cc1373f..24be9e0c5 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -197,7 +197,7 @@ func (gui *Gui) update() { case b := <-blockChan: block := b.Resource.(*ethchain.Block) if bytes.Compare(block.Coinbase, gui.addr) == 0 { - gui.setWalletValue(gui.eth.StateManager().ProcState().GetAccount(gui.addr).Amount, nil) + gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.addr).Amount, nil) } case txMsg := <-txChan: -- cgit v1.2.3 From 43f88b2bbb6fc993f8bfee531056a7e11bef59bd Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 19 May 2014 12:14:32 +0200 Subject: Removed nonce incrementing --- ethereal/ui/gui.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 24be9e0c5..e465d5273 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -210,8 +210,10 @@ func (gui *Gui) update() { gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) gui.txDb.Put(tx.Hash(), tx.RlpEncode()) - object.Nonce += 1 - state.SetStateObject(object) + /* + object.Nonce += 1 + state.SetStateObject(object) + */ unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { -- cgit v1.2.3 From 34014c1c516ea03b28e56db1a0478087d2416f74 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 17:08:23 +0200 Subject: Bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index e465d5273..e267dabfd 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -55,7 +55,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC6" + const version = "0.5.0 RC7" defer gui.txDb.Close() -- cgit v1.2.3 From 16bd88c10ab3553984d180e3048839982c864f69 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 12:14:39 +0200 Subject: Removed method name --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index e267dabfd..440e94e22 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -234,7 +234,7 @@ func (gui *Gui) update() { gui.setWalletValue(object.Amount, nil) - state.SetStateObject(object) + state.UpdateStateObject(object) } } } -- cgit v1.2.3 From 68f4a12a8b6e0cde4a8ba144d2f63e911361cb58 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 13:37:46 +0200 Subject: Fixed unconfirmed balance string --- ethereal/ui/gui.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 440e94e22..3e2fc0dbd 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -164,7 +164,7 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { var str string if unconfirmedFunds != nil { pos := "+" - if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { + if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 { pos = "-" } val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) @@ -206,15 +206,10 @@ func (gui *Gui) update() { if txMsg.Event == "newTx:pre" { object := state.GetAccount(gui.addr) - if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce { + if bytes.Compare(tx.Sender(), gui.addr) == 0 { gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) gui.txDb.Put(tx.Hash(), tx.RlpEncode()) - /* - object.Nonce += 1 - state.SetStateObject(object) - */ - unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) -- cgit v1.2.3 From 10e2c40b59010ec594df43d057354d05a34709ff Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 14:00:54 +0200 Subject: Improved on some ui elements --- ethereal/ui/gui.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 3e2fc0dbd..6043152f9 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -74,6 +74,7 @@ func (gui *Gui) Start(assetPath string) { // Expose the eth library and the ui library to QML context.SetVar("eth", gui) + context.SetVar("pub", gui.pub) gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath) context.SetVar("ui", gui.uiLib) -- cgit v1.2.3 From 3ddaf56afd919d1bc435379861a3ab37f3392116 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 14:04:11 +0200 Subject: Bumped --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 6043152f9..7290bd6ec 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -55,7 +55,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC7" + const version = "0.5.0 RC8" defer gui.txDb.Close() -- cgit v1.2.3 From d35380c19e5ce92b57158e7780f7105dc4136916 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 23 May 2014 14:37:03 +0200 Subject: New main script through init return value --- ethereal/ui/gui.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7290bd6ec..022f192bf 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "github.com/obscuren/mutan" "math/big" "strings" ) @@ -262,7 +261,7 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.GetKeyRing().Get(0) - mainInput, initInput := mutan.PreParse(data) + //mainInput, initInput := mutan.PreParse(data) - return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput) + return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data) } -- cgit v1.2.3 From b42c70be9c669ba372ed99d820a5a9e807191619 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 26 May 2014 00:10:38 +0200 Subject: Recv send for txs --- ethereal/ui/gui.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 022f192bf..a8bfb2b58 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -151,7 +151,15 @@ func (gui *Gui) readPreviousTransactions() { for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) - gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + var inout string + if bytes.Compare(tx.Sender(), gui.addr) == 0 { + inout = "send" + } else { + inout = "recv" + } + + gui.win.Root().Call("addTx", ethpub.NewPTx(tx), inout) + } it.Release() } @@ -207,12 +215,12 @@ func (gui *Gui) update() { object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 { - gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { - gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) + gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) @@ -261,7 +269,5 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.GetKeyRing().Get(0) - //mainInput, initInput := mutan.PreParse(data) - return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data) } -- cgit v1.2.3 From 818bc84591c490b29cb28ee1e4895c8f303a0af1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 26 May 2014 00:39:05 +0200 Subject: Bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index a8bfb2b58..8d6796ddb 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -54,7 +54,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC8" + const version = "0.5.0 RC9" defer gui.txDb.Close() -- cgit v1.2.3 From 5fc6ee6a4acd1db22a38abb4cff5e5196bf1538e Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 26 May 2014 17:07:20 +0200 Subject: Implemented simple block/tx explorer --- ethereal/ui/gui.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8d6796ddb..794786d97 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -136,14 +136,20 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { return gui.win } - -func (gui *Gui) setInitialBlockChain() { - // Load previous 10 blocks - chain := gui.eth.BlockChain().GetChain(gui.eth.BlockChain().CurrentBlock.Hash(), 10) - for _, block := range chain { - gui.processBlock(block) +func (gui *Gui) recursiveAdd(sBlk []byte) { + blk := gui.eth.BlockChain().GetBlock(sBlk) + if blk != nil { + //ethutil.Config.Log.Infoln("Adding block", blk) + gui.processBlock(blk) + gui.recursiveAdd(blk.PrevHash) + return + } else { + //ethutil.Config.Log.Debugln("At Genesis, added all blocks to GUI") } - + return +} +func (gui *Gui) setInitialBlockChain() { + gui.recursiveAdd(gui.eth.BlockChain().LastBlockHash) } func (gui *Gui) readPreviousTransactions() { -- cgit v1.2.3 From d694e00a3340a36c39872950bb7a2404e9686c18 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 26 May 2014 21:11:38 +0200 Subject: Fixed debugger --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8d6796ddb..1018d77ac 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -130,7 +130,7 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { gui.win = win gui.uiLib.win = win - db := &Debugger{gui.win, make(chan bool)} + db := &Debugger{gui.win, make(chan bool), true} gui.lib.Db = db gui.uiLib.Db = db -- cgit v1.2.3 From 47a58b40cd4ba764c9823448687307bb4a80c697 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 27 May 2014 10:29:39 +0200 Subject: Removed recursive function for loop --- ethereal/ui/gui.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 64c739c15..7577de1fa 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -136,20 +136,13 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { return gui.win } -func (gui *Gui) recursiveAdd(sBlk []byte) { +func (gui *Gui) setInitialBlockChain() { + sBlk := gui.eth.BlockChain().LastBlockHash blk := gui.eth.BlockChain().GetBlock(sBlk) - if blk != nil { - //ethutil.Config.Log.Infoln("Adding block", blk) + for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) { + sBlk = blk.PrevHash gui.processBlock(blk) - gui.recursiveAdd(blk.PrevHash) - return - } else { - //ethutil.Config.Log.Debugln("At Genesis, added all blocks to GUI") } - return -} -func (gui *Gui) setInitialBlockChain() { - gui.recursiveAdd(gui.eth.BlockChain().LastBlockHash) } func (gui *Gui) readPreviousTransactions() { -- cgit v1.2.3 From 1ab865a994758cef8a6bf75a3cc263f16a97d847 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 27 May 2014 11:49:42 +0200 Subject: Adding new blocks on broadcast --- ethereal/ui/gui.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7577de1fa..18e13d985 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -141,7 +141,7 @@ func (gui *Gui) setInitialBlockChain() { blk := gui.eth.BlockChain().GetBlock(sBlk) for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) { sBlk = blk.PrevHash - gui.processBlock(blk) + gui.processBlock(blk, true) } } @@ -163,8 +163,8 @@ func (gui *Gui) readPreviousTransactions() { it.Release() } -func (gui *Gui) processBlock(block *ethchain.Block) { - gui.win.Root().Call("addBlock", ethpub.NewPBlock(block)) +func (gui *Gui) processBlock(block *ethchain.Block, initial bool) { + gui.win.Root().Call("addBlock", ethpub.NewPBlock(block), initial) } func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { @@ -203,6 +203,7 @@ func (gui *Gui) update() { select { case b := <-blockChan: block := b.Resource.(*ethchain.Block) + gui.processBlock(block, false) if bytes.Compare(block.Coinbase, gui.addr) == 0 { gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.addr).Amount, nil) } -- cgit v1.2.3 From 47417506c377dd0848739473fa14a51708b6a034 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 13:28:11 +0200 Subject: New debugger implemented --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 1018d77ac..ca6da5c49 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -130,7 +130,7 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { gui.win = win gui.uiLib.win = win - db := &Debugger{gui.win, make(chan bool), true} + db := &Debugger{gui.win, make(chan bool), make(chan bool), true} gui.lib.Db = db gui.uiLib.Db = db -- cgit v1.2.3 From 34b861c19c02947503a175f7b2be6c880a007d11 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 16:10:15 +0200 Subject: bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index b49fafac1..63ab028ab 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -54,7 +54,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC9" + const version = "0.5.0 RC10" defer gui.txDb.Close() -- cgit v1.2.3 From 58032d60e748611b0610cf764743c6b8e5681a87 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 28 May 2014 16:17:57 +0200 Subject: Bump to RC11 --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 63ab028ab..32ff76b1a 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -54,7 +54,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC10" + const version = "0.5.0 RC11" defer gui.txDb.Close() -- cgit v1.2.3 From 8fab7ce37d6748cbf34ebee96622448ec8a4c9e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 May 2014 23:14:23 +0200 Subject: Fixes and improved debugger --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 63ab028ab..6a1c4f110 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -269,5 +269,5 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.GetKeyRing().Get(0) - return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data) + return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) } -- cgit v1.2.3 From efadfbfb1779549c2898304dce4bbce30b067ceb Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 May 2014 12:24:14 +0200 Subject: Minor UI changes * Moved log from block view * Prepend instead of append for logs --- ethereal/ui/gui.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 1698f5de0..9a8673a1c 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -66,7 +66,6 @@ func (gui *Gui) Start(assetPath string) { }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) - ethutil.Config.Log.Infoln("[GUI] Starting GUI") // Create a new QML engine gui.engine = qml.NewEngine() context := gui.engine.Context() @@ -93,6 +92,9 @@ func (gui *Gui) Start(assetPath string) { panic(err) } + ethutil.Config.Log.AddLogSystem(gui) + ethutil.Config.Log.Infoln("[GUI] Starting GUI") + win.Show() win.Wait() -- cgit v1.2.3 From fcbf99a30a15b445c35d70a8a781190a2739845b Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 11:50:30 +0200 Subject: Minor GUI updates * IceCream => IceCREAM * Added coin base to block info --- ethereal/ui/gui.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 9a8673a1c..d08c1b118 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -110,6 +110,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { win := gui.createWindow(component) go gui.setInitialBlockChain() + go gui.loadAddressBook() go gui.readPreviousTransactions() go gui.update() @@ -147,6 +148,19 @@ func (gui *Gui) setInitialBlockChain() { } } +type address struct { + Name, Address string +} + +var namereg = ethutil.FromHex("bb5f186604d057c1c5240ca2ae0f6430138ac010") + +func (gui *Gui) loadAddressBook() { + gui.win.Root().Call("clearAddress") + gui.eth.StateManager().CurrentState().GetStateObject(namereg).State().EachStorage(func(name string, value *ethutil.Value) { + gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Hex(value.Bytes())}) + }) +} + func (gui *Gui) readPreviousTransactions() { it := gui.txDb.Db().NewIterator(nil, nil) for it.Next() { @@ -191,10 +205,12 @@ func (gui *Gui) update() { blockChan := make(chan ethutil.React, 1) txChan := make(chan ethutil.React, 1) + objectChan := make(chan ethutil.React, 1) reactor.Subscribe("newBlock", blockChan) reactor.Subscribe("newTx:pre", txChan) reactor.Subscribe("newTx:post", txChan) + reactor.Subscribe("object:"+string(namereg), objectChan) state := gui.eth.StateManager().TransState() @@ -241,6 +257,8 @@ func (gui *Gui) update() { state.UpdateStateObject(object) } + case <-objectChan: + gui.loadAddressBook() } } } -- cgit v1.2.3 From 0938b56829b9cbe8804a4ca85b14534908dbdfbc Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 13:04:23 +0200 Subject: Update peer info --- ethereal/ui/gui.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index d08c1b118..7c37e2d62 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -109,9 +109,11 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { win := gui.createWindow(component) - go gui.setInitialBlockChain() - go gui.loadAddressBook() - go gui.readPreviousTransactions() + gui.setInitialBlockChain() + gui.loadAddressBook() + gui.readPreviousTransactions() + gui.setPeerInfo() + go gui.update() return win, nil @@ -206,11 +208,13 @@ func (gui *Gui) update() { blockChan := make(chan ethutil.React, 1) txChan := make(chan ethutil.React, 1) objectChan := make(chan ethutil.React, 1) + peerChan := make(chan ethutil.React, 1) reactor.Subscribe("newBlock", blockChan) reactor.Subscribe("newTx:pre", txChan) reactor.Subscribe("newTx:post", txChan) reactor.Subscribe("object:"+string(namereg), objectChan) + reactor.Subscribe("peerList", peerChan) state := gui.eth.StateManager().TransState() @@ -259,10 +263,16 @@ func (gui *Gui) update() { } case <-objectChan: gui.loadAddressBook() + case <-peerChan: + gui.setPeerInfo() } } } +func (gui *Gui) setPeerInfo() { + gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers)) +} + // Logging functions that log directly to the GUI interface func (gui *Gui) Println(v ...interface{}) { str := strings.TrimRight(fmt.Sprintln(v...), "\n") -- cgit v1.2.3 From e7c9b86a5aba022afd812f1a4fb554ee17a74bbd Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 13:28:31 +0200 Subject: Improved UI * Added mining button --- ethereal/ui/gui.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7c37e2d62..d6430d1fe 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" "strings" @@ -101,6 +102,19 @@ func (gui *Gui) Start(assetPath string) { gui.eth.Stop() } +func (gui *Gui) ToggleMining() { + var txt string + if gui.eth.Mining { + utils.StopMining(gui.eth) + txt = "Start mining" + } else { + utils.StartMining(gui.eth) + txt = "Stop mining" + } + + gui.win.Root().Set("miningButtonText", txt) +} + func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/wallet.qml")) if err != nil { -- cgit v1.2.3 From 0bdb0a9d58be08e210eb94dc6893f6103202ae7c Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 19:36:05 +0200 Subject: Added ini file for ethereum. fixes #66 --- ethereal/ui/gui.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index d6430d1fe..42d1c7a04 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -67,6 +67,7 @@ func (gui *Gui) Start(assetPath string) { }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) + // Create a new QML engine gui.engine = qml.NewEngine() context := gui.engine.Context() @@ -315,3 +316,11 @@ func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PR return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) } + +func (gui *Gui) ChangeClientId(id string) { + ethutil.Config.SetIdentifier(id) +} + +func (gui *Gui) ClientId() string { + return ethutil.Config.Identifier +} -- cgit v1.2.3 From be27309dbb75730c74fed1c355411997472203c6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 20:35:37 +0200 Subject: show first? --- ethereal/ui/gui.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 42d1c7a04..b8245f47e 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -94,10 +94,11 @@ func (gui *Gui) Start(assetPath string) { panic(err) } + win.Show() + ethutil.Config.Log.AddLogSystem(gui) ethutil.Config.Log.Infoln("[GUI] Starting GUI") - win.Show() win.Wait() gui.eth.Stop() -- cgit v1.2.3 From d6acb74ac95fc2630e5a1e2c71cc6534f135606b Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 31 May 2014 11:34:37 +0200 Subject: fixed logging issue that would otherwise crash the client. Fixes #68 --- ethereal/ui/gui.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index b8245f47e..44215efdb 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -87,6 +87,8 @@ func (gui *Gui) Start(assetPath string) { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) + + ethutil.Config.Log.AddLogSystem(gui) } if err != nil { ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") @@ -94,11 +96,9 @@ func (gui *Gui) Start(assetPath string) { panic(err) } - win.Show() - - ethutil.Config.Log.AddLogSystem(gui) ethutil.Config.Log.Infoln("[GUI] Starting GUI") + win.Show() win.Wait() gui.eth.Stop() @@ -174,9 +174,12 @@ var namereg = ethutil.FromHex("bb5f186604d057c1c5240ca2ae0f6430138ac010") func (gui *Gui) loadAddressBook() { gui.win.Root().Call("clearAddress") - gui.eth.StateManager().CurrentState().GetStateObject(namereg).State().EachStorage(func(name string, value *ethutil.Value) { - gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Hex(value.Bytes())}) - }) + stateObject := gui.eth.StateManager().CurrentState().GetStateObject(namereg) + if stateObject != nil { + stateObject.State().EachStorage(func(name string, value *ethutil.Value) { + gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Hex(value.Bytes())}) + }) + } } func (gui *Gui) readPreviousTransactions() { -- cgit v1.2.3 From a6f4eef1dadee9d8caa9b0ac20e2ce4a3034a100 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 2 Jun 2014 15:16:37 +0200 Subject: Added Peer Window --- ethereal/ui/gui.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 44215efdb..db06add8e 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -12,6 +12,7 @@ import ( "github.com/go-qml/qml" "math/big" "strings" + "time" ) type Gui struct { @@ -91,7 +92,7 @@ func (gui *Gui) Start(assetPath string) { ethutil.Config.Log.AddLogSystem(gui) } if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'") + ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'", err) panic(err) } @@ -235,6 +236,8 @@ func (gui *Gui) update() { reactor.Subscribe("object:"+string(namereg), objectChan) reactor.Subscribe("peerList", peerChan) + ticker := time.NewTicker(5 * time.Second) + state := gui.eth.StateManager().TransState() unconfirmedFunds := new(big.Int) @@ -284,12 +287,19 @@ func (gui *Gui) update() { gui.loadAddressBook() case <-peerChan: gui.setPeerInfo() + case <-ticker.C: + gui.setPeerInfo() } } } func (gui *Gui) setPeerInfo() { gui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", gui.eth.PeerCount(), gui.eth.MaxPeers)) + + gui.win.Root().Call("resetPeers") + for _, peer := range gui.pub.GetPeers() { + gui.win.Root().Call("addPeer", peer) + } } // Logging functions that log directly to the GUI interface -- cgit v1.2.3 From cc1d043423293eff97d01c8f4897b354112c8210 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 3 Jun 2014 11:48:44 +0200 Subject: Implemented transaction catching up. Implements #73 --- ethereal/ui/gui.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index db06add8e..701bacf00 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -163,6 +163,17 @@ func (gui *Gui) setInitialBlockChain() { blk := gui.eth.BlockChain().GetBlock(sBlk) for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) { sBlk = blk.PrevHash + + // Loop through all transactions to see if we missed any while being offline + for _, tx := range blk.Transactions() { + if bytes.Compare(tx.Sender(), gui.addr) == 0 || bytes.Compare(tx.Recipient, gui.addr) == 0 { + if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil { + gui.txDb.Put(tx.Hash(), tx.RlpEncode()) + } + + } + } + gui.processBlock(blk, true) } } -- cgit v1.2.3 From 3755616a2912f47a963d4ecc781bddd4229fe290 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 3 Jun 2014 14:30:26 +0200 Subject: Added namereg register option to qml wallet --- ethereal/ui/gui.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 701bacf00..9fc1abc28 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -329,6 +329,11 @@ func (gui *Gui) Printf(format string, v ...interface{}) { gui.win.Root().Call("addLog", line) } } +func (gui *Gui) RegisterName(name string) { + keyPair := ethutil.GetKeyRing().Get(0) + name = fmt.Sprintf("\"%s\"\n1", name) + gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), "namereg", "1000", "1000000", "150", name) +} func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.GetKeyRing().Get(0) -- cgit v1.2.3 From 7843390ecd52df37a28282d76be198d5456ce385 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 4 Jun 2014 15:54:33 +0200 Subject: Implement getStateKeyVal for JS bindings. Gives JS the option to 'loop' over contract key/val storage --- ethereal/ui/gui.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 9fc1abc28..4dda5017f 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -65,6 +65,8 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.PBlock, obj qml.Object) { p.Number = 0; p.Hash = "" }, }, { Init: func(p *ethpub.PTx, obj qml.Object) { p.Value = ""; p.Hash = ""; p.Address = "" }, + }, { + Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" }, }}) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) -- cgit v1.2.3 From ba3623d0cc0608f2d73e10e61a184238924fccdb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 9 Jun 2014 22:04:16 +0200 Subject: Fixed debugger hang --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 4dda5017f..5954df70c 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -154,7 +154,7 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { gui.win = win gui.uiLib.win = win - db := &Debugger{gui.win, make(chan bool), make(chan bool), true} + db := &Debugger{gui.win, make(chan bool), make(chan bool), true, false} gui.lib.Db = db gui.uiLib.Db = db -- cgit v1.2.3 From d929c634749c3c2db9f3290e635a763eba211656 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 9 Jun 2014 22:23:33 +0200 Subject: bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 5954df70c..2ba89ce22 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -56,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC11" + const version = "0.5.0 RC12" defer gui.txDb.Close() -- cgit v1.2.3 From e7a22af0e633db4da3d81f1ad07126ea3b06f891 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 12 Jun 2014 10:06:02 +0200 Subject: Minor UI adjustments --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 2ba89ce22..23f53ef47 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -69,7 +69,7 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" }, }}) - ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", version)) + ethutil.Config.SetClientString("Ethereal") // Create a new QML engine gui.engine = qml.NewEngine() -- cgit v1.2.3 From ef1b923b31dfda78bc8f3dce415721aa9518fe4b Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 14 Jun 2014 15:44:32 +0200 Subject: Added a log level slider which can change the log level --- ethereal/ui/gui.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 23f53ef47..b67035149 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -356,3 +356,7 @@ func (gui *Gui) ChangeClientId(id string) { func (gui *Gui) ClientId() string { return ethutil.Config.Identifier } + +func (gui *Gui) SetLogLevel(level int) { + ethutil.Config.Log.SetLevel(level) +} -- cgit v1.2.3 From c1220e87293e440f842095c5a601515c0c8f5cb0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 16 Jun 2014 18:24:24 +0200 Subject: bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index b67035149..01d963332 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -56,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC12" + const version = "0.5.0 RC13" defer gui.txDb.Close() -- cgit v1.2.3 From 65cbea2b6a5d1321c8262f88d952f0be7fbebe3d Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 20 Jun 2014 00:48:48 +0200 Subject: bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 01d963332..1037ba5ac 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -56,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC13" + const version = "0.5.0 RC14" defer gui.txDb.Close() -- cgit v1.2.3 From d060ae6a368bb880132e548c58b33e2508adc125 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 11:41:11 +0100 Subject: changed logger API, functions that allow Gui to implement ethlog.LogSystem for gui logging --- ethereal/ui/gui.go | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 01d963332..d3b298d90 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -15,6 +16,8 @@ import ( "time" ) +var logger = ethlog.NewLogger("GUI") + type Gui struct { // The main application window win *qml.Window @@ -33,10 +36,11 @@ type Gui struct { addr []byte pub *ethpub.PEthereum + logLevel ethlog.LogLevel } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum) *Gui { +func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { @@ -52,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: logLevel} } func (gui *Gui) Start(assetPath string) { @@ -90,16 +94,15 @@ func (gui *Gui) Start(assetPath string) { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) - - ethutil.Config.Log.AddLogSystem(gui) + ethlog.AddLogSystem(gui) } if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'", err) + logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err) panic(err) } - ethutil.Config.Log.Infoln("[GUI] Starting GUI") + logger.Infoln("Starting GUI") win.Show() win.Wait() @@ -315,22 +318,6 @@ func (gui *Gui) setPeerInfo() { } } -// Logging functions that log directly to the GUI interface -func (gui *Gui) Println(v ...interface{}) { - str := strings.TrimRight(fmt.Sprintln(v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} - -func (gui *Gui) Printf(format string, v ...interface{}) { - str := strings.TrimRight(fmt.Sprintf(format, v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} func (gui *Gui) RegisterName(name string) { keyPair := ethutil.GetKeyRing().Get(0) name = fmt.Sprintf("\"%s\"\n1", name) @@ -357,6 +344,28 @@ func (gui *Gui) ClientId() string { return ethutil.Config.Identifier } -func (gui *Gui) SetLogLevel(level int) { - ethutil.Config.Log.SetLevel(level) +// functions that allow Gui to implement interface ethlog.LogSystem +func (gui *Gui) SetLogLevel(level ethlog.LogLevel) { + gui.logLevel = level +} + +func (gui *Gui) GetLogLevel() ethlog.LogLevel { + return gui.logLevel +} + +func (gui *Gui) Println(v ...interface{}) { + gui.printLog(fmt.Sprintln(v...)) +} + +func (gui *Gui) Printf(format string, v ...interface{}) { + gui.printLog(fmt.Sprintf(format, v...)) +} + +// Print function that logs directly to the GUI +func (gui *Gui) printLog(s string) { + str := strings.TrimRight(s, "\n") + lines := strings.Split(str, "\n") + for _, line := range lines { + gui.win.Root().Call("addLog", line) + } } -- cgit v1.2.3 From 6f09a3e8200ba2eeeeb296141d6644d04078a9c4 Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:38:23 +0100 Subject: fix imports in ui_lib and flags cos of defaultAssetPath move; fix logLevel type for gui --- ethereal/ui/gui.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index ed29e2485..f3a918ea0 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -40,7 +40,7 @@ type Gui struct { } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { +func New(ethereum *eth.Ethereum, logLevel int) *Gui { lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { @@ -56,7 +56,7 @@ func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: logLevel} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel)} } func (gui *Gui) Start(assetPath string) { -- cgit v1.2.3 From b3367ec0e3e69694481cccd9335a63d2c559a543 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Jun 2014 10:37:48 +0200 Subject: Added option to not break eachline --- ethereal/ui/gui.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 1037ba5ac..7b59e2fbc 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -154,10 +154,6 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { gui.win = win gui.uiLib.win = win - db := &Debugger{gui.win, make(chan bool), make(chan bool), true, false} - gui.lib.Db = db - gui.uiLib.Db = db - return gui.win } func (gui *Gui) setInitialBlockChain() { -- cgit v1.2.3 From c0a05fcf8984f04f198c5c0f8be4f73090f99403 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 12:13:31 +0100 Subject: log slider - only add the gui logger after window is shown otherwise slider wont be shown - need to silence gui logger after window closed otherwise logsystem hangs - gui.GetLogLevelInt() extra function needed to give correcty int typecast value to gui widget that sets initial loglevel to default --- ethereal/ui/gui.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index f3a918ea0..8845f6af3 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -90,11 +90,12 @@ func (gui *Gui) Start(assetPath string) { var win *qml.Window var err error + var addlog = false if len(data) == 0 { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) - ethlog.AddLogSystem(gui) + addlog = true } if err != nil { logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err) @@ -105,8 +106,13 @@ func (gui *Gui) Start(assetPath string) { logger.Infoln("Starting GUI") win.Show() + // only add the gui logger after window is shown otherwise slider wont be shown + if addlog { + ethlog.AddLogSystem(gui) + } win.Wait() - + // need to silence gui logger after window closed otherwise logsystem hangs + gui.SetLogLevel(ethlog.Silence) gui.eth.Stop() } @@ -353,6 +359,12 @@ func (gui *Gui) GetLogLevel() ethlog.LogLevel { return gui.logLevel } +// this extra function needed to give int typecast value to gui widget +// that sets initial loglevel to default +func (gui *Gui) GetLogLevelInt() int { + return int(gui.logLevel) +} + func (gui *Gui) Println(v ...interface{}) { gui.printLog(fmt.Sprintln(v...)) } -- cgit v1.2.3 From 21d86ca486a88c936a1fe71f78d76c78df36a7eb Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 16:26:14 +0100 Subject: gui stop - introduce gui.Stop() - remember state with open - stopping ethereum stack is not gui concern, moved to main - stopping mining, gui and ethereum handled via interrupt callbacks - ^C triggers exactly the same behaviour as quit via menu --- ethereal/ui/gui.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 8845f6af3..938037b90 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -37,6 +37,7 @@ type Gui struct { pub *ethpub.PEthereum logLevel ethlog.LogLevel + open bool } // Create GUI, but doesn't start it @@ -56,7 +57,7 @@ func New(ethereum *eth.Ethereum, logLevel int) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel)} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel), open: false} } func (gui *Gui) Start(assetPath string) { @@ -104,7 +105,7 @@ func (gui *Gui) Start(assetPath string) { } logger.Infoln("Starting GUI") - + gui.open = true win.Show() // only add the gui logger after window is shown otherwise slider wont be shown if addlog { @@ -113,7 +114,16 @@ func (gui *Gui) Start(assetPath string) { win.Wait() // need to silence gui logger after window closed otherwise logsystem hangs gui.SetLogLevel(ethlog.Silence) - gui.eth.Stop() + gui.open = false +} + +func (gui *Gui) Stop() { + if gui.open { + gui.SetLogLevel(ethlog.Silence) + gui.open = false + gui.win.Hide() + } + logger.Infoln("Stopped") } func (gui *Gui) ToggleMining() { -- cgit v1.2.3 From ae5ace16190d48bfe7a0364fdb0b51644518ec42 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 18:41:36 +0100 Subject: go fmt --- ethereal/ui/gui.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 83b1508e9..be7b395d8 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -6,9 +6,9 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethdb" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -35,9 +35,9 @@ type Gui struct { addr []byte - pub *ethpub.PEthereum + pub *ethpub.PEthereum logLevel ethlog.LogLevel - open bool + open bool } // Create GUI, but doesn't start it -- cgit v1.2.3 From a68bfd215f7b1859c1b14b0df59f3260b35df828 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Jun 2014 19:54:00 +0200 Subject: bump --- ethereal/ui/gui.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index be7b395d8..f861236aa 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -61,7 +61,7 @@ func New(ethereum *eth.Ethereum, logLevel int) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC14" + const version = "0.5.0 RC15" defer gui.txDb.Close() -- cgit v1.2.3 From 8aea468744e223f310da98f7478fb5b468d99563 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 20:38:26 +0100 Subject: gui changes - remove lib *EthLib, expose gui itself to initial import window - remove addr []byte instead use dynamic adress() - use ethereum.KeyManager to retrieve address and privateKey - add Session string (keyRing identifier) - add and reimplement ImportAndSetPrivKey and CreateAndSetPrivKey --- ethereal/ui/gui.go | 88 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 36 deletions(-) (limited to 'ethereal/ui/gui.go') diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index f861236aa..d8c39e837 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -28,36 +28,28 @@ type Gui struct { eth *eth.Ethereum // The public Ethereum library - lib *EthLib uiLib *UiLib txDb *ethdb.LDBDatabase - addr []byte - pub *ethpub.PEthereum logLevel ethlog.LogLevel open bool + + Session string } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum, logLevel int) *Gui { - lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} +func New(ethereum *eth.Ethereum, session string, logLevel int) *Gui { + db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { panic(err) } - // On first run we won't have any keys yet, so this would crash. - // Therefor we check if we are ready to actually start this process - var addr []byte - if ethutil.GetKeyRing().Len() != 0 { - addr = ethutil.GetKeyRing().Get(0).Address() - } - pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: ethlog.LogLevel(logLevel), open: false} + return &Gui{eth: ethereum, txDb: db, pub: pub, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false} } func (gui *Gui) Start(assetPath string) { @@ -158,12 +150,11 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { } func (gui *Gui) showKeyImport(context *qml.Context) (*qml.Window, error) { - context.SetVar("lib", gui.lib) + context.SetVar("lib", gui) component, err := gui.engine.LoadFile(gui.uiLib.AssetPath("qml/first_run.qml")) if err != nil { return nil, err } - return gui.createWindow(component), nil } @@ -175,15 +166,36 @@ func (gui *Gui) createWindow(comp qml.Object) *qml.Window { return gui.win } + +func (gui *Gui) ImportAndSetPrivKey(secret string) bool { + err := gui.eth.KeyManager().InitFromString(gui.Session, 0, secret) + if err != nil { + logger.Errorln("unable to import: ", err) + return false + } + logger.Errorln("successfully imported: ", err) + return true +} + +func (gui *Gui) CreateAndSetPrivKey() (string, string, string, string) { + err := gui.eth.KeyManager().Init(gui.Session, 0, true) + if err != nil { + logger.Errorln("unable to create key: ", err) + return "", "", "", "" + } + return gui.eth.KeyManager().KeyPair().AsStrings() +} + func (gui *Gui) setInitialBlockChain() { sBlk := gui.eth.BlockChain().LastBlockHash blk := gui.eth.BlockChain().GetBlock(sBlk) for ; blk != nil; blk = gui.eth.BlockChain().GetBlock(sBlk) { sBlk = blk.PrevHash + addr := gui.address() // Loop through all transactions to see if we missed any while being offline for _, tx := range blk.Transactions() { - if bytes.Compare(tx.Sender(), gui.addr) == 0 || bytes.Compare(tx.Recipient, gui.addr) == 0 { + if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 { if ok, _ := gui.txDb.Get(tx.Hash()); ok == nil { gui.txDb.Put(tx.Hash(), tx.RlpEncode()) } @@ -199,25 +211,26 @@ type address struct { Name, Address string } -var namereg = ethutil.FromHex("bb5f186604d057c1c5240ca2ae0f6430138ac010") +var namereg = ethutil.Hex2Bytes("bb5f186604d057c1c5240ca2ae0f6430138ac010") func (gui *Gui) loadAddressBook() { gui.win.Root().Call("clearAddress") stateObject := gui.eth.StateManager().CurrentState().GetStateObject(namereg) if stateObject != nil { stateObject.State().EachStorage(func(name string, value *ethutil.Value) { - gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Hex(value.Bytes())}) + gui.win.Root().Call("addAddress", struct{ Name, Address string }{name, ethutil.Bytes2Hex(value.Bytes())}) }) } } func (gui *Gui) readPreviousTransactions() { it := gui.txDb.Db().NewIterator(nil, nil) + addr := gui.address() for it.Next() { tx := ethchain.NewTransactionFromBytes(it.Value()) var inout string - if bytes.Compare(tx.Sender(), gui.addr) == 0 { + if bytes.Compare(tx.Sender(), addr) == 0 { inout = "send" } else { inout = "recv" @@ -269,29 +282,29 @@ func (gui *Gui) update() { state := gui.eth.StateManager().TransState() unconfirmedFunds := new(big.Int) - gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.addr).Amount))) + gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) for { select { case b := <-blockChan: block := b.Resource.(*ethchain.Block) gui.processBlock(block, false) - if bytes.Compare(block.Coinbase, gui.addr) == 0 { - gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.addr).Amount, nil) + if bytes.Compare(block.Coinbase, gui.address()) == 0 { + gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, nil) } case txMsg := <-txChan: tx := txMsg.Resource.(*ethchain.Transaction) if txMsg.Event == "newTx:pre" { - object := state.GetAccount(gui.addr) + object := state.GetAccount(gui.address()) - if bytes.Compare(tx.Sender(), gui.addr) == 0 { + if bytes.Compare(tx.Sender(), gui.address()) == 0 { gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) - } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { + } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) @@ -300,10 +313,10 @@ func (gui *Gui) update() { gui.setWalletValue(object.Amount, unconfirmedFunds) } else { - object := state.GetAccount(gui.addr) - if bytes.Compare(tx.Sender(), gui.addr) == 0 { + object := state.GetAccount(gui.address()) + if bytes.Compare(tx.Sender(), gui.address()) == 0 { object.SubAmount(tx.Value) - } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { + } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { object.AddAmount(tx.Value) } @@ -330,22 +343,25 @@ func (gui *Gui) setPeerInfo() { } } +func (gui *Gui) privateKey() string { + return ethutil.Bytes2Hex(gui.eth.KeyManager().PrivateKey()) +} + +func (gui *Gui) address() []byte { + return gui.eth.KeyManager().Address() +} + func (gui *Gui) RegisterName(name string) { - keyPair := ethutil.GetKeyRing().Get(0) name = fmt.Sprintf("\"%s\"\n1", name) - gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), "namereg", "1000", "1000000", "150", name) + gui.pub.Transact(gui.privateKey(), "namereg", "1000", "1000000", "150", name) } func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.GetKeyRing().Get(0) - - return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) + return gui.pub.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data) } func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { - keyPair := ethutil.GetKeyRing().Get(0) - - return gui.pub.Transact(ethutil.Hex(keyPair.PrivateKey), recipient, value, gas, gasPrice, data) + return gui.pub.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data) } func (gui *Gui) ChangeClientId(id string) { -- cgit v1.2.3