From a3c482351114404a4568f4b3f4503182402dc6fd Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 3 Jul 2014 17:35:48 +0100 Subject: [PATCH 1/5] Gui saves custom client id and loglevel - gui NewWindow takes SimpleClientIdentity as argument - gui NewWindow takes ethutil.ConfigManager as argument to manage flag persistence - gui now saves loglevel and custom client id via config.Save - rename custom client id methods consistently also in wallet.qml - clientIdentifier now set in main wrappers - version handled within wrapper - modify InitConfig now returning *ethutil.ConfigManager (passed to gui) --- ethereal/assets/qml/wallet.qml | 4 ++-- ethereal/gui.go | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index 628d9f96a6..4b252f2009 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -248,9 +248,9 @@ ApplicationWindow { text: "Client ID" } TextField { - text: eth.clientId() + text: eth.getCustomIdentifier() onTextChanged: { - eth.changeClientId(text) + eth.setCustomIdentifier(text) } } } diff --git a/ethereal/gui.go b/ethereal/gui.go index 1719d41b2a..9f28045f86 100644 --- a/ethereal/gui.go +++ b/ethereal/gui.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethwire" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -36,11 +37,13 @@ type Gui struct { logLevel ethlog.LogLevel open bool - Session string + Session string + clientIdentity *ethwire.SimpleClientIdentity + config *ethutil.ConfigManager } // Create GUI, but doesn't start it -func NewWindow(ethereum *eth.Ethereum, session string, logLevel int) *Gui { +func NewWindow(ethereum *eth.Ethereum, config *ethutil.ConfigManager, clientIdentity *ethwire.SimpleClientIdentity, session string, logLevel int) *Gui { db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { panic(err) @@ -48,11 +51,10 @@ func NewWindow(ethereum *eth.Ethereum, session string, logLevel int) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, txDb: db, pub: pub, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false} + return &Gui{eth: ethereum, txDb: db, pub: pub, logLevel: ethlog.LogLevel(logLevel), Session: session, open: false, clientIdentity: clientIdentity, config: config} } func (gui *Gui) Start(assetPath string) { - const version = "0.5.16" defer gui.txDb.Close() @@ -65,8 +67,6 @@ func (gui *Gui) Start(assetPath string) { Init: func(p *ethpub.KeyVal, obj qml.Object) { p.Key = ""; p.Value = "" }, }}) - ethutil.Config.SetClientString("Ethereal") - // Create a new QML engine gui.engine = qml.NewEngine() context := gui.engine.Context() @@ -103,14 +103,14 @@ func (gui *Gui) Start(assetPath string) { ethlog.AddLogSystem(gui) } win.Wait() - // need to silence gui logger after window closed otherwise logsystem hangs - gui.SetLogLevel(ethlog.Silence) + // need to silence gui logger after window closed otherwise logsystem hangs (but do not save loglevel) + gui.logLevel = ethlog.Silence gui.open = false } func (gui *Gui) Stop() { if gui.open { - gui.SetLogLevel(ethlog.Silence) + gui.logLevel = ethlog.Silence gui.open = false gui.win.Hide() } @@ -369,17 +369,19 @@ func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PR return gui.pub.Transact(gui.privateKey(), recipient, value, gas, gasPrice, data) } -func (gui *Gui) ChangeClientId(id string) { - ethutil.Config.SetIdentifier(id) +func (gui *Gui) SetCustomIdentifier(customIdentifier string) { + gui.clientIdentity.SetCustomIdentifier(customIdentifier) + gui.config.Save("id", customIdentifier) } -func (gui *Gui) ClientId() string { - return ethutil.Config.Identifier +func (gui *Gui) GetCustomIdentifier() string { + return gui.clientIdentity.GetCustomIdentifier() } // functions that allow Gui to implement interface ethlog.LogSystem func (gui *Gui) SetLogLevel(level ethlog.LogLevel) { gui.logLevel = level + gui.config.Save("loglevel", level) } func (gui *Gui) GetLogLevel() ethlog.LogLevel { From 9de30d96f0362bc885d75a27bbd9c3d02af2d983 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 3 Jul 2014 17:36:24 +0100 Subject: [PATCH 2/5] Modify main wrappers - clientIdentifier now set in main wrappers - version handled within wrapper - modify InitConfig now returning *ethutil.ConfigManager (passed to gui) - added NewClientIdentity returning *ethwire.SimpleClientIdentiy (passed to ethereum) --- ethereal/main.go | 14 +++++++++++--- ethereum/main.go | 11 +++++++++-- utils/cmd.go | 15 ++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ethereal/main.go b/ethereal/main.go index f3f1d31400..645e8f2ce5 100644 --- a/ethereal/main.go +++ b/ethereal/main.go @@ -8,6 +8,11 @@ import ( "runtime" ) +const ( + ClientIdentifier = "Ethereal" + Version = "0.5.16" +) + func main() { // Leave QT on top at ALL times. Qt Needs to be initialized from the main thread qml.Init(nil) @@ -23,7 +28,8 @@ func main() { // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line - utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") + + config := utils.InitConfig(ConfigFile, Datadir, "ETH") utils.InitDataDir(Datadir) @@ -36,7 +42,9 @@ func main() { // create, import, export keys utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) - ethereum := utils.NewEthereum(db, keyManager, UseUPnP, OutboundPort, MaxPeer) + clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) + + ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) if ShowGenesis { utils.ShowGenesis(ethereum) @@ -46,7 +54,7 @@ func main() { utils.StartRpc(ethereum, RpcPort) } - gui := NewWindow(ethereum, KeyRing, LogLevel) + gui := NewWindow(ethereum, config, clientIdentity, KeyRing, LogLevel) utils.RegisterInterrupt(func(os.Signal) { gui.Stop() diff --git a/ethereum/main.go b/ethereum/main.go index 1531871cb5..e4d73d4942 100644 --- a/ethereum/main.go +++ b/ethereum/main.go @@ -6,6 +6,11 @@ import ( "runtime" ) +const ( + ClientIdentifier = "Ethereum(G)" + Version = "0.5.16" +) + var logger = ethlog.NewLogger("CLI") func main() { @@ -15,7 +20,7 @@ func main() { // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line - utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH") + utils.InitConfig(ConfigFile, Datadir, "ETH") utils.InitDataDir(Datadir) @@ -28,7 +33,9 @@ func main() { // create, import, export keys utils.KeyTasks(keyManager, KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive) - ethereum := utils.NewEthereum(db, keyManager, UseUPnP, OutboundPort, MaxPeer) + clientIdentity := utils.NewClientIdentity(ClientIdentifier, Version, Identifier) + + ethereum := utils.NewEthereum(db, clientIdentity, keyManager, UseUPnP, OutboundPort, MaxPeer) if ShowGenesis { utils.ShowGenesis(ethereum) diff --git a/utils/cmd.go b/utils/cmd.go index e10addf6c0..889726b049 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethrpc" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethwire" "io" "log" "os" @@ -98,9 +99,9 @@ func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string) } } -func InitConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) { +func InitConfig(ConfigFile string, Datadir string, EnvPrefix string) *ethutil.ConfigManager { InitDataDir(Datadir) - ethutil.ReadConfig(ConfigFile, Datadir, Identifier, EnvPrefix) + return ethutil.ReadConfig(ConfigFile, Datadir, EnvPrefix) } func exit(err error) { @@ -122,8 +123,12 @@ func NewDatabase() ethutil.Database { return db } -func NewEthereum(db ethutil.Database, keyManager *ethcrypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum { - ethereum, err := eth.New(db, keyManager, eth.CapDefault, usePnp) +func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity { + return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier) +} + +func NewEthereum(db ethutil.Database, clientIdentity ethwire.ClientIdentity, keyManager *ethcrypto.KeyManager, usePnp bool, OutboundPort string, MaxPeer int) *eth.Ethereum { + ethereum, err := eth.New(db, clientIdentity, keyManager, eth.CapDefault, usePnp) if err != nil { logger.Fatalln("eth start err:", err) } @@ -133,7 +138,7 @@ func NewEthereum(db ethutil.Database, keyManager *ethcrypto.KeyManager, usePnp b } func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) { - logger.Infof("Starting Ethereum v%s", ethutil.Config.Ver) + logger.Infof("Starting %s", ethereum.ClientIdentity()) ethereum.Start(UseSeed) RegisterInterrupt(func(sig os.Signal) { ethereum.Stop() From ca395306e3997c1f2fd2aa2e780518eb2e2f1845 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 4 Jul 2014 13:04:25 +0200 Subject: [PATCH 3/5] Updated debugger * Compile on the go. Continues compilation in order to update the ASM view * Short cuts commands --- ethereal/assets/debugger/debugger.qml | 70 +++++++++++++++++++++++++-- ethereal/debugger.go | 39 +++++++++------ 2 files changed, 91 insertions(+), 18 deletions(-) diff --git a/ethereal/assets/debugger/debugger.qml b/ethereal/assets/debugger/debugger.qml index b93308b3e2..579e8be3ab 100644 --- a/ethereal/assets/debugger/debugger.qml +++ b/ethereal/assets/debugger/debugger.qml @@ -7,6 +7,7 @@ import QtQuick.Controls.Styles 1.1 import Ethereum 1.0 ApplicationWindow { + id: win visible: false title: "IceCREAM" minimumWidth: 1280 @@ -17,6 +18,10 @@ ApplicationWindow { property alias codeText: codeEditor.text property alias dataText: rawDataField.text + onClosing: { + compileTimer.stop() + } + MenuBar { Menu { title: "Debugger" @@ -34,12 +39,44 @@ ApplicationWindow { MenuItem { text: "Continue" - shortcut: "Ctrl+c" + shortcut: "Ctrl+g" onTriggered: dbg.continue() } + MenuItem { + text: "Command" + shortcut: "Ctrl+l" + onTriggered: { + dbgCommand.focus = true + } + } + MenuItem { + text: "Focus code" + shortcut: "Ctrl+1" + onTriggered: { + codeEditor.focus = true + } + } + MenuItem { + text: "Focus data" + shortcut: "Ctrl+2" + onTriggered: { + rawDataField.focus = true + } + } + + /* + MenuItem { + text: "Close window" + shortcut: "Ctrl+w" + onTriggered: { + win.close() + } + } + */ } } + SplitView { anchors.fill: parent property var asmModel: ListModel { @@ -73,6 +110,15 @@ ApplicationWindow { anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: settings.left + focus: true + + Timer { + id: compileTimer + interval: 500 ; running: true ; repeat: true + onTriggered: { + dbg.compile(codeEditor.text) + } + } } Column { @@ -185,7 +231,7 @@ ApplicationWindow { } height: parent.height width: parent.width - TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width } + TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width -1 } model: logModel } } @@ -207,7 +253,7 @@ ApplicationWindow { y: 1 x: asmTableView.width width: 500 - placeholderText: "Debugger command (help for help)" + placeholderText: "Debugger (type 'help')" Keys.onReturnPressed: { exec() } @@ -225,6 +271,7 @@ ApplicationWindow { } toolBar: ToolBar { + height: 30 RowLayout { spacing: 5 @@ -254,6 +301,23 @@ ApplicationWindow { text: "Continue" } } + + + ComboBox { + id: snippets + anchors.right: parent.right + model: ListModel { + ListElement { text: "Snippets" ; value: "" } + ListElement { text: "Call Contract" ; value: "var[2] in;\nvar ret;\n\nin[0] = \"arg1\"\nin[1] = 0xdeadbeef\n\nvar success = call(0x0c542ddea93dae0c2fcb2cf175f03ad80d6be9a0, 0, 7000, in, ret)\n\nreturn ret" } + } + onCurrentIndexChanged: { + if(currentIndex != 0) { + var code = snippets.model.get(currentIndex).value; + codeEditor.insert(codeEditor.cursorPosition, code) + } + } + } + } function debugCurrent() { diff --git a/ethereal/debugger.go b/ethereal/debugger.go index 8eab04b4d6..d1516c5d51 100644 --- a/ethereal/debugger.go +++ b/ethereal/debugger.go @@ -52,13 +52,27 @@ func (self *DebuggerWindow) SetCode(code string) { func (self *DebuggerWindow) SetData(data string) { self.win.Set("dataText", data) } -func (self *DebuggerWindow) SetAsm(data string) { - dis := ethchain.Disassemble(ethutil.Hex2Bytes(data)) +func (self *DebuggerWindow) SetAsm(data []byte) { + self.win.Root().Call("clearAsm") + + dis := ethchain.Disassemble(data) for _, str := range dis { self.win.Root().Call("setAsm", str) } } +func (self *DebuggerWindow) Compile(code string) { + var err error + script := ethutil.StringToByteFunc(code, func(s string) (ret []byte) { + ret, err = ethutil.Compile(s) + return + }) + + if err == nil { + self.SetAsm(script) + } +} + func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { if !self.Db.done { self.Db.Q <- true @@ -91,27 +105,21 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data return } - dis := ethchain.Disassemble(script) - self.win.Root().Call("clearAsm") - - for _, str := range dis { - self.win.Root().Call("setAsm", str) - } + self.SetAsm(script) var ( gas = ethutil.Big(gasStr) gasPrice = ethutil.Big(gasPriceStr) value = ethutil.Big(valueStr) // Contract addr as test address - keyPair = self.lib.eth.KeyManager().KeyPair() - callerTx = ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script) + keyPair = self.lib.eth.KeyManager().KeyPair() ) - callerTx.Sign(keyPair.PrivateKey) - state := self.lib.eth.BlockChain().CurrentBlock.State() + state := self.lib.eth.StateManager().TransState() account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) - contract := ethchain.MakeContract(callerTx, state) + contract := ethchain.NewStateObject([]byte{0}) contract.Amount = value + callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice) block := self.lib.eth.BlockChain().CurrentBlock @@ -179,8 +187,9 @@ func (self *DebuggerWindow) ExecCommand(command string) { cmd := strings.Split(command, " ") switch cmd[0] { case "help": - self.Logln("Debgger commands:") - self.Logln("break, bp Set breakpoint") + self.Logln("Debugger commands:") + self.Logln("break, bp Set breakpoint on instruction") + self.Logln("clear [break, bp] Clears previous set sub-command(s)") case "break", "bp": if len(cmd) > 1 { lineNo, err := strconv.Atoi(cmd[1]) From de183e80db6ce380c8030f00c24479ed0290878b Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 4 Jul 2014 13:42:43 +0200 Subject: [PATCH 4/5] Silent compiler errors when continues compiling --- ethereal/debugger.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereal/debugger.go b/ethereal/debugger.go index d1516c5d51..f649857b2b 100644 --- a/ethereal/debugger.go +++ b/ethereal/debugger.go @@ -64,7 +64,7 @@ func (self *DebuggerWindow) SetAsm(data []byte) { func (self *DebuggerWindow) Compile(code string) { var err error script := ethutil.StringToByteFunc(code, func(s string) (ret []byte) { - ret, err = ethutil.Compile(s) + ret, err = ethutil.Compile(s, true) return }) @@ -95,7 +95,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data var err error script := ethutil.StringToByteFunc(scriptStr, func(s string) (ret []byte) { - ret, err = ethutil.Compile(s) + ret, err = ethutil.Compile(s, false) return }) From 9e38ca555dccd6b9a4a3fa0eb9eb749d2dc3c82c Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 4 Jul 2014 15:31:13 +0200 Subject: [PATCH 5/5] Visual updates --- ethereal/assets/debugger/debugger.qml | 12 +----------- ethereal/debugger.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ethereal/assets/debugger/debugger.qml b/ethereal/assets/debugger/debugger.qml index 579e8be3ab..f204647c8e 100644 --- a/ethereal/assets/debugger/debugger.qml +++ b/ethereal/assets/debugger/debugger.qml @@ -231,7 +231,7 @@ ApplicationWindow { } height: parent.height width: parent.width - TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width -1 } + TableViewColumn{ id: message ; role: "message" ; title: "log" ; width: logTableView.width - 2 } model: logModel } } @@ -258,16 +258,6 @@ ApplicationWindow { exec() } } - - Button { - anchors { - left: dbgCommand.right - } - text: "Exec" - onClicked: { - exec() - } - } } toolBar: ToolBar { diff --git a/ethereal/debugger.go b/ethereal/debugger.go index f649857b2b..89e0f36eb1 100644 --- a/ethereal/debugger.go +++ b/ethereal/debugger.go @@ -73,6 +73,10 @@ func (self *DebuggerWindow) Compile(code string) { } } +func (self *DebuggerWindow) ClearLog() { + self.win.Root().Call("clearLog") +} + func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { if !self.Db.done { self.Db.Q <- true @@ -188,8 +192,8 @@ func (self *DebuggerWindow) ExecCommand(command string) { switch cmd[0] { case "help": self.Logln("Debugger commands:") - self.Logln("break, bp Set breakpoint on instruction") - self.Logln("clear [break, bp] Clears previous set sub-command(s)") + self.Logln("break, bp Set breakpoint on instruction") + self.Logln("clear [log, break, bp] Clears previous set sub-command(s)") case "break", "bp": if len(cmd) > 1 { lineNo, err := strconv.Atoi(cmd[1]) @@ -211,6 +215,8 @@ func (self *DebuggerWindow) ExecCommand(command string) { self.vm.BreakPoints = nil self.Logln("Breakpoints cleared") + case "log": + self.ClearLog() default: self.Logf("clear '%s' is not valid", cmd[1]) }