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 +++++++++++++++++++++++++++++++++++++++++++++++++ ethereal/ui/library.go | 60 ++++++++++++++ ethereal/ui/ui_lib.go | 76 +++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100644 ethereal/ui/gui.go create mode 100644 ethereal/ui/library.go create mode 100644 ethereal/ui/ui_lib.go (limited to 'ethereal/ui') 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) + } +} diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go new file mode 100644 index 000000000..05fffd579 --- /dev/null +++ b/ethereal/ui/library.go @@ -0,0 +1,60 @@ +package ethui + +import ( + "encoding/hex" + "fmt" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethutil" + "strings" +) + +type EthLib struct { + stateManager *ethchain.StateManager + blockChain *ethchain.BlockChain + txPool *ethchain.TxPool +} + +func (lib *EthLib) CreateTx(receiver, a, data string) string { + var hash []byte + if len(receiver) == 0 { + hash = ethchain.ContractAddr + } else { + var err error + hash, err = hex.DecodeString(receiver) + if err != nil { + return err.Error() + } + } + + k, _ := ethutil.Config.Db.Get([]byte("KeyRing")) + keyPair := ethutil.NewKeyFromBytes(k) + + amount := ethutil.Big(a) + code := ethchain.Compile(strings.Split(data, "\n")) + tx := ethchain.NewTransaction(hash, amount, code) + tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce + + tx.Sign(keyPair.PrivateKey) + + lib.txPool.QueueTransaction(tx) + + if len(receiver) == 0 { + ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) + } else { + ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) + } + + return ethutil.Hex(tx.Hash()) +} + +func (lib *EthLib) GetBlock(hexHash string) *Block { + hash, err := hex.DecodeString(hexHash) + if err != nil { + return nil + } + + block := lib.blockChain.GetBlock(hash) + fmt.Println(block) + + return &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go new file mode 100644 index 000000000..3997191fa --- /dev/null +++ b/ethereal/ui/ui_lib.go @@ -0,0 +1,76 @@ +package ethui + +import ( + "bitbucket.org/kardianos/osext" + "github.com/ethereum/eth-go" + "github.com/ethereum/eth-go/ethutil" + "github.com/niemeyer/qml" + "os" + "path" + "path/filepath" + "runtime" +) + +// UI Library that has some basic functionality exposed +type UiLib struct { + engine *qml.Engine + eth *eth.Ethereum + connected bool +} + +// Opens a QML file (external application) +func (ui *UiLib) Open(path string) { + component, err := ui.engine.LoadFile(path[7:]) + if err != nil { + ethutil.Config.Log.Debugln(err) + } + win := component.CreateWindow(nil) + + go func() { + win.Show() + win.Wait() + }() +} + +func (ui *UiLib) Connect(button qml.Object) { + if !ui.connected { + ui.eth.Start() + ui.connected = true + button.Set("enabled", false) + } +} + +func (ui *UiLib) ConnectToPeer(addr string) { + ui.eth.ConnectToPeer(addr) +} + +func (ui *UiLib) AssetPath(p string) string { + return AssetPath(p) +} + +func AssetPath(p string) string { + var base string + + // If the current working directory is the go-ethereum dir + // assume a debug build and use the source directory as + // asset directory. + pwd, _ := os.Getwd() + if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") { + base = path.Join(pwd, "assets") + } else { + switch runtime.GOOS { + case "darwin": + // Get Binary Directory + exedir, _ := osext.ExecutableFolder() + base = filepath.Join(exedir, "../Resources") + case "linux": + base = "/usr/share/ethereal" + case "window": + fallthrough + default: + base = "." + } + } + + return path.Join(base, p) +} -- 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 +++++++---- ethereal/ui/ui_lib.go | 14 +++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'ethereal/ui') 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) diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 3997191fa..4441a7238 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -16,6 +16,14 @@ type UiLib struct { engine *qml.Engine eth *eth.Ethereum connected bool + assetPath string +} + +func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { + if assetPath == "" { + assetPath = DefaultAssetPath() + } + return &UiLib{engine: engine, eth: eth, assetPath: assetPath} } // Opens a QML file (external application) @@ -45,10 +53,10 @@ func (ui *UiLib) ConnectToPeer(addr string) { } func (ui *UiLib) AssetPath(p string) string { - return AssetPath(p) + return path.Join(ui.assetPath, p) } -func AssetPath(p string) string { +func DefaultAssetPath() string { var base string // If the current working directory is the go-ethereum dir @@ -72,5 +80,5 @@ func AssetPath(p string) string { } } - return path.Join(base, p) + return base } -- cgit v1.2.3 From c5215fd4fb9de7594fdb812f8f9e4c471ee8d003 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 27 Mar 2014 19:41:42 +0100 Subject: Added gas and gas price. * library's `createTx` method changed so it accepts a gas price * dev console accepts code as well as the library --- ethereal/ui/library.go | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 05fffd579..bd67f3c20 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/obscuren/mutan" "strings" ) @@ -14,6 +15,50 @@ type EthLib struct { txPool *ethchain.TxPool } +func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) string { + var hash []byte + var contractCreation bool + if len(recipient) == 0 { + contractCreation = true + } else { + var err error + hash, err = hex.DecodeString(recipient) + if err != nil { + return err.Error() + } + } + + keyPair := ethutil.Config.Db.GetKeys()[0] + value := ethutil.Big(valueStr) + gas := ethutil.Big(valueStr) + gasPrice := ethutil.Big(gasPriceStr) + var tx *ethchain.Transaction + // Compile and assemble the given data + if contractCreation { + asm, err := mutan.NewCompiler().Compile(strings.NewReader(data)) + if err != nil { + return err.Error() + } + + code := ethutil.Assemble(asm) + tx = ethchain.NewContractCreationTx(value, gasPrice, code) + } else { + tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) + } + tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce + tx.Sign(keyPair.PrivateKey) + lib.txPool.QueueTransaction(tx) + + if contractCreation { + ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) + } else { + ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) + } + + return ethutil.Hex(tx.Hash()) +} + +/* func (lib *EthLib) CreateTx(receiver, a, data string) string { var hash []byte if len(receiver) == 0 { @@ -31,7 +76,7 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string { amount := ethutil.Big(a) code := ethchain.Compile(strings.Split(data, "\n")) - tx := ethchain.NewTransaction(hash, amount, code) + tx := ethchain.NewTx(hash, amount, code) tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce tx.Sign(keyPair.PrivateKey) @@ -46,6 +91,7 @@ func (lib *EthLib) CreateTx(receiver, a, data string) string { return ethutil.Hex(tx.Hash()) } +*/ func (lib *EthLib) GetBlock(hexHash string) *Block { hash, err := hex.DecodeString(hexHash) -- cgit v1.2.3 From ebbc5e7cb8b3886c8557f9f8623113f52f7f5e4a Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 30 Mar 2014 22:03:29 +0200 Subject: Updated to new mutan api --- ethereal/ui/library.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index bd67f3c20..692ec454c 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -35,7 +35,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin var tx *ethchain.Transaction // Compile and assemble the given data if contractCreation { - asm, err := mutan.NewCompiler().Compile(strings.NewReader(data)) + asm, err := mutan.Compile(strings.NewReader(data), false) if err != nil { return err.Error() } -- cgit v1.2.3 From 97b98b1250890977ea622af378fe864e4620e313 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 31 Mar 2014 00:22:50 +0200 Subject: Fixed an issue with sending gas to a contract --- ethereal/ui/library.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 692ec454c..6f8cb6f65 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -30,7 +30,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin keyPair := ethutil.Config.Db.GetKeys()[0] value := ethutil.Big(valueStr) - gas := ethutil.Big(valueStr) + gas := ethutil.Big(gasStr) gasPrice := ethutil.Big(gasPriceStr) var tx *ethchain.Transaction // Compile and assemble the given data @@ -40,7 +40,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin return err.Error() } - code := ethutil.Assemble(asm) + code := ethutil.Assemble(asm...) tx = ethchain.NewContractCreationTx(value, gasPrice, code) } else { tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) -- cgit v1.2.3 From 5660d598df3d86f892975fcf9628133529598221 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 1 Apr 2014 10:40:34 +0200 Subject: Added tx output --- ethereal/ui/library.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 6f8cb6f65..7a8939bf1 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -15,7 +15,7 @@ type EthLib struct { txPool *ethchain.TxPool } -func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) string { +func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { var hash []byte var contractCreation bool if len(recipient) == 0 { @@ -24,7 +24,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin var err error hash, err = hex.DecodeString(recipient) if err != nil { - return err.Error() + return "", err } } @@ -37,7 +37,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin if contractCreation { asm, err := mutan.Compile(strings.NewReader(data), false) if err != nil { - return err.Error() + return "", err } code := ethutil.Assemble(asm...) @@ -55,7 +55,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) } - return ethutil.Hex(tx.Hash()) + return ethutil.Hex(tx.Hash()), nil } /* -- cgit v1.2.3 From 1e94cb5286067da80c3227861a836c611f01e32b Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 9 Apr 2014 16:01:11 +0200 Subject: Nonce handling --- ethereal/ui/library.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 7a8939bf1..9a7469426 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -45,7 +45,9 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin } else { tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) } - tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce + acc := lib.stateManager.GetAddrState(keyPair.Address()) + tx.Nonce = acc.Nonce + //acc.Nonce++ tx.Sign(keyPair.PrivateKey) lib.txPool.QueueTransaction(tx) -- 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 +++++++++++++++++++++++++--------- ethereal/ui/library.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) (limited to 'ethereal/ui') 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() diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 9a7469426..b8ecf3b14 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -5,7 +5,9 @@ import ( "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/mutan" + "github.com/obscuren/secp256k1-go" "strings" ) @@ -15,6 +17,32 @@ type EthLib struct { txPool *ethchain.TxPool } +func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool { + fmt.Println(privKey) + mnemonic := strings.Split(privKey, " ") + if len(mnemonic) == 24 { + fmt.Println("Got mnemonic key, importing.") + key := ethutil.MnemonicDecode(mnemonic) + utils.ImportPrivateKey(key) + } else if len(mnemonic) == 1 { + fmt.Println("Got hex key, importing.") + utils.ImportPrivateKey(privKey) + } else { + fmt.Println("Did not recognise format, exiting.") + return false + } + return true +} + +func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { + pub, prv := secp256k1.GenerateKeyPair() + pair := ðutil.Key{PrivateKey: prv, PublicKey: pub} + ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode()) + mne := ethutil.MnemonicEncode(ethutil.Hex(prv)) + mnemonicString := strings.Join(mne, " ") + return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) +} + func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { var hash []byte var contractCreation bool -- 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 ++-- ethereal/ui/library.go | 37 +---------------------------- ethereal/ui/ui_lib.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 38 deletions(-) (limited to 'ethereal/ui') 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 diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 9a7469426..13400a2a0 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -43,7 +43,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin code := ethutil.Assemble(asm...) tx = ethchain.NewContractCreationTx(value, gasPrice, code) } else { - tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) + tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) } acc := lib.stateManager.GetAddrState(keyPair.Address()) tx.Nonce = acc.Nonce @@ -60,41 +60,6 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin return ethutil.Hex(tx.Hash()), nil } -/* -func (lib *EthLib) CreateTx(receiver, a, data string) string { - var hash []byte - if len(receiver) == 0 { - hash = ethchain.ContractAddr - } else { - var err error - hash, err = hex.DecodeString(receiver) - if err != nil { - return err.Error() - } - } - - k, _ := ethutil.Config.Db.Get([]byte("KeyRing")) - keyPair := ethutil.NewKeyFromBytes(k) - - amount := ethutil.Big(a) - code := ethchain.Compile(strings.Split(data, "\n")) - tx := ethchain.NewTx(hash, amount, code) - tx.Nonce = lib.stateManager.GetAddrState(keyPair.Address()).Nonce - - tx.Sign(keyPair.PrivateKey) - - lib.txPool.QueueTransaction(tx) - - if len(receiver) == 0 { - ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) - } else { - ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) - } - - return ethutil.Hex(tx.Hash()) -} -*/ - func (lib *EthLib) GetBlock(hexHash string) *Block { hash, err := hex.DecodeString(hexHash) if err != nil { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 5c3c98fb9..adba177d0 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -2,13 +2,18 @@ package ethui import ( "bitbucket.org/kardianos/osext" + "fmt" "github.com/ethereum/eth-go" + "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/niemeyer/qml" + "github.com/obscuren/mutan" + "math/big" "os" "path" "path/filepath" "runtime" + "strings" ) // UI Library that has some basic functionality exposed @@ -17,6 +22,8 @@ type UiLib struct { eth *eth.Ethereum connected bool assetPath string + // The main application window + win *qml.Window } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { @@ -81,3 +88,59 @@ func DefaultAssetPath() string { return base } + +type memAddr struct { + Num string + Value string +} + +func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { + state := ui.eth.BlockChain().CurrentBlock.State() + + asm, err := mutan.Compile(strings.NewReader(data), false) + if err != nil { + fmt.Println(err) + } + + callerScript := ethutil.Assemble(asm...) + dis := ethchain.Disassemble(callerScript) + ui.win.Root().Call("clearAsm") + for _, str := range dis { + ui.win.Root().Call("setAsm", str) + } + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript) + + // Contract addr as test address + keyPair := ethutil.Config.Db.GetKeys()[0] + account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Account + c := ethchain.MakeContract(callerTx, state) + callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), new(big.Int)) + + block := ui.eth.BlockChain().CurrentBlock + vm := ethchain.NewVm(state, ethchain.RuntimeVars{ + Origin: account.Address(), + BlockNumber: block.BlockInfo().Number, + PrevHash: block.PrevHash, + Coinbase: block.Coinbase, + Time: block.Time, + Diff: block.Difficulty, + TxData: nil, + }) + callerClosure.Call(vm, nil, func(op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { + ui.win.Root().Call("clearMem") + ui.win.Root().Call("clearStack") + + addr := 0 + for i := 0; i+32 <= mem.Len(); i += 32 { + ui.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) + addr++ + } + + for _, val := range stack.Data() { + ui.win.Root().Call("setStack", val.String()) + } + }) + state.Reset() + + return "", nil +} -- cgit v1.2.3 From cf1ae41bc0bedeb5208dc00696c538c13f2183c6 Mon Sep 17 00:00:00 2001 From: Maran Date: Fri, 11 Apr 2014 13:26:14 -0400 Subject: Improved (hopefully) the send transaction tab --- ethereal/ui/library.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index b8ecf3b14..d4800bf1d 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -63,15 +63,21 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin var tx *ethchain.Transaction // Compile and assemble the given data if contractCreation { - asm, err := mutan.Compile(strings.NewReader(data), false) - if err != nil { - return "", err + asm, errors := mutan.Compile(strings.NewReader(data), false) + if len(errors) > 0 { + var errs string + for _, er := range errors { + if er != nil { + errs += er.Error() + } + } + return "", fmt.Errorf(errs) } code := ethutil.Assemble(asm...) tx = ethchain.NewContractCreationTx(value, gasPrice, code) } else { - tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, []string{}) + tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) } acc := lib.stateManager.GetAddrState(keyPair.Address()) tx.Nonce = acc.Nonce -- cgit v1.2.3 From a9a65859134b93cfe2818fdad290530822d6a7b4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 11 Apr 2014 13:36:25 -0400 Subject: Debugger --- ethereal/ui/ui_lib.go | 56 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index adba177d0..fde2697b8 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -94,7 +94,40 @@ type memAddr struct { Value string } -func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { +type Debugger struct { + ui *UiLib + next chan bool +} + +func (d *Debugger) halting(op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { + d.ui.win.Root().Call("clearMem") + d.ui.win.Root().Call("clearStack") + + addr := 0 + for i := 0; i+32 <= mem.Len(); i += 32 { + d.ui.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) + addr++ + } + + for _, val := range stack.Data() { + d.ui.win.Root().Call("setStack", val.String()) + } + +out: + for { + select { + case <-d.next: + break out + default: + } + } +} + +func (d *Debugger) Next() { + d.next <- true +} + +func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { state := ui.eth.BlockChain().CurrentBlock.State() asm, err := mutan.Compile(strings.NewReader(data), false) @@ -126,21 +159,12 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) Diff: block.Difficulty, TxData: nil, }) - callerClosure.Call(vm, nil, func(op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { - ui.win.Root().Call("clearMem") - ui.win.Root().Call("clearStack") - - addr := 0 - for i := 0; i+32 <= mem.Len(); i += 32 { - ui.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) - addr++ - } - for _, val := range stack.Data() { - ui.win.Root().Call("setStack", val.String()) - } - }) - state.Reset() + db := &Debugger{ui, make(chan bool)} + ui.engine.Context().SetVar("db", db) + go func() { + callerClosure.Call(vm, nil, db.halting) - return "", nil + state.Reset() + }() } -- 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') 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 ++- ethereal/ui/library.go | 1 + ethereal/ui/ui_lib.go | 89 ++++++++++++++++++++++++++------------------------ 3 files changed, 51 insertions(+), 43 deletions(-) (limited to 'ethereal/ui') 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 diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 08f99e7db..42aebcd87 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -15,6 +15,7 @@ type EthLib struct { stateManager *ethchain.StateManager blockChain *ethchain.BlockChain txPool *ethchain.TxPool + Db *Debugger } func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index fde2697b8..86855290f 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -16,6 +16,11 @@ import ( "strings" ) +type memAddr struct { + Num string + Value string +} + // UI Library that has some basic functionality exposed type UiLib struct { engine *qml.Engine @@ -24,6 +29,7 @@ type UiLib struct { assetPath string // The main application window win *qml.Window + Db *Debugger } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { @@ -89,48 +95,11 @@ func DefaultAssetPath() string { return base } -type memAddr struct { - Num string - Value string -} - -type Debugger struct { - ui *UiLib - next chan bool -} - -func (d *Debugger) halting(op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { - d.ui.win.Root().Call("clearMem") - d.ui.win.Root().Call("clearStack") - - addr := 0 - for i := 0; i+32 <= mem.Len(); i += 32 { - d.ui.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) - addr++ - } - - for _, val := range stack.Data() { - d.ui.win.Root().Call("setStack", val.String()) - } - -out: - for { - select { - case <-d.next: - break out - default: - } - } -} - -func (d *Debugger) Next() { - d.next <- true -} - func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { state := ui.eth.BlockChain().CurrentBlock.State() - asm, err := mutan.Compile(strings.NewReader(data), false) + mainInput, _ := ethutil.PreProcess(data) + asm, err := mutan.Compile(strings.NewReader(mainInput), false) if err != nil { fmt.Println(err) } @@ -160,11 +129,47 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) TxData: nil, }) - db := &Debugger{ui, make(chan bool)} - ui.engine.Context().SetVar("db", db) go func() { - callerClosure.Call(vm, nil, db.halting) + callerClosure.Call(vm, nil, ui.Db.halting) state.Reset() }() } + +func (ui *UiLib) Next() { + ui.Db.Next() +} + +type Debugger struct { + win *qml.Window + N chan bool +} + +func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { + d.win.Root().Call("setInstruction", pc) + d.win.Root().Call("clearMem") + d.win.Root().Call("clearStack") + + addr := 0 + for i := 0; i+32 <= mem.Len(); i += 32 { + d.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) + addr++ + } + + for _, val := range stack.Data() { + d.win.Root().Call("setStack", val.String()) + } + +out: + for { + select { + case <-d.N: + break out + default: + } + } +} + +func (d *Debugger) Next() { + d.N <- true +} -- cgit v1.2.3 From 91c75c9305e7554c21e84ed1a07ec0e750bb775a Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 14 Apr 2014 17:08:15 -0400 Subject: Adding log messages to debug panel --- ethereal/ui/ui_lib.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 86855290f..b2552cdce 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -102,6 +102,9 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) asm, err := mutan.Compile(strings.NewReader(mainInput), false) if err != nil { fmt.Println(err) + for _, e := range err { + ui.win.Root().Call("addDebugMessage", e.Error()) + } } callerScript := ethutil.Assemble(asm...) -- cgit v1.2.3 From 7cb065489c3d664f5924afad4f72e2a0a3a5c800 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 15 Apr 2014 16:13:04 -0400 Subject: added init and main functions to script --- ethereal/ui/library.go | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 42aebcd87..76032f400 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -44,6 +44,22 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) } +// General compiler and preprocessor function +func compile(script string) ([]byte, error) { + asm, errors := mutan.Compile(strings.NewReader(script), false) + if len(errors) > 0 { + var errs string + for _, er := range errors { + if er != nil { + errs += er.Error() + } + } + return nil, fmt.Errorf("%v", errs) + } + + return ethutil.Assemble(asm...), nil +} + func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { var hash []byte var contractCreation bool @@ -64,19 +80,19 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin var tx *ethchain.Transaction // Compile and assemble the given data if contractCreation { - asm, errors := mutan.Compile(strings.NewReader(data), false) - if len(errors) > 0 { - var errs string - for _, er := range errors { - if er != nil { - errs += er.Error() - } - } - return "", fmt.Errorf(errs) + mainInput, initInput := ethutil.PreProcess(data) + mainScript, err := compile(mainInput) + if err != nil { + return "", err + } + initScript, err := compile(initInput) + if err != nil { + return "", err } - code := ethutil.Assemble(asm...) - tx = ethchain.NewContractCreationTx(value, gasPrice, code) + // TODO + fmt.Println(initScript) + tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript) } else { tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) } -- 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 +- ethereal/ui/library.go | 25 +++---------------------- ethereal/ui/ui_lib.go | 18 ++++++++---------- 3 files changed, 12 insertions(+), 33 deletions(-) (limited to 'ethereal/ui') 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 { diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 76032f400..6c6f7557a 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" - "github.com/obscuren/mutan" "github.com/obscuren/secp256k1-go" "strings" ) @@ -44,22 +43,6 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) } -// General compiler and preprocessor function -func compile(script string) ([]byte, error) { - asm, errors := mutan.Compile(strings.NewReader(script), false) - if len(errors) > 0 { - var errs string - for _, er := range errors { - if er != nil { - errs += er.Error() - } - } - return nil, fmt.Errorf("%v", errs) - } - - return ethutil.Assemble(asm...), nil -} - func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { var hash []byte var contractCreation bool @@ -81,18 +64,16 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin // Compile and assemble the given data if contractCreation { mainInput, initInput := ethutil.PreProcess(data) - mainScript, err := compile(mainInput) + mainScript, err := utils.Compile(mainInput) if err != nil { return "", err } - initScript, err := compile(initInput) + initScript, err := utils.Compile(initInput) if err != nil { return "", err } - // TODO - fmt.Println(initScript) - tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript) + tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript, initScript) } else { tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index b2552cdce..a0d2f557a 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -6,14 +6,13 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/niemeyer/qml" - "github.com/obscuren/mutan" "math/big" "os" "path" "path/filepath" "runtime" - "strings" ) type memAddr struct { @@ -99,25 +98,24 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) state := ui.eth.BlockChain().CurrentBlock.State() mainInput, _ := ethutil.PreProcess(data) - asm, err := mutan.Compile(strings.NewReader(mainInput), false) + callerScript, err := utils.Compile(mainInput) if err != nil { - fmt.Println(err) - for _, e := range err { - ui.win.Root().Call("addDebugMessage", e.Error()) - } + ethutil.Config.Log.Debugln(err) + + return } - callerScript := ethutil.Assemble(asm...) dis := ethchain.Disassemble(callerScript) ui.win.Root().Call("clearAsm") + for _, str := range dis { ui.win.Root().Call("setAsm", str) } - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript, nil) // Contract addr as test address keyPair := ethutil.Config.Db.GetKeys()[0] - account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Account + account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Object c := ethchain.MakeContract(callerTx, state) callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), new(big.Int)) -- cgit v1.2.3 From a0c97b663dcb8de940c17479877e3165834f0c8a Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 20 Apr 2014 02:05:20 +0200 Subject: Updated closure call --- ethereal/ui/ui_lib.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index a0d2f557a..95743fa5d 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "github.com/niemeyer/qml" - "math/big" "os" "path" "path/filepath" @@ -117,7 +116,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) keyPair := ethutil.Config.Db.GetKeys()[0] account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Object c := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), new(big.Int)) + callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr), ethutil.Big(valueStr)) block := ui.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, ethchain.RuntimeVars{ -- cgit v1.2.3 From 6d5d539a859cae43a1e97acd6fc5675d45b09063 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 21 Apr 2014 00:57:57 +0200 Subject: Round one HTML external applications using QML(Qt5) WebKit2 w/o native bindings --- ethereal/ui/ui_lib.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 95743fa5d..096af16db 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -51,6 +51,22 @@ func (ui *UiLib) Open(path string) { }() } +func (ui *UiLib) OpenHtml(path string) { + component, err := ui.engine.LoadFile(ui.AssetPath("qml/webapp.qml")) + if err != nil { + ethutil.Config.Log.Debugln(err) + + return + } + win := component.CreateWindow(nil) + win.Set("url", path) + + go func() { + win.Show() + win.Wait() + }() +} + func (ui *UiLib) Connect(button qml.Object) { if !ui.connected { ui.eth.Start() -- 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 + ethereal/ui/library.go | 9 ++++++--- ethereal/ui/ui_lib.go | 10 +++++++++- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') 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) } diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 6c6f7557a..b097ddbb2 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -44,6 +44,7 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { } func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { + fmt.Println("Create tx") var hash []byte var contractCreation bool if len(recipient) == 0 { @@ -64,18 +65,21 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin // Compile and assemble the given data if contractCreation { mainInput, initInput := ethutil.PreProcess(data) + fmt.Println("Precompile done") + fmt.Println("main", mainInput) mainScript, err := utils.Compile(mainInput) if err != nil { return "", err } + fmt.Println("init", initInput) initScript, err := utils.Compile(initInput) if err != nil { return "", err } - tx = ethchain.NewContractCreationTx(value, gasPrice, mainScript, initScript) + tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) } else { - tx = ethchain.NewTransactionMessage(hash, value, gasPrice, gas, nil) + tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, nil) } acc := lib.stateManager.GetAddrState(keyPair.Address()) tx.Nonce = acc.Nonce @@ -99,7 +103,6 @@ func (lib *EthLib) GetBlock(hexHash string) *Block { } block := lib.blockChain.GetBlock(hash) - fmt.Println(block) return &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 096af16db..09f81c67e 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -59,6 +59,14 @@ func (ui *UiLib) OpenHtml(path string) { return } win := component.CreateWindow(nil) + if filepath.Ext(path) == "eth" { + fmt.Println("Ethereum package not yet supported") + + return + + // TODO + ethutil.OpenPackage(path) + } win.Set("url", path) go func() { @@ -126,7 +134,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) for _, str := range dis { ui.win.Root().Call("setAsm", str) } - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasPriceStr), callerScript, nil) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), callerScript, nil) // Contract addr as test address keyPair := ethutil.Config.Db.GetKeys()[0] -- cgit v1.2.3 From 43f1214f97e52863b1f1ef7913991bef3d00c58e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 23 Apr 2014 15:54:34 +0200 Subject: Refactored code --- ethereal/ui/library.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index b097ddbb2..537cfa994 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -43,8 +43,7 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) } -func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data string) (string, error) { - fmt.Println("Create tx") +func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { var hash []byte var contractCreation bool if len(recipient) == 0 { @@ -64,26 +63,24 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin var tx *ethchain.Transaction // Compile and assemble the given data if contractCreation { - mainInput, initInput := ethutil.PreProcess(data) - fmt.Println("Precompile done") - fmt.Println("main", mainInput) - mainScript, err := utils.Compile(mainInput) - if err != nil { - return "", err - } - fmt.Println("init", initInput) - initScript, err := utils.Compile(initInput) + // Compile script + mainScript, initScript, err := utils.CompileScript(dataStr) if err != nil { return "", err } tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) } else { - tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, nil) + lines := strings.Split(dataStr, "\n") + var data []byte + for _, line := range lines { + data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) + } + + tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, data) } acc := lib.stateManager.GetAddrState(keyPair.Address()) tx.Nonce = acc.Nonce - //acc.Nonce++ tx.Sign(keyPair.PrivateKey) lib.txPool.QueueTransaction(tx) -- 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 +++++++++++++- ethereal/ui/library.go | 24 ++++++++++++++++++++++++ ethereal/ui/ui_lib.go | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'ethereal/ui') 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) diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 537cfa994..5ca2b4273 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -10,6 +10,20 @@ import ( "strings" ) +type Contract struct { + object *ethchain.StateObject +} + +func NewContract(object *ethchain.StateObject) *Contract { + return &Contract{object: object} +} + +func (c *Contract) GetStorage(address string) string { + val := c.object.GetMem(ethutil.Big("0x" + address)) + + return val.BigInt().String() +} + type EthLib struct { stateManager *ethchain.StateManager blockChain *ethchain.BlockChain @@ -43,6 +57,16 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) } +func (lib *EthLib) GetKey() string { + return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) +} + +func (lib *EthLib) GetStateObject(address string) *Contract { + stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) + + return NewContract(stateObject) +} + func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { var hash []byte var contractCreation bool diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 09f81c67e..9191e5ea9 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" - "github.com/niemeyer/qml" + "github.com/go-qml/qml" "os" "path" "path/filepath" -- cgit v1.2.3 From c535d0d24623caafcab084546f85f1f70cb2ac67 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 24 Apr 2014 14:42:31 +0200 Subject: Added new block sub for webapp --- ethereal/ui/ui_lib.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9191e5ea9..08e2267a7 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -70,8 +70,34 @@ func (ui *UiLib) OpenHtml(path string) { win.Set("url", path) go func() { + blockChan := make(chan ethutil.React, 1) + quitChan := make(chan bool) + + go func() { + out: + for { + select { + case <-quitChan: + ui.eth.Reactor().Unsubscribe("newBlock", blockChan) + break out + case block := <-blockChan: + if block, ok := block.Resource.(*ethchain.Block); ok { + b := &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + win.ObjectByName("webView").Call("onNewBlockCb", b) + } + } + } + + // Clean up + close(blockChan) + close(quitChan) + }() + ui.eth.Reactor().Subscribe("newBlock", blockChan) + win.Show() win.Wait() + + quitChan <- true }() } -- 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 ++++++---------------------------------------- ethereal/ui/library.go | 8 ++++++-- ethereal/ui/types.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ ethereal/ui/ui_lib.go | 13 +++++++++--- 4 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 ethereal/ui/types.go (limited to 'ethereal/ui') 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) diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 5ca2b4273..7f667f2c1 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -67,6 +67,10 @@ func (lib *EthLib) GetStateObject(address string) *Contract { return NewContract(stateObject) } +func (lib *EthLib) Watch(addr string) { + lib.stateManager.Watch(ethutil.FromHex(addr)) +} + func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { var hash []byte var contractCreation bool @@ -117,7 +121,7 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr st return ethutil.Hex(tx.Hash()), nil } -func (lib *EthLib) GetBlock(hexHash string) *Block { +func (lib *EthLib) GetBlock(hexHash string) *QBlock { hash, err := hex.DecodeString(hexHash) if err != nil { return nil @@ -125,5 +129,5 @@ func (lib *EthLib) GetBlock(hexHash string) *Block { block := lib.blockChain.GetBlock(hash) - return &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + return &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} } diff --git a/ethereal/ui/types.go b/ethereal/ui/types.go new file mode 100644 index 000000000..5c39f0217 --- /dev/null +++ b/ethereal/ui/types.go @@ -0,0 +1,56 @@ +package ethui + +import ( + "encoding/hex" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethutil" +) + +// Block interface exposed to QML +type QBlock struct { + Number int + Hash string +} + +// Creates a new QML Block from a chain block +func NewQBlock(block *ethchain.Block) *QBlock { + info := block.BlockInfo() + hash := hex.EncodeToString(block.Hash()) + + return &QBlock{Number: int(info.Number), Hash: hash} +} + +type QTx struct { + Value, Hash, Address string + Contract bool +} + +func NewQTx(tx *ethchain.Transaction) *QTx { + hash := hex.EncodeToString(tx.Hash()) + sender := hex.EncodeToString(tx.Recipient) + isContract := len(tx.Data) > 0 + + return &QTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} +} + +type QKey struct { + Address string +} + +type QKeyRing struct { + Keys []interface{} +} + +func NewQKeyRing(keys []interface{}) *QKeyRing { + return &QKeyRing{Keys: keys} +} + +type QStateObject struct { + Address string + Amount string + Nonce int +} + +func NewQStateObject(stateObject *ethchain.StateObject) *QStateObject { + return &QStateObject{ethutil.Hex(stateObject.Address()), stateObject.Amount.String(), int(stateObject.Nonce)} +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 08e2267a7..6217c0065 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -69,8 +69,10 @@ func (ui *UiLib) OpenHtml(path string) { } win.Set("url", path) + webView := win.ObjectByName("webView") go func() { blockChan := make(chan ethutil.React, 1) + addrChan := make(chan ethutil.React, 1) quitChan := make(chan bool) go func() { @@ -82,8 +84,12 @@ func (ui *UiLib) OpenHtml(path string) { break out case block := <-blockChan: if block, ok := block.Resource.(*ethchain.Block); ok { - b := &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} - win.ObjectByName("webView").Call("onNewBlockCb", b) + b := &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + webView.Call("onNewBlockCb", b) + } + case stateObject := <-addrChan: + if stateObject, ok := stateObject.Resource.(*ethchain.StateObject); ok { + webView.Call("onObjectChangeCb", NewQStateObject(stateObject)) } } } @@ -93,6 +99,7 @@ func (ui *UiLib) OpenHtml(path string) { close(quitChan) }() ui.eth.Reactor().Subscribe("newBlock", blockChan) + ui.eth.Reactor().Subscribe("addressChanged", addrChan) win.Show() win.Wait() @@ -169,7 +176,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr), ethutil.Big(valueStr)) block := ui.eth.BlockChain().CurrentBlock - vm := ethchain.NewVm(state, ethchain.RuntimeVars{ + vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{ Origin: account.Address(), BlockNumber: block.BlockInfo().Number, PrevHash: block.PrevHash, -- 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') 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 68e5568804cc99d217e7a3aaca796406e428f221 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 28 Apr 2014 00:25:01 +0200 Subject: Draft mut(an)ed(itor) --- ethereal/ui/ui_lib.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 6217c0065..309ab7928 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -108,6 +108,25 @@ func (ui *UiLib) OpenHtml(path string) { }() } +func (ui *UiLib) Muted(content string) { + component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) + if err != nil { + ethutil.Config.Log.Debugln(err) + + return + } + win := component.CreateWindow(nil) + go func() { + path := "file://" + ui.AssetPath("muted/index.html") + win.Set("url", path) + debuggerPath := "file://" + ui.AssetPath("muted/debugger.html") + win.Set("debugUrl", debuggerPath) + + win.Show() + win.Wait() + }() +} + func (ui *UiLib) Connect(button qml.Object) { if !ui.connected { ui.eth.Start() -- cgit v1.2.3 From a0f35d324822fc66951f8a33526ff3d15b0de09d Mon Sep 17 00:00:00 2001 From: Casey Kuhlman Date: Mon, 28 Apr 2014 11:37:44 +0200 Subject: PreProcess moved to Mutan package --- ethereal/ui/ui_lib.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 309ab7928..a9bde74b0 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/obscuren/mutan" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "os" @@ -172,7 +173,7 @@ func DefaultAssetPath() string { func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { state := ui.eth.BlockChain().CurrentBlock.State() - mainInput, _ := ethutil.PreProcess(data) + mainInput, _ := mutan.PreProcess(data) callerScript, err := utils.Compile(mainInput) if err != nil { ethutil.Config.Log.Debugln(err) -- cgit v1.2.3 From 922974c760278b6d49cb6f286b663d60f77d5248 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 28 Apr 2014 23:24:42 +0200 Subject: Added muted --- ethereal/ui/ui_lib.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index a9bde74b0..07cd0ac8a 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -120,8 +120,8 @@ func (ui *UiLib) Muted(content string) { go func() { path := "file://" + ui.AssetPath("muted/index.html") win.Set("url", path) - debuggerPath := "file://" + ui.AssetPath("muted/debugger.html") - win.Set("debugUrl", debuggerPath) + //debuggerPath := "file://" + ui.AssetPath("muted/debugger.html") + //win.Set("debugUrl", debuggerPath) win.Show() win.Wait() -- cgit v1.2.3 From 64c2550b3154df7f2c75dda559d91046cb559ffd Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Apr 2014 01:44:02 +0200 Subject: Split off External applications from main library External applications now accept containers which function as the frontend where the ExtApplication functions as the backend. Containers execute within their own engine and have their own context and are destroyed when released. --- ethereal/ui/ext_app.go | 175 ++++++++++++++++++++++++++++++++++++++++++ ethereal/ui/html_container.go | 73 ++++++++++++++++++ ethereal/ui/library.go | 33 ++++++-- ethereal/ui/ui_lib.go | 62 +++------------ 4 files changed, 286 insertions(+), 57 deletions(-) create mode 100644 ethereal/ui/ext_app.go create mode 100644 ethereal/ui/html_container.go (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go new file mode 100644 index 000000000..b90a2192c --- /dev/null +++ b/ethereal/ui/ext_app.go @@ -0,0 +1,175 @@ +package ethui + +import ( + "fmt" + "github.com/ethereum/eth-go" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethutil" + "github.com/go-qml/qml" + "math/big" +) + +type AppContainer interface { + Create() error + Destroy() + + Window() *qml.Window + Engine() *qml.Engine + + NewBlock(*ethchain.Block) + ObjectChanged(*ethchain.StateObject) + StorageChanged(*ethchain.StateObject, []byte, *big.Int) +} + +type ExtApplication struct { + *QEthereum + + blockChan chan ethutil.React + changeChan chan ethutil.React + quitChan chan bool + + container AppContainer + lib *UiLib + registeredEvents []string +} + +func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { + app := &ExtApplication{ + NewQEthereum(lib.eth), + make(chan ethutil.React, 1), + make(chan ethutil.React, 1), + make(chan bool), + container, + lib, + nil, + } + + return app +} + +func (app *ExtApplication) run() { + // Set the "eth" api on to the containers context + context := app.container.Engine().Context() + context.SetVar("eth", app) + context.SetVar("ui", app.lib) + + err := app.container.Create() + if err != nil { + fmt.Println(err) + + return + } + + // Call the main loop + go app.mainLoop() + + // Subscribe to events + reactor := app.lib.eth.Reactor() + reactor.Subscribe("newBlock", app.blockChan) + + win := app.container.Window() + win.Show() + win.Wait() + + app.stop() +} + +func (app *ExtApplication) stop() { + // Clean up + reactor := app.lib.eth.Reactor() + reactor.Unsubscribe("newBlock", app.blockChan) + for _, event := range app.registeredEvents { + reactor.Unsubscribe(event, app.changeChan) + } + + // Kill the main loop + app.quitChan <- true + + close(app.blockChan) + close(app.quitChan) + close(app.changeChan) + + app.container.Destroy() +} + +func (app *ExtApplication) mainLoop() { +out: + for { + select { + case <-app.quitChan: + break out + case block := <-app.blockChan: + if block, ok := block.Resource.(*ethchain.Block); ok { + app.container.NewBlock(block) + } + case object := <-app.changeChan: + if stateObject, ok := object.Resource.(*ethchain.StateObject); ok { + app.container.ObjectChanged(stateObject) + } else if _, ok := object.Resource.(*big.Int); ok { + // + } + } + } + +} + +func (app *ExtApplication) Watch(addr, storageAddr string) { + var event string + if len(storageAddr) == 0 { + event = "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr)) + app.lib.eth.Reactor().Subscribe(event, app.changeChan) + } else { + event = "object:" + string(ethutil.FromHex(addr)) + app.lib.eth.Reactor().Subscribe(event, app.changeChan) + } + + app.registeredEvents = append(app.registeredEvents, event) +} + +type QEthereum struct { + stateManager *ethchain.StateManager + blockChain *ethchain.BlockChain + txPool *ethchain.TxPool +} + +func NewQEthereum(eth *eth.Ethereum) *QEthereum { + return &QEthereum{ + eth.StateManager(), + eth.BlockChain(), + eth.TxPool(), + } +} + +func (lib *QEthereum) GetBlock(hexHash string) *QBlock { + hash := ethutil.FromHex(hexHash) + + block := lib.blockChain.GetBlock(hash) + + return &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} +} + +func (lib *QEthereum) GetKey() string { + return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) +} + +func (lib *QEthereum) GetStateObject(address string) *Contract { + stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) + if stateObject != nil { + return NewContract(stateObject) + } + + // See GetStorage for explanation on "nil" + return NewContract(nil) +} + +func (lib *QEthereum) Watch(addr, storageAddr string) { + // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) +} + +func (lib *QEthereum) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + return lib.Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr) +} + +func (lib *QEthereum) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + return "", nil +} diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go new file mode 100644 index 000000000..8e3ef0fc7 --- /dev/null +++ b/ethereal/ui/html_container.go @@ -0,0 +1,73 @@ +package ethui + +import ( + "errors" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethutil" + "github.com/go-qml/qml" + "math/big" + "path/filepath" +) + +type HtmlApplication struct { + win *qml.Window + webView qml.Object + engine *qml.Engine + lib *UiLib + path string +} + +func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication { + engine := qml.NewEngine() + + return &HtmlApplication{engine: engine, lib: lib, path: path} + +} + +func (app *HtmlApplication) Create() error { + component, err := app.engine.LoadFile(app.lib.AssetPath("qml/webapp.qml")) + if err != nil { + return err + } + + if filepath.Ext(app.path) == "eth" { + return errors.New("Ethereum package not yet supported") + + // TODO + ethutil.OpenPackage(app.path) + } + + win := component.CreateWindow(nil) + win.Set("url", app.path) + webView := win.ObjectByName("webView") + + app.win = win + app.webView = webView + + return nil +} + +func (app *HtmlApplication) Engine() *qml.Engine { + return app.engine +} + +func (app *HtmlApplication) Window() *qml.Window { + return app.win +} + +func (app *HtmlApplication) NewBlock(block *ethchain.Block) { + b := &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + app.webView.Call("onNewBlockCb", b) +} + +func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { + app.webView.Call("onObjectChangeCb", NewQStateObject(stateObject)) +} + +func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) { + app.webView.Call("onStorageChangeCb", nil) +} + +func (app *HtmlApplication) Destroy() { + app.engine.Destroy() +} diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 7f667f2c1..ec5f29f95 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -19,9 +19,24 @@ func NewContract(object *ethchain.StateObject) *Contract { } func (c *Contract) GetStorage(address string) string { - val := c.object.GetMem(ethutil.Big("0x" + address)) + // Because somehow, even if you return nil to QML it + // still has some magical object so we can't rely on + // undefined or null at the QML side + if c.object != nil { + val := c.object.GetMem(ethutil.Big("0x" + address)) - return val.BigInt().String() + return val.BigInt().String() + } + + return "" +} + +func (c *Contract) Value() string { + if c.object != nil { + return c.object.Amount.String() + } + + return "" } type EthLib struct { @@ -63,15 +78,23 @@ func (lib *EthLib) GetKey() string { func (lib *EthLib) GetStateObject(address string) *Contract { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) + if stateObject != nil { + return NewContract(stateObject) + } - return NewContract(stateObject) + // See GetStorage for explanation on "nil" + return NewContract(nil) } -func (lib *EthLib) Watch(addr string) { - lib.stateManager.Watch(ethutil.FromHex(addr)) +func (lib *EthLib) Watch(addr, storageAddr string) { + // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) } func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + return lib.Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr) +} + +func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { var hash []byte var contractCreation bool if len(recipient) == 0 { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 07cd0ac8a..0feb522bc 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -6,9 +6,9 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" - "github.com/obscuren/mutan" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" + "github.com/obscuren/mutan" "os" "path" "path/filepath" @@ -53,60 +53,18 @@ func (ui *UiLib) Open(path string) { } func (ui *UiLib) OpenHtml(path string) { - component, err := ui.engine.LoadFile(ui.AssetPath("qml/webapp.qml")) - if err != nil { - ethutil.Config.Log.Debugln(err) + container := NewHtmlApplication(path, ui) + app := NewExtApplication(container, ui) - return - } - win := component.CreateWindow(nil) - if filepath.Ext(path) == "eth" { - fmt.Println("Ethereum package not yet supported") - - return + go app.run() +} - // TODO - ethutil.OpenPackage(path) +func (ui *UiLib) Watch(addr, storageAddr string) { + if len(storageAddr) == 0 { + ui.eth.Reactor().Subscribe("storage:"+string(ethutil.FromHex(addr))+":"+string(ethutil.FromHex(storageAddr)), nil) + } else { + ui.eth.Reactor().Subscribe("object:"+string(ethutil.FromHex(addr)), nil) } - win.Set("url", path) - - webView := win.ObjectByName("webView") - go func() { - blockChan := make(chan ethutil.React, 1) - addrChan := make(chan ethutil.React, 1) - quitChan := make(chan bool) - - go func() { - out: - for { - select { - case <-quitChan: - ui.eth.Reactor().Unsubscribe("newBlock", blockChan) - break out - case block := <-blockChan: - if block, ok := block.Resource.(*ethchain.Block); ok { - b := &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} - webView.Call("onNewBlockCb", b) - } - case stateObject := <-addrChan: - if stateObject, ok := stateObject.Resource.(*ethchain.StateObject); ok { - webView.Call("onObjectChangeCb", NewQStateObject(stateObject)) - } - } - } - - // Clean up - close(blockChan) - close(quitChan) - }() - ui.eth.Reactor().Subscribe("newBlock", blockChan) - ui.eth.Reactor().Subscribe("addressChanged", addrChan) - - win.Show() - win.Wait() - - quitChan <- true - }() } func (ui *UiLib) Muted(content string) { -- cgit v1.2.3 From 183dbcc6a0e56bf46f6406d47134f3b88eb5eef1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 30 Apr 2014 14:42:57 +0200 Subject: fixed state object changes for eth api --- ethereal/ui/ext_app.go | 62 ++++++++++++++++++++++++++++++++++++++++++-------- ethereal/ui/library.go | 35 +++------------------------- ethereal/ui/types.go | 37 ++++++++++++++++++++++++++---- 3 files changed, 88 insertions(+), 46 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index b90a2192c..c02ffb7b2 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -5,8 +5,10 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" + "strings" ) type AppContainer interface { @@ -116,10 +118,10 @@ out: func (app *ExtApplication) Watch(addr, storageAddr string) { var event string if len(storageAddr) == 0 { - event = "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr)) + event = "object:" + string(ethutil.FromHex(addr)) app.lib.eth.Reactor().Subscribe(event, app.changeChan) } else { - event = "object:" + string(ethutil.FromHex(addr)) + event = "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr)) app.lib.eth.Reactor().Subscribe(event, app.changeChan) } @@ -152,24 +154,66 @@ func (lib *QEthereum) GetKey() string { return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) } -func (lib *QEthereum) GetStateObject(address string) *Contract { +func (lib *QEthereum) GetStateObject(address string) *QStateObject { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) if stateObject != nil { - return NewContract(stateObject) + return NewQStateObject(stateObject) } // See GetStorage for explanation on "nil" - return NewContract(nil) + return NewQStateObject(nil) } func (lib *QEthereum) Watch(addr, storageAddr string) { // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) } -func (lib *QEthereum) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - return lib.Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr) +func (lib *QEthereum) CreateTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + return lib.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr) } -func (lib *QEthereum) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - return "", nil +func (lib *QEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { + var hash []byte + var contractCreation bool + if len(recipient) == 0 { + contractCreation = true + } else { + hash = ethutil.FromHex(recipient) + } + + keyPair := ethutil.Config.Db.GetKeys()[0] + value := ethutil.Big(valueStr) + gas := ethutil.Big(gasStr) + gasPrice := ethutil.Big(gasPriceStr) + var tx *ethchain.Transaction + // Compile and assemble the given data + if contractCreation { + // Compile script + mainScript, initScript, err := utils.CompileScript(dataStr) + if err != nil { + return "", err + } + + tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) + } else { + lines := strings.Split(dataStr, "\n") + var data []byte + for _, line := range lines { + data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) + } + + tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, data) + } + acc := lib.stateManager.GetAddrState(keyPair.Address()) + tx.Nonce = acc.Nonce + tx.Sign(keyPair.PrivateKey) + lib.txPool.QueueTransaction(tx) + + if contractCreation { + ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) + } else { + ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) + } + + return ethutil.Hex(tx.Hash()), nil } diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index ec5f29f95..70462a93d 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -10,35 +10,6 @@ import ( "strings" ) -type Contract struct { - object *ethchain.StateObject -} - -func NewContract(object *ethchain.StateObject) *Contract { - return &Contract{object: object} -} - -func (c *Contract) GetStorage(address string) string { - // Because somehow, even if you return nil to QML it - // still has some magical object so we can't rely on - // undefined or null at the QML side - if c.object != nil { - val := c.object.GetMem(ethutil.Big("0x" + address)) - - return val.BigInt().String() - } - - return "" -} - -func (c *Contract) Value() string { - if c.object != nil { - return c.object.Amount.String() - } - - return "" -} - type EthLib struct { stateManager *ethchain.StateManager blockChain *ethchain.BlockChain @@ -76,14 +47,14 @@ func (lib *EthLib) GetKey() string { return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) } -func (lib *EthLib) GetStateObject(address string) *Contract { +func (lib *EthLib) GetStateObject(address string) *QStateObject { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) if stateObject != nil { - return NewContract(stateObject) + return NewQStateObject(stateObject) } // See GetStorage for explanation on "nil" - return NewContract(nil) + return NewQStateObject(nil) } func (lib *EthLib) Watch(addr, storageAddr string) { diff --git a/ethereal/ui/types.go b/ethereal/ui/types.go index 5c39f0217..9e12a8892 100644 --- a/ethereal/ui/types.go +++ b/ethereal/ui/types.go @@ -46,11 +46,38 @@ func NewQKeyRing(keys []interface{}) *QKeyRing { } type QStateObject struct { - Address string - Amount string - Nonce int + object *ethchain.StateObject +} + +func NewQStateObject(object *ethchain.StateObject) *QStateObject { + return &QStateObject{object: object} } -func NewQStateObject(stateObject *ethchain.StateObject) *QStateObject { - return &QStateObject{ethutil.Hex(stateObject.Address()), stateObject.Amount.String(), int(stateObject.Nonce)} +func (c *QStateObject) GetStorage(address string) string { + // Because somehow, even if you return nil to QML it + // still has some magical object so we can't rely on + // undefined or null at the QML side + if c.object != nil { + val := c.object.GetMem(ethutil.Big("0x" + address)) + + return val.BigInt().String() + } + + return "" +} + +func (c *QStateObject) Value() string { + if c.object != nil { + return c.object.Amount.String() + } + + return "" +} + +func (c *QStateObject) Address() string { + if c.object != nil { + return ethutil.Hex(c.object.Address()) + } + + return "" } -- 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') 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 471bd398f380bc26ba3144a0834092036565e429 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 2 May 2014 12:07:24 +0200 Subject: Moved Ext ethereum api Moved the external ethereum api which can be used by any 3rd party application. --- ethereal/ui/types.go | 83 ---------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 ethereal/ui/types.go (limited to 'ethereal/ui') diff --git a/ethereal/ui/types.go b/ethereal/ui/types.go deleted file mode 100644 index 9e12a8892..000000000 --- a/ethereal/ui/types.go +++ /dev/null @@ -1,83 +0,0 @@ -package ethui - -import ( - "encoding/hex" - "github.com/ethereum/eth-go/ethchain" - "github.com/ethereum/eth-go/ethutil" -) - -// Block interface exposed to QML -type QBlock struct { - Number int - Hash string -} - -// Creates a new QML Block from a chain block -func NewQBlock(block *ethchain.Block) *QBlock { - info := block.BlockInfo() - hash := hex.EncodeToString(block.Hash()) - - return &QBlock{Number: int(info.Number), Hash: hash} -} - -type QTx struct { - Value, Hash, Address string - Contract bool -} - -func NewQTx(tx *ethchain.Transaction) *QTx { - hash := hex.EncodeToString(tx.Hash()) - sender := hex.EncodeToString(tx.Recipient) - isContract := len(tx.Data) > 0 - - return &QTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} -} - -type QKey struct { - Address string -} - -type QKeyRing struct { - Keys []interface{} -} - -func NewQKeyRing(keys []interface{}) *QKeyRing { - return &QKeyRing{Keys: keys} -} - -type QStateObject struct { - object *ethchain.StateObject -} - -func NewQStateObject(object *ethchain.StateObject) *QStateObject { - return &QStateObject{object: object} -} - -func (c *QStateObject) GetStorage(address string) string { - // Because somehow, even if you return nil to QML it - // still has some magical object so we can't rely on - // undefined or null at the QML side - if c.object != nil { - val := c.object.GetMem(ethutil.Big("0x" + address)) - - return val.BigInt().String() - } - - return "" -} - -func (c *QStateObject) Value() string { - if c.object != nil { - return c.object.Amount.String() - } - - return "" -} - -func (c *QStateObject) Address() string { - if c.object != nil { - return ethutil.Hex(c.object.Address()) - } - - return "" -} -- 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/ext_app.go | 96 +------------------------------------------ ethereal/ui/gui.go | 13 +++--- ethereal/ui/html_container.go | 5 ++- ethereal/ui/library.go | 10 ++--- 4 files changed, 17 insertions(+), 107 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index c02ffb7b2..1021afea9 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -2,13 +2,11 @@ package ethui import ( "fmt" - "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" - "strings" ) type AppContainer interface { @@ -24,7 +22,7 @@ type AppContainer interface { } type ExtApplication struct { - *QEthereum + *utils.PEthereum blockChan chan ethutil.React changeChan chan ethutil.React @@ -37,7 +35,7 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ - NewQEthereum(lib.eth), + utils.NewPEthereum(lib.eth), make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), @@ -127,93 +125,3 @@ func (app *ExtApplication) Watch(addr, storageAddr string) { app.registeredEvents = append(app.registeredEvents, event) } - -type QEthereum struct { - stateManager *ethchain.StateManager - blockChain *ethchain.BlockChain - txPool *ethchain.TxPool -} - -func NewQEthereum(eth *eth.Ethereum) *QEthereum { - return &QEthereum{ - eth.StateManager(), - eth.BlockChain(), - eth.TxPool(), - } -} - -func (lib *QEthereum) GetBlock(hexHash string) *QBlock { - hash := ethutil.FromHex(hexHash) - - block := lib.blockChain.GetBlock(hash) - - return &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} -} - -func (lib *QEthereum) GetKey() string { - return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) -} - -func (lib *QEthereum) GetStateObject(address string) *QStateObject { - stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) - if stateObject != nil { - return NewQStateObject(stateObject) - } - - // See GetStorage for explanation on "nil" - return NewQStateObject(nil) -} - -func (lib *QEthereum) Watch(addr, storageAddr string) { - // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) -} - -func (lib *QEthereum) CreateTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - return lib.Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr) -} - -func (lib *QEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - var hash []byte - var contractCreation bool - if len(recipient) == 0 { - contractCreation = true - } else { - hash = ethutil.FromHex(recipient) - } - - keyPair := ethutil.Config.Db.GetKeys()[0] - value := ethutil.Big(valueStr) - gas := ethutil.Big(gasStr) - gasPrice := ethutil.Big(gasPriceStr) - var tx *ethchain.Transaction - // Compile and assemble the given data - if contractCreation { - // Compile script - mainScript, initScript, err := utils.CompileScript(dataStr) - if err != nil { - return "", err - } - - tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) - } else { - lines := strings.Split(dataStr, "\n") - var data []byte - for _, line := range lines { - data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) - } - - tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, data) - } - acc := lib.stateManager.GetAddrState(keyPair.Address()) - tx.Nonce = acc.Nonce - tx.Sign(keyPair.PrivateKey) - lib.txPool.QueueTransaction(tx) - - if contractCreation { - ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) - } else { - ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) - } - - return ethutil.Hex(tx.Hash()), nil -} 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) diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 8e3ef0fc7..16cc531f2 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" "path/filepath" @@ -56,12 +57,12 @@ func (app *HtmlApplication) Window() *qml.Window { } func (app *HtmlApplication) NewBlock(block *ethchain.Block) { - b := &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + b := &utils.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} app.webView.Call("onNewBlockCb", b) } func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { - app.webView.Call("onObjectChangeCb", NewQStateObject(stateObject)) + app.webView.Call("onObjectChangeCb", utils.NewPStateObject(stateObject)) } func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) { diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 70462a93d..231fd96e7 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -47,14 +47,14 @@ func (lib *EthLib) GetKey() string { return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) } -func (lib *EthLib) GetStateObject(address string) *QStateObject { +func (lib *EthLib) GetStateObject(address string) *utils.PStateObject { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) if stateObject != nil { - return NewQStateObject(stateObject) + return utils.NewPStateObject(stateObject) } // See GetStorage for explanation on "nil" - return NewQStateObject(nil) + return utils.NewPStateObject(nil) } func (lib *EthLib) Watch(addr, storageAddr string) { @@ -115,7 +115,7 @@ func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr st return ethutil.Hex(tx.Hash()), nil } -func (lib *EthLib) GetBlock(hexHash string) *QBlock { +func (lib *EthLib) GetBlock(hexHash string) *utils.PBlock { hash, err := hex.DecodeString(hexHash) if err != nil { return nil @@ -123,5 +123,5 @@ func (lib *EthLib) GetBlock(hexHash string) *QBlock { block := lib.blockChain.GetBlock(hash) - return &QBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + return &utils.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} } -- 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/ext_app.go | 6 +++--- ethereal/ui/gui.go | 14 +++++++------- ethereal/ui/html_container.go | 6 +++--- ethereal/ui/library.go | 11 ++++++----- 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index 1021afea9..a215709d0 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -3,8 +3,8 @@ package ethui import ( "fmt" "github.com/ethereum/eth-go/ethchain" + "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" ) @@ -22,7 +22,7 @@ type AppContainer interface { } type ExtApplication struct { - *utils.PEthereum + *ethpub.PEthereum blockChan chan ethutil.React changeChan chan ethutil.React @@ -35,7 +35,7 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ - utils.NewPEthereum(lib.eth), + ethpub.NewPEthereum(lib.eth), make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), 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) diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 16cc531f2..e3e48bfcc 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -3,8 +3,8 @@ package ethui import ( "errors" "github.com/ethereum/eth-go/ethchain" + "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" "path/filepath" @@ -57,12 +57,12 @@ func (app *HtmlApplication) Window() *qml.Window { } func (app *HtmlApplication) NewBlock(block *ethchain.Block) { - b := &utils.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} app.webView.Call("onNewBlockCb", b) } func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { - app.webView.Call("onObjectChangeCb", utils.NewPStateObject(stateObject)) + app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject)) } func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) { diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 231fd96e7..1328cd6b7 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/secp256k1-go" @@ -47,14 +48,14 @@ func (lib *EthLib) GetKey() string { return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) } -func (lib *EthLib) GetStateObject(address string) *utils.PStateObject { +func (lib *EthLib) GetStateObject(address string) *ethpub.PStateObject { stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) if stateObject != nil { - return utils.NewPStateObject(stateObject) + return ethpub.NewPStateObject(stateObject) } // See GetStorage for explanation on "nil" - return utils.NewPStateObject(nil) + return ethpub.NewPStateObject(nil) } func (lib *EthLib) Watch(addr, storageAddr string) { @@ -115,7 +116,7 @@ func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr st return ethutil.Hex(tx.Hash()), nil } -func (lib *EthLib) GetBlock(hexHash string) *utils.PBlock { +func (lib *EthLib) GetBlock(hexHash string) *ethpub.PBlock { hash, err := hex.DecodeString(hexHash) if err != nil { return nil @@ -123,5 +124,5 @@ func (lib *EthLib) GetBlock(hexHash string) *utils.PBlock { block := lib.blockChain.GetBlock(hash) - return &utils.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + return ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} } -- cgit v1.2.3 From dd45197bcd174e16adc3b738bf390cc3018a5a28 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 May 2014 11:56:05 +0200 Subject: Added storage watch --- ethereal/ui/ext_app.go | 7 +++---- ethereal/ui/html_container.go | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index a215709d0..de5f15db6 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "math/big" ) type AppContainer interface { @@ -18,7 +17,7 @@ type AppContainer interface { NewBlock(*ethchain.Block) ObjectChanged(*ethchain.StateObject) - StorageChanged(*ethchain.StateObject, []byte, *big.Int) + StorageChanged(*ethchain.StorageState) } type ExtApplication struct { @@ -105,8 +104,8 @@ out: case object := <-app.changeChan: if stateObject, ok := object.Resource.(*ethchain.StateObject); ok { app.container.ObjectChanged(stateObject) - } else if _, ok := object.Resource.(*big.Int); ok { - // + } else if storageObject, ok := object.Resource.(*ethchain.StorageState); ok { + app.container.StorageChanged(storageObject) } } } diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index e3e48bfcc..4f12aaaf6 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "math/big" "path/filepath" ) @@ -65,8 +64,8 @@ func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject)) } -func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) { - app.webView.Call("onStorageChangeCb", nil) +func (app *HtmlApplication) StorageChanged(storageObject *ethchain.StorageState) { + app.webView.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject)) } func (app *HtmlApplication) Destroy() { -- cgit v1.2.3 From e94e5ac75dbbc4ec52228ae11377a4fa71ab95ab Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 5 May 2014 14:16:14 +0200 Subject: Implemented rpc for ethereal and ethereum --- ethereal/ui/ext_app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index a215709d0..110ad37d7 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -35,7 +35,7 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ - ethpub.NewPEthereum(lib.eth), + ethpub.NewPEthereum(lib.eth.StateManager(), lib.eth.BlockChain(), lib.eth.TxPool()), make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), -- cgit v1.2.3 From 71defc11fa01b113e26da876388f7a50f314d7fb Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 8 May 2014 14:20:17 +0200 Subject: Fixed closure --- ethereal/ui/ui_lib.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 0feb522bc..855ed4af3 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -151,7 +151,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) keyPair := ethutil.Config.Db.GetKeys()[0] account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Object c := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr), ethutil.Big(valueStr)) + callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) block := ui.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{ -- 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 +++++++++++++++++++++++++------------------------ ethereal/ui/library.go | 85 ----------------------------- ethereal/ui/ui_lib.go | 2 +- 3 files changed, 74 insertions(+), 154 deletions(-) (limited to 'ethereal/ui') 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) +} diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index 1328cd6b7..c889efb45 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -1,10 +1,8 @@ package ethui import ( - "encoding/hex" "fmt" "github.com/ethereum/eth-go/ethchain" - "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/secp256k1-go" @@ -43,86 +41,3 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { mnemonicString := strings.Join(mne, " ") return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) } - -func (lib *EthLib) GetKey() string { - return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) -} - -func (lib *EthLib) GetStateObject(address string) *ethpub.PStateObject { - stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address)) - if stateObject != nil { - return ethpub.NewPStateObject(stateObject) - } - - // See GetStorage for explanation on "nil" - return ethpub.NewPStateObject(nil) -} - -func (lib *EthLib) Watch(addr, storageAddr string) { - // lib.stateManager.Watch(ethutil.FromHex(addr), ethutil.FromHex(storageAddr)) -} - -func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - return lib.Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr) -} - -func (lib *EthLib) Transact(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) { - var hash []byte - var contractCreation bool - if len(recipient) == 0 { - contractCreation = true - } else { - var err error - hash, err = hex.DecodeString(recipient) - if err != nil { - return "", err - } - } - - keyPair := ethutil.Config.Db.GetKeys()[0] - value := ethutil.Big(valueStr) - gas := ethutil.Big(gasStr) - gasPrice := ethutil.Big(gasPriceStr) - var tx *ethchain.Transaction - // Compile and assemble the given data - if contractCreation { - // Compile script - mainScript, initScript, err := utils.CompileScript(dataStr) - if err != nil { - return "", err - } - - tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript) - } else { - lines := strings.Split(dataStr, "\n") - var data []byte - for _, line := range lines { - data = append(data, ethutil.BigToBytes(ethutil.Big(line), 256)...) - } - - tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, data) - } - acc := lib.stateManager.GetAddrState(keyPair.Address()) - tx.Nonce = acc.Nonce - tx.Sign(keyPair.PrivateKey) - lib.txPool.QueueTransaction(tx) - - if contractCreation { - ethutil.Config.Log.Infof("Contract addr %x", tx.Hash()[12:]) - } else { - ethutil.Config.Log.Infof("Tx hash %x", tx.Hash()) - } - - return ethutil.Hex(tx.Hash()), nil -} - -func (lib *EthLib) GetBlock(hexHash string) *ethpub.PBlock { - hash, err := hex.DecodeString(hexHash) - if err != nil { - return nil - } - - block := lib.blockChain.GetBlock(hash) - - return ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} -} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 855ed4af3..0e7992b4a 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -149,7 +149,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) // Contract addr as test address keyPair := ethutil.Config.Db.GetKeys()[0] - account := ui.eth.StateManager().GetAddrState(keyPair.Address()).Object + account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address()) c := ethchain.MakeContract(callerTx, state) callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) -- cgit v1.2.3 From 0bf2d24cb030ec53abedf483189ecbaa3c9676be Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 9 May 2014 14:51:02 +0200 Subject: Changed seeding --- ethereal/ui/ui_lib.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 0e7992b4a..7fe610c6a 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -88,7 +88,7 @@ func (ui *UiLib) Muted(content string) { func (ui *UiLib) Connect(button qml.Object) { if !ui.connected { - ui.eth.Start() + ui.eth.Start(true) ui.connected = true button.Set("enabled", false) } -- 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 ++++++- ethereal/ui/ui_lib.go | 10 ---------- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'ethereal/ui') 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) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 7fe610c6a..35ceb7d79 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -59,14 +59,6 @@ func (ui *UiLib) OpenHtml(path string) { go app.run() } -func (ui *UiLib) Watch(addr, storageAddr string) { - if len(storageAddr) == 0 { - ui.eth.Reactor().Subscribe("storage:"+string(ethutil.FromHex(addr))+":"+string(ethutil.FromHex(storageAddr)), nil) - } else { - ui.eth.Reactor().Subscribe("object:"+string(ethutil.FromHex(addr)), nil) - } -} - func (ui *UiLib) Muted(content string) { component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) if err != nil { @@ -78,8 +70,6 @@ func (ui *UiLib) Muted(content string) { go func() { path := "file://" + ui.AssetPath("muted/index.html") win.Set("url", path) - //debuggerPath := "file://" + ui.AssetPath("muted/debugger.html") - //win.Set("debugUrl", debuggerPath) win.Show() win.Wait() -- 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') 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 ++-- ethereal/ui/ui_lib.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ethereal/ui') 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) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 35ceb7d79..6736e79ae 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -121,7 +121,7 @@ func DefaultAssetPath() string { func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { state := ui.eth.BlockChain().CurrentBlock.State() - mainInput, _ := mutan.PreProcess(data) + mainInput, _ := mutan.PreParse(data) callerScript, err := utils.Compile(mainInput) if err != nil { ethutil.Config.Log.Debugln(err) -- 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') 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') 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/ext_app.go | 2 +- ethereal/ui/gui.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index 93db0ade1..de5f15db6 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -34,7 +34,7 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ - ethpub.NewPEthereum(lib.eth.StateManager(), lib.eth.BlockChain(), lib.eth.TxPool()), + ethpub.NewPEthereum(lib.eth), make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), 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') 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 ++++--------------------------------------------- ethereal/ui/library.go | 13 ++++++++----- ethereal/ui/ui_lib.go | 2 +- 3 files changed, 13 insertions(+), 51 deletions(-) (limited to 'ethereal/ui') 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) diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go index c889efb45..267108195 100644 --- a/ethereal/ui/library.go +++ b/ethereal/ui/library.go @@ -34,10 +34,13 @@ func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool { } func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { - pub, prv := secp256k1.GenerateKeyPair() - pair := ðutil.Key{PrivateKey: prv, PublicKey: pub} - ethutil.Config.Db.Put([]byte("KeyRing"), pair.RlpEncode()) - mne := ethutil.MnemonicEncode(ethutil.Hex(prv)) + _, prv := secp256k1.GenerateKeyPair() + keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv) + if err != nil { + panic(err) + } + + mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey)) mnemonicString := strings.Join(mne, " ") - return mnemonicString, fmt.Sprintf("%x", pair.Address()), fmt.Sprintf("%x", prv), fmt.Sprintf("%x", pub) + return mnemonicString, fmt.Sprintf("%x", keyPair.Address()), ethutil.Hex(keyPair.PrivateKey), ethutil.Hex(keyPair.PublicKey) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 6736e79ae..0c43f1675 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -138,7 +138,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), callerScript, nil) // Contract addr as test address - keyPair := ethutil.Config.Db.GetKeys()[0] + keyPair := ethutil.GetKeyRing().Get(0) account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address()) c := ethchain.MakeContract(callerTx, state) callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) -- 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') 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') 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') 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') 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') 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 0cf617ef0c796cf97252fb64a92afc7cb1d892f2 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 20 May 2014 16:58:13 +0200 Subject: Implemented GUI watchers for rapid reload. Implements #46 --- ethereal/ui/ext_app.go | 12 ++++++--- ethereal/ui/html_container.go | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 3 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index de5f15db6..d1a256cdb 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -18,14 +18,16 @@ type AppContainer interface { NewBlock(*ethchain.Block) ObjectChanged(*ethchain.StateObject) StorageChanged(*ethchain.StorageState) + NewWatcher(chan bool) } type ExtApplication struct { *ethpub.PEthereum - blockChan chan ethutil.React - changeChan chan ethutil.React - quitChan chan bool + blockChan chan ethutil.React + changeChan chan ethutil.React + quitChan chan bool + watcherQuitChan chan bool container AppContainer lib *UiLib @@ -38,6 +40,7 @@ func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), + make(chan bool), container, lib, nil, @@ -66,6 +69,8 @@ func (app *ExtApplication) run() { reactor := app.lib.eth.Reactor() reactor.Subscribe("newBlock", app.blockChan) + app.container.NewWatcher(app.watcherQuitChan) + win := app.container.Window() win.Show() win.Wait() @@ -83,6 +88,7 @@ func (app *ExtApplication) stop() { // Kill the main loop app.quitChan <- true + app.watcherQuitChan <- true close(app.blockChan) close(app.quitChan) diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 4f12aaaf6..3867c0353 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -6,6 +6,12 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "github.com/howeyc/fsnotify" + "io/ioutil" + "log" + "net/url" + "os" + "path" "path/filepath" ) @@ -15,6 +21,7 @@ type HtmlApplication struct { engine *qml.Engine lib *UiLib path string + watcher *fsnotify.Watcher } func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication { @@ -47,6 +54,59 @@ func (app *HtmlApplication) Create() error { return nil } +func (app *HtmlApplication) RootFolder() string { + folder, err := url.Parse(app.path) + if err != nil { + return "" + } + return path.Dir(folder.RequestURI()) +} +func (app *HtmlApplication) RecursiveFolders() []os.FileInfo { + files, _ := ioutil.ReadDir(app.RootFolder()) + var folders []os.FileInfo + for _, file := range files { + if file.IsDir() { + folders = append(folders, file) + } + } + return folders +} + +func (app *HtmlApplication) NewWatcher(quitChan chan bool) { + var err error + + app.watcher, err = fsnotify.NewWatcher() + if err != nil { + return + } + err = app.watcher.Watch(app.RootFolder()) + if err != nil { + log.Fatal(err) + } + for _, folder := range app.RecursiveFolders() { + fullPath := app.RootFolder() + "/" + folder.Name() + app.watcher.Watch(fullPath) + } + + go func() { + out: + for { + select { + case <-quitChan: + app.watcher.Close() + break out + case <-app.watcher.Event: + //ethutil.Config.Log.Debugln("Got event:", ev) + app.webView.Call("reload") + case err := <-app.watcher.Error: + // TODO: Do something here + ethutil.Config.Log.Infoln("Watcher error:", err) + } + } + }() + +} + func (app *HtmlApplication) Engine() *qml.Engine { return app.engine } -- 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') 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') 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') 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') 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') 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 ++--- ethereal/ui/ui_lib.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') 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) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 0c43f1675..1c88b0181 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -135,7 +135,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) for _, str := range dis { ui.win.Root().Call("setAsm", str) } - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), callerScript, nil) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), nil) // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) -- 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') 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') 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') 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 +- ethereal/ui/ui_lib.go | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'ethereal/ui') 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 diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 1c88b0181..51fa26a88 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -6,9 +6,7 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" - "github.com/obscuren/mutan" "os" "path" "path/filepath" @@ -121,27 +119,28 @@ func DefaultAssetPath() string { func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { state := ui.eth.BlockChain().CurrentBlock.State() - mainInput, _ := mutan.PreParse(data) - callerScript, err := utils.Compile(mainInput) + script, err := ethutil.Compile(data) if err != nil { ethutil.Config.Log.Debugln(err) return } - dis := ethchain.Disassemble(callerScript) + dis := ethchain.Disassemble(script) ui.win.Root().Call("clearAsm") for _, str := range dis { ui.win.Root().Call("setAsm", str) } - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), nil) - // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) + callerTx := + ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) + callerTx.Sign(keyPair.PrivateKey) + account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address()) - c := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, c, c.Script(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) + contract := ethchain.MakeContract(callerTx, state) + callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) block := ui.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{ @@ -151,23 +150,28 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) Coinbase: block.Coinbase, Time: block.Time, Diff: block.Difficulty, - TxData: nil, }) + ui.Db.done = false go func() { - callerClosure.Call(vm, nil, ui.Db.halting) + callerClosure.Call(vm, contract.Init(), ui.Db.halting) state.Reset() + + ui.Db.done = true }() } func (ui *UiLib) Next() { - ui.Db.Next() + if !ui.Db.done { + ui.Db.Next() + } } type Debugger struct { - win *qml.Window - N chan bool + win *qml.Window + N chan bool + done bool } func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { -- 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') 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 4fd267a7785ea06014f38f9be4e8e380c7f1cb1e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 10:42:37 +0200 Subject: Sep debugger from main --- ethereal/ui/debugger.go | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ ethereal/ui/ui_lib.go | 14 +++++--- 2 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 ethereal/ui/debugger.go (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go new file mode 100644 index 000000000..4debc05b2 --- /dev/null +++ b/ethereal/ui/debugger.go @@ -0,0 +1,86 @@ +package ethui + +import ( + "fmt" + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethutil" + "github.com/go-qml/qml" +) + +type DebuggerWindow struct { + win *qml.Window + engine *qml.Engine + lib *UiLib + Db *Debugger +} + +func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { + engine := qml.NewEngine() + component, err := engine.LoadFile(lib.AssetPath("debugger/debugger.qml")) + if err != nil { + fmt.Println(err) + + return nil + } + + win := component.CreateWindow(nil) + db := &Debugger{win, make(chan bool), true} + + return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db} +} + +func (self *DebuggerWindow) Show() { + go func() { + self.win.Show() + self.win.Wait() + }() +} + +func (self *DebuggerWindow) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { + state := self.lib.eth.BlockChain().CurrentBlock.State() + + script, err := ethutil.Compile(data) + if err != nil { + ethutil.Config.Log.Debugln(err) + + return + } + + dis := ethchain.Disassemble(script) + self.lib.win.Root().Call("clearAsm") + + for _, str := range dis { + self.lib.win.Root().Call("setAsm", str) + } + // Contract addr as test address + keyPair := ethutil.GetKeyRing().Get(0) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) + callerTx.Sign(keyPair.PrivateKey) + + account := self.lib.eth.StateManager().TransState().GetStateObject(keyPair.Address()) + contract := ethchain.MakeContract(callerTx, state) + callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) + + block := self.lib.eth.BlockChain().CurrentBlock + vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{ + Origin: account.Address(), + BlockNumber: block.BlockInfo().Number, + PrevHash: block.PrevHash, + Coinbase: block.Coinbase, + Time: block.Time, + Diff: block.Difficulty, + }) + + self.Db.done = false + go func() { + callerClosure.Call(vm, contract.Init(), self.Db.halting) + + state.Reset() + + self.Db.done = true + }() +} + +func (self *DebuggerWindow) Next() { + self.Db.Next() +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 51fa26a88..c3f9f52e6 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -90,6 +90,12 @@ func (ui *UiLib) AssetPath(p string) string { return path.Join(ui.assetPath, p) } +func (self *UiLib) StartDebugger() { + dbWindow := NewDebuggerWindow(self) + + dbWindow.Show() +} + func DefaultAssetPath() string { var base string // If the current working directory is the go-ethereum dir @@ -163,9 +169,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) } func (ui *UiLib) Next() { - if !ui.Db.done { - ui.Db.Next() - } + ui.Db.Next() } type Debugger struct { @@ -200,5 +204,7 @@ out: } func (d *Debugger) Next() { - d.N <- true + if !d.done { + d.N <- true + } } -- 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') 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 d0b31e203053f3f176e61719d877dcaa04169bb3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 13:09:47 +0200 Subject: New debugger --- ethereal/ui/debugger.go | 55 ++++++++++++++++++++++++++++++++++++++++++++++--- ethereal/ui/ui_lib.go | 38 ---------------------------------- 2 files changed, 52 insertions(+), 41 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 4debc05b2..ce2d73b9a 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -30,13 +30,16 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { } func (self *DebuggerWindow) Show() { + context := self.engine.Context() + context.SetVar("dbg", self) + go func() { self.win.Show() self.win.Wait() }() } -func (self *DebuggerWindow) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { +func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { state := self.lib.eth.BlockChain().CurrentBlock.State() script, err := ethutil.Compile(data) @@ -50,14 +53,14 @@ func (self *DebuggerWindow) DebugTx(recipient, valueStr, gasStr, gasPriceStr, da self.lib.win.Root().Call("clearAsm") for _, str := range dis { - self.lib.win.Root().Call("setAsm", str) + self.win.Root().Call("setAsm", str) } // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) callerTx.Sign(keyPair.PrivateKey) - account := self.lib.eth.StateManager().TransState().GetStateObject(keyPair.Address()) + account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) contract := ethchain.MakeContract(callerTx, state) callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) @@ -84,3 +87,49 @@ func (self *DebuggerWindow) DebugTx(recipient, valueStr, gasStr, gasPriceStr, da func (self *DebuggerWindow) Next() { self.Db.Next() } + +type Debugger struct { + win *qml.Window + N chan bool + done bool +} + +type storeVal struct { + Key, Value string +} + +func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) { + d.win.Root().Call("setInstruction", pc) + d.win.Root().Call("clearMem") + d.win.Root().Call("clearStack") + d.win.Root().Call("clearStorage") + + addr := 0 + for i := 0; i+32 <= mem.Len(); i += 32 { + d.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) + addr++ + } + + for _, val := range stack.Data() { + d.win.Root().Call("setStack", val.String()) + } + + stateObject.State().EachStorage(func(key string, node *ethutil.Value) { + d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())}) + }) + +out: + for { + select { + case <-d.N: + break out + default: + } + } +} + +func (d *Debugger) Next() { + if !d.done { + d.N <- true + } +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index c3f9f52e6..998392525 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -2,7 +2,6 @@ package ethui import ( "bitbucket.org/kardianos/osext" - "fmt" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" @@ -171,40 +170,3 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) func (ui *UiLib) Next() { ui.Db.Next() } - -type Debugger struct { - win *qml.Window - N chan bool - done bool -} - -func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack) { - d.win.Root().Call("setInstruction", pc) - d.win.Root().Call("clearMem") - d.win.Root().Call("clearStack") - - addr := 0 - for i := 0; i+32 <= mem.Len(); i += 32 { - d.win.Root().Call("setMem", memAddr{fmt.Sprintf("%03d", addr), fmt.Sprintf("% x", mem.Data()[i:i+32])}) - addr++ - } - - for _, val := range stack.Data() { - d.win.Root().Call("setStack", val.String()) - } - -out: - for { - select { - case <-d.N: - break out - default: - } - } -} - -func (d *Debugger) Next() { - if !d.done { - d.N <- true - } -} -- 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/debugger.go | 24 ++++++++++++++++++++---- ethereal/ui/gui.go | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index ce2d73b9a..817c0b08f 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -24,7 +24,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { } win := component.CreateWindow(nil) - db := &Debugger{win, make(chan bool), true} + db := &Debugger{win, make(chan bool), make(chan bool), true} return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db} } @@ -40,8 +40,18 @@ func (self *DebuggerWindow) Show() { } func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { + if !self.Db.done { + self.Db.Q <- true + } + state := self.lib.eth.BlockChain().CurrentBlock.State() + defer func() { + if r := recover(); r != nil { + fmt.Println(r) + } + }() + script, err := ethutil.Compile(data) if err != nil { ethutil.Config.Log.Debugln(err) @@ -50,7 +60,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { } dis := ethchain.Disassemble(script) - self.lib.win.Root().Call("clearAsm") + self.win.Root().Call("clearAsm") for _, str := range dis { self.win.Root().Call("setAsm", str) @@ -91,6 +101,7 @@ func (self *DebuggerWindow) Next() { type Debugger struct { win *qml.Window N chan bool + Q chan bool done bool } @@ -98,7 +109,7 @@ type storeVal struct { Key, Value string } -func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) { +func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, stack *ethchain.Stack, stateObject *ethchain.StateObject) bool { d.win.Root().Call("setInstruction", pc) d.win.Root().Call("clearMem") d.win.Root().Call("clearStack") @@ -123,9 +134,14 @@ out: select { case <-d.N: break out - default: + case <-d.Q: + d.done = true + + return false } } + + return true } func (d *Debugger) Next() { 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 a0f73c2703aacab189c5cf26a5c95e156039eb9e Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 16:09:04 +0200 Subject: Minor fixes and improvements to the ui --- ethereal/ui/debugger.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 817c0b08f..8b27c2fe5 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -5,6 +5,8 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "math/big" + "strings" ) type DebuggerWindow struct { @@ -39,11 +41,35 @@ func (self *DebuggerWindow) Show() { }() } -func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { +func formatData(data string) []byte { + if len(data) == 0 { + return nil + } + // Simple stupid + d := new(big.Int) + if data[0:1] == "\"" && data[len(data)-1:] == "\"" { + d.SetBytes([]byte(data[1 : len(data)-1])) + } else if data[:2] == "0x" { + d.SetBytes(ethutil.FromHex(data[2:])) + } else { + d.SetString(data, 0) + } + + return ethutil.BigToBytes(d, 256) +} + +func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { if !self.Db.done { self.Db.Q <- true } + dataSlice := strings.Split(dataStr, "\n") + var data []byte + for _, dataItem := range dataSlice { + d := formatData(dataItem) + data = append(data, d...) + } + state := self.lib.eth.BlockChain().CurrentBlock.State() defer func() { @@ -52,7 +78,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { } }() - script, err := ethutil.Compile(data) + script, err := ethutil.Compile(scriptStr) if err != nil { ethutil.Config.Log.Debugln(err) @@ -72,7 +98,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) contract := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) + callerClosure := ethchain.NewClosure(account, contract, script, state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) block := self.lib.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{ @@ -86,7 +112,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, data string) { self.Db.done = false go func() { - callerClosure.Call(vm, contract.Init(), self.Db.halting) + callerClosure.Call(vm, data, self.Db.halting) state.Reset() -- 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') 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 09728bf43ce5eaed3060d0ce8aae323055aa6cba Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 28 May 2014 13:00:45 +0200 Subject: Debugger script&data now accept "0x" values --- ethereal/ui/debugger.go | 64 ++++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 24 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 8b27c2fe5..5b1fb50a2 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -9,6 +9,23 @@ import ( "strings" ) +func formatData(data string) []byte { + if len(data) == 0 { + return nil + } + // Simple stupid + d := new(big.Int) + if data[0:1] == "\"" && data[len(data)-1:] == "\"" { + d.SetBytes([]byte(data[1 : len(data)-1])) + } else if data[:2] == "0x" { + d.SetBytes(ethutil.FromHex(data[2:])) + } else { + d.SetString(data, 0) + } + + return ethutil.BigToBytes(d, 256) +} + type DebuggerWindow struct { win *qml.Window engine *qml.Engine @@ -41,21 +58,12 @@ func (self *DebuggerWindow) Show() { }() } -func formatData(data string) []byte { - if len(data) == 0 { - return nil - } - // Simple stupid - d := new(big.Int) - if data[0:1] == "\"" && data[len(data)-1:] == "\"" { - d.SetBytes([]byte(data[1 : len(data)-1])) - } else if data[:2] == "0x" { - d.SetBytes(ethutil.FromHex(data[2:])) - } else { - d.SetString(data, 0) - } +func (self *DebuggerWindow) SetCode(code string) { + self.win.Set("codeText", code) +} - return ethutil.BigToBytes(d, 256) +func (self *DebuggerWindow) SetData(data string) { + self.win.Set("dataText", data) } func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { @@ -63,22 +71,28 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.Db.Q <- true } - dataSlice := strings.Split(dataStr, "\n") - var data []byte - for _, dataItem := range dataSlice { - d := formatData(dataItem) - data = append(data, d...) - } - - state := self.lib.eth.BlockChain().CurrentBlock.State() - defer func() { if r := recover(); r != nil { fmt.Println(r) + self.Db.done = true } }() - script, err := ethutil.Compile(scriptStr) + data := ethutil.StringToByteFunc(dataStr, func(s string) (ret []byte) { + slice := strings.Split(dataStr, "\n") + for _, dataItem := range slice { + d := formatData(dataItem) + ret = append(ret, d...) + } + return + }) + + var err error + script := ethutil.StringToByteFunc(scriptStr, func(s string) (ret []byte) { + ret, err = ethutil.Compile(s) + return + }) + if err != nil { ethutil.Config.Log.Debugln(err) @@ -91,11 +105,13 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data for _, str := range dis { self.win.Root().Call("setAsm", str) } + // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) callerTx.Sign(keyPair.PrivateKey) + state := self.lib.eth.BlockChain().CurrentBlock.State() account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) contract := ethchain.MakeContract(callerTx, state) callerClosure := ethchain.NewClosure(account, contract, script, state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) -- cgit v1.2.3 From 1eda1d25b0d27fe57287698fb883c9153ddda292 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 28 May 2014 15:48:17 +0200 Subject: Hooked up the Block Explorer to the Debugger so we can instantly debug made transactions --- ethereal/ui/debugger.go | 6 ++++++ ethereal/ui/ui_lib.go | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 5b1fb50a2..342e3a7d0 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -65,6 +65,12 @@ 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.FromHex(data)) + for _, str := range dis { + self.win.Root().Call("setAsm", str) + } +} func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, dataStr string) { if !self.Db.done { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 998392525..73ec67c86 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -2,6 +2,7 @@ package ethui import ( "bitbucket.org/kardianos/osext" + "encoding/hex" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" @@ -24,8 +25,9 @@ type UiLib struct { connected bool assetPath string // The main application window - win *qml.Window - Db *Debugger + win *qml.Window + Db *Debugger + DbWindow *DebuggerWindow } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { @@ -88,9 +90,26 @@ func (ui *UiLib) ConnectToPeer(addr string) { func (ui *UiLib) AssetPath(p string) string { return path.Join(ui.assetPath, p) } +func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { + dbWindow := NewDebuggerWindow(self) + object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash)) + if len(object.Script()) > 0 { + dbWindow.SetCode("0x" + hex.EncodeToString(object.Script())) + } + dbWindow.SetData(data) + + dbWindow.Show() +} + +func (self *UiLib) StartDbWithCode(code string) { + dbWindow := NewDebuggerWindow(self) + dbWindow.SetCode("0x" + code) + dbWindow.Show() +} func (self *UiLib) StartDebugger() { dbWindow := NewDebuggerWindow(self) + //self.DbWindow = dbWindow dbWindow.Show() } -- cgit v1.2.3 From d4f9daa631fa832d556c16f3a29eaf73bd849f32 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 28 May 2014 16:14:24 +0200 Subject: Refactor hex encode and remove coupling of popup to main window --- ethereal/ui/ui_lib.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 73ec67c86..9c4301ffe 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -2,7 +2,6 @@ package ethui import ( "bitbucket.org/kardianos/osext" - "encoding/hex" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" @@ -94,7 +93,7 @@ func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { dbWindow := NewDebuggerWindow(self) object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash)) if len(object.Script()) > 0 { - dbWindow.SetCode("0x" + hex.EncodeToString(object.Script())) + dbWindow.SetCode("0x" + ethutil.Hex(object.Script())) } dbWindow.SetData(data) -- 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') 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 44db1a1eb20275349985f1f1b5eddd9a28731488 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 28 May 2014 18:11:27 +0200 Subject: Add 0x when feeding data to debugger --- ethereal/ui/ui_lib.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9c4301ffe..9f2cca1e0 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -95,7 +95,7 @@ func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { if len(object.Script()) > 0 { dbWindow.SetCode("0x" + ethutil.Hex(object.Script())) } - dbWindow.SetData(data) + dbWindow.SetData("0x" + data) dbWindow.Show() } -- 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/debugger.go | 46 ++++++++++++++++++---------------------------- ethereal/ui/gui.go | 2 +- 2 files changed, 19 insertions(+), 29 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 342e3a7d0..9bca7e4fe 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -5,27 +5,9 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "math/big" "strings" ) -func formatData(data string) []byte { - if len(data) == 0 { - return nil - } - // Simple stupid - d := new(big.Int) - if data[0:1] == "\"" && data[len(data)-1:] == "\"" { - d.SetBytes([]byte(data[1 : len(data)-1])) - } else if data[:2] == "0x" { - d.SetBytes(ethutil.FromHex(data[2:])) - } else { - d.SetString(data, 0) - } - - return ethutil.BigToBytes(d, 256) -} - type DebuggerWindow struct { win *qml.Window engine *qml.Engine @@ -77,17 +59,10 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.Db.Q <- true } - defer func() { - if r := recover(); r != nil { - fmt.Println(r) - self.Db.done = true - } - }() - data := ethutil.StringToByteFunc(dataStr, func(s string) (ret []byte) { slice := strings.Split(dataStr, "\n") for _, dataItem := range slice { - d := formatData(dataItem) + d := ethutil.FormatData(dataItem) ret = append(ret, d...) } return @@ -100,7 +75,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data }) if err != nil { - ethutil.Config.Log.Debugln(err) + self.Logln(err) return } @@ -130,11 +105,17 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data Coinbase: block.Coinbase, Time: block.Time, Diff: block.Difficulty, + Value: ethutil.Big(valueStr), }) self.Db.done = false go func() { - callerClosure.Call(vm, data, self.Db.halting) + ret, _, err := callerClosure.Call(vm, data, self.Db.halting) + if err != nil { + self.Logln("exited with errors:", err) + } else { + self.Logf("exited: %v", ret) + } state.Reset() @@ -142,6 +123,15 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data }() } +func (self *DebuggerWindow) Logf(format string, v ...interface{}) { + self.win.Root().Call("setLog", fmt.Sprintf(format, v...)) +} + +func (self *DebuggerWindow) Logln(v ...interface{}) { + str := fmt.Sprintln(v...) + self.Logf("%s", str[:len(str)-1]) +} + func (self *DebuggerWindow) Next() { self.Db.Next() } 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 0b4c42d75694787d47697288266c073a3cf41c48 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 29 May 2014 02:05:06 +0200 Subject: Disabled instruction selection --- ethereal/ui/debugger.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 9bca7e4fe..99dbabec0 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -71,6 +71,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) + fmt.Printf("%x\n", ret) return }) -- 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/debugger.go | 1 + ethereal/ui/gui.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 99dbabec0..a6b8e16d0 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -83,6 +83,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data dis := ethchain.Disassemble(script) self.win.Root().Call("clearAsm") + self.win.Root().Call("clearLog") for _, str := range dis { self.win.Root().Call("setAsm", str) 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') 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') 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') 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') 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') 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') 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') 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') 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') 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') 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 964587b14a52f5a64c166fe28cc5a51eb2bac1c7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 5 Jun 2014 09:00:57 +0200 Subject: Added more debugger output --- ethereal/ui/debugger.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index a6b8e16d0..eb68b51dc 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "math/big" "strings" ) @@ -89,15 +90,17 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.win.Root().Call("setAsm", str) } + gas := ethutil.Big(gasStr) + gasPrice := ethutil.Big(gasPriceStr) // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script) callerTx.Sign(keyPair.PrivateKey) state := self.lib.eth.BlockChain().CurrentBlock.State() account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) contract := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, contract, script, state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) + callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice) block := self.lib.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{ @@ -111,12 +114,18 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data }) self.Db.done = false + self.Logf("callsize %d", len(script)) go func() { - ret, _, err := callerClosure.Call(vm, data, self.Db.halting) + ret, g, err := callerClosure.Call(vm, data, self.Db.halting) + self.Logln("gas usage", g, "total price =", new(big.Int).Mul(g, gasPrice)) if err != nil { self.Logln("exited with errors:", err) } else { - self.Logf("exited: %v", ret) + if len(ret) > 0 { + self.Logf("exited: % x", ret) + } else { + self.Logf("exited: nil") + } } state.Reset() -- cgit v1.2.3 From cc20b0e3a0754c77fe04a8b5c5668d0eda955bcf Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 6 Jun 2014 12:13:13 +0200 Subject: debugger output --- ethereal/ui/debugger.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index eb68b51dc..a4489cdf4 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -117,7 +117,8 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.Logf("callsize %d", len(script)) go func() { ret, g, err := callerClosure.Call(vm, data, self.Db.halting) - self.Logln("gas usage", g, "total price =", new(big.Int).Mul(g, gasPrice)) + tot := new(big.Int).Mul(g, gasPrice) + self.Logf("gas usage %v total price = %v (%v)", g, tot, ethutil.CurrencyToString(tot)) if err != nil { self.Logln("exited with errors:", err) } else { -- 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/debugger.go | 38 +++++++++++++++++++++++++++++++------- ethereal/ui/gui.go | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index a4489cdf4..919407b34 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -26,7 +26,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { } win := component.CreateWindow(nil) - db := &Debugger{win, make(chan bool), make(chan bool), true} + db := &Debugger{win, make(chan bool), make(chan bool), true, false} return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db} } @@ -60,6 +60,12 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.Db.Q <- true } + defer func() { + if r := recover(); r != nil { + self.Logf("compile FAULT: %v", r) + } + }() + data := ethutil.StringToByteFunc(dataStr, func(s string) (ret []byte) { slice := strings.Split(dataStr, "\n") for _, dataItem := range slice { @@ -131,7 +137,11 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data state.Reset() - self.Db.done = true + if !self.Db.interrupt { + self.Db.done = true + } else { + self.Db.interrupt = false + } }() } @@ -149,10 +159,10 @@ func (self *DebuggerWindow) Next() { } type Debugger struct { - win *qml.Window - N chan bool - Q chan bool - done bool + win *qml.Window + N chan bool + Q chan bool + done, interrupt bool } type storeVal struct { @@ -185,7 +195,8 @@ out: case <-d.N: break out case <-d.Q: - d.done = true + d.interrupt = true + d.clearBuffers() return false } @@ -194,6 +205,19 @@ out: return true } +func (d *Debugger) clearBuffers() { +out: + // drain + for { + select { + case <-d.N: + case <-d.Q: + default: + break out + } + } +} + func (d *Debugger) Next() { if !d.done { d.N <- true 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') 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') 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') 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') 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 3ec0c719b99b6b14ed6c13128b2caec723bc4a93 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Jun 2014 13:47:18 +0200 Subject: Verbose logging --- ethereal/ui/debugger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 919407b34..9ebfc5fe7 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -78,7 +78,6 @@ 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) - fmt.Printf("%x\n", ret) return }) @@ -118,6 +117,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data Diff: block.Difficulty, Value: ethutil.Big(valueStr), }) + vm.Verbose = true self.Db.done = false self.Logf("callsize %d", len(script)) -- cgit v1.2.3 From c89566a42f984e4441c3398c3c136baa7cd46ac4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 20 Jun 2014 00:42:53 +0200 Subject: Removed old debugger code --- ethereal/ui/debugger.go | 3 ++- ethereal/ui/ui_lib.go | 51 ------------------------------------------------- 2 files changed, 2 insertions(+), 52 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 9ebfc5fe7..9d60c7587 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -109,8 +109,9 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data block := self.lib.eth.BlockChain().CurrentBlock vm := ethchain.NewVm(state, self.lib.eth.StateManager(), ethchain.RuntimeVars{ + Block: block, Origin: account.Address(), - BlockNumber: block.BlockInfo().Number, + BlockNumber: block.Number, PrevHash: block.PrevHash, Coinbase: block.Coinbase, Time: block.Time, diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9f2cca1e0..791d4fe09 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -3,7 +3,6 @@ package ethui import ( "bitbucket.org/kardianos/osext" "github.com/ethereum/eth-go" - "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" "os" @@ -138,53 +137,3 @@ func DefaultAssetPath() string { return base } - -func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) { - state := ui.eth.BlockChain().CurrentBlock.State() - - script, err := ethutil.Compile(data) - if err != nil { - ethutil.Config.Log.Debugln(err) - - return - } - - dis := ethchain.Disassemble(script) - ui.win.Root().Call("clearAsm") - - for _, str := range dis { - ui.win.Root().Call("setAsm", str) - } - // Contract addr as test address - keyPair := ethutil.GetKeyRing().Get(0) - callerTx := - ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), script) - callerTx.Sign(keyPair.PrivateKey) - - account := ui.eth.StateManager().TransState().GetStateObject(keyPair.Address()) - contract := ethchain.MakeContract(callerTx, state) - callerClosure := ethchain.NewClosure(account, contract, contract.Init(), state, ethutil.Big(gasStr), ethutil.Big(gasPriceStr)) - - block := ui.eth.BlockChain().CurrentBlock - vm := ethchain.NewVm(state, ui.eth.StateManager(), ethchain.RuntimeVars{ - Origin: account.Address(), - BlockNumber: block.BlockInfo().Number, - PrevHash: block.PrevHash, - Coinbase: block.Coinbase, - Time: block.Time, - Diff: block.Difficulty, - }) - - ui.Db.done = false - go func() { - callerClosure.Call(vm, contract.Init(), ui.Db.halting) - - state.Reset() - - ui.Db.done = true - }() -} - -func (ui *UiLib) Next() { - ui.Db.Next() -} -- 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') 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 +++++++++++++++++++++++++------------------ ethereal/ui/html_container.go | 4 +-- ethereal/ui/ui_lib.go | 6 ++--- 3 files changed, 38 insertions(+), 29 deletions(-) (limited to 'ethereal/ui') 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) + } } diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 3867c0353..d7dc80af7 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -96,11 +96,11 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) { app.watcher.Close() break out case <-app.watcher.Event: - //ethutil.Config.Log.Debugln("Got event:", ev) + //logger.Debugln("Got event:", ev) app.webView.Call("reload") case err := <-app.watcher.Error: // TODO: Do something here - ethutil.Config.Log.Infoln("Watcher error:", err) + logger.Infoln("Watcher error:", err) } } }() diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9f2cca1e0..eb607aac5 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -40,7 +40,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func (ui *UiLib) Open(path string) { component, err := ui.engine.LoadFile(path[7:]) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) } win := component.CreateWindow(nil) @@ -60,7 +60,7 @@ func (ui *UiLib) OpenHtml(path string) { func (ui *UiLib) Muted(content string) { component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) return } @@ -144,7 +144,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) script, err := ethutil.Compile(data) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) return } -- cgit v1.2.3 From 1024766514eea7bb628ec6e5ed974e997b8faefc Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:20:59 +0100 Subject: refactor cli and gui wrapper code. Details: - all cli functions shared between ethereum and ethereal abstracted to utils/ cmd.go (should be ethcommon or shared or sth) - simplify main() now readable stepwise - rename main wrapper files to main.go - rename commmand line args definition file from config.go to flags.go - rename Do -> Start to parallel option names - register interrupt for rpc server stop - fix interrupt stopping js repl and ethereum - register interrupt for mining stop - custom config file option from command line - debug option from command line - loglevel option from command line - changed ethutil.Config API - default datadir and default config file set together with other flag defaults in wrappers - default assetpath set together with other command line flags defaults in gui wrapper (not in ethutil.Config or ui/ui_lib) - options precedence: default < config file < environment variables < command line --- ethereal/ui/ui_lib.go | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 2dd66f4fd..156d55157 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -29,9 +29,6 @@ type UiLib struct { } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { - if assetPath == "" { - assetPath = DefaultAssetPath() - } return &UiLib{engine: engine, eth: eth, assetPath: assetPath} } @@ -88,6 +85,7 @@ func (ui *UiLib) ConnectToPeer(addr string) { func (ui *UiLib) AssetPath(p string) string { return path.Join(ui.assetPath, p) } + func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { dbWindow := NewDebuggerWindow(self) object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash)) @@ -111,29 +109,3 @@ func (self *UiLib) StartDebugger() { dbWindow.Show() } - -func DefaultAssetPath() string { - var base string - // If the current working directory is the go-ethereum dir - // assume a debug build and use the source directory as - // asset directory. - pwd, _ := os.Getwd() - if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal") { - base = path.Join(pwd, "assets") - } else { - switch runtime.GOOS { - case "darwin": - // Get Binary Directory - exedir, _ := osext.ExecutableFolder() - base = filepath.Join(exedir, "../Resources") - case "linux": - base = "/usr/share/ethereal" - case "window": - fallthrough - default: - base = "." - } - } - - return base -} -- 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 ++-- ethereal/ui/ui_lib.go | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'ethereal/ui') 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) { diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 156d55157..5f6a9ef0b 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -1,14 +1,10 @@ package ethui import ( - "bitbucket.org/kardianos/osext" "github.com/ethereum/eth-go" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "os" "path" - "path/filepath" - "runtime" ) type memAddr struct { -- cgit v1.2.3 From f6aabb7a90903a681eca44976301620756124137 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 23 Jun 2014 16:25:57 +0200 Subject: Implements QML Apps. Implements #47 You are welcome Stephan. --- ethereal/ui/qml_app.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ ethereal/ui/ui_lib.go | 15 ++++--------- 2 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 ethereal/ui/qml_app.go (limited to 'ethereal/ui') diff --git a/ethereal/ui/qml_app.go b/ethereal/ui/qml_app.go new file mode 100644 index 000000000..d47751616 --- /dev/null +++ b/ethereal/ui/qml_app.go @@ -0,0 +1,59 @@ +package ethui + +import ( + "github.com/ethereum/eth-go/ethchain" + "github.com/ethereum/eth-go/ethpub" + "github.com/ethereum/eth-go/ethutil" + "github.com/go-qml/qml" +) + +type QmlApplication struct { + win *qml.Window + engine *qml.Engine + lib *UiLib + path string +} + +func NewQmlApplication(path string, lib *UiLib) *QmlApplication { + engine := qml.NewEngine() + return &QmlApplication{engine: engine, path: path, lib: lib} +} + +func (app *QmlApplication) Create() error { + component, err := app.engine.LoadFile(app.path) + if err != nil { + ethutil.Config.Log.Debugln(err) + } + app.win = component.CreateWindow(nil) + + return nil +} + +func (app *QmlApplication) Destroy() { + app.engine.Destroy() +} + +func (app *QmlApplication) NewWatcher(quitChan chan bool) { +} + +// Events +func (app *QmlApplication) NewBlock(block *ethchain.Block) { + pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + app.win.Call("onNewBlockCb", pblock) +} + +func (app *QmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { + app.win.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject)) +} + +func (app *QmlApplication) StorageChanged(storageObject *ethchain.StorageState) { + app.win.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject)) +} + +// Getters +func (app *QmlApplication) Engine() *qml.Engine { + return app.engine +} +func (app *QmlApplication) Window() *qml.Window { + return app.win +} diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 791d4fe09..908497be3 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -35,18 +35,11 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { return &UiLib{engine: engine, eth: eth, assetPath: assetPath} } -// Opens a QML file (external application) -func (ui *UiLib) Open(path string) { - component, err := ui.engine.LoadFile(path[7:]) - if err != nil { - ethutil.Config.Log.Debugln(err) - } - win := component.CreateWindow(nil) +func (ui *UiLib) OpenQml(path string) { + container := NewQmlApplication(path[7:], ui) + app := NewExtApplication(container, ui) - go func() { - win.Show() - win.Wait() - }() + go app.run() } func (ui *UiLib) OpenHtml(path string) { -- cgit v1.2.3 From 9a06efd0809c370451c5e85ce4688104cd5df461 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 25 Jun 2014 18:28:38 +0100 Subject: new logger API for upstream merge --- ethereal/ui/qml_app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/qml_app.go b/ethereal/ui/qml_app.go index d47751616..39ab7f922 100644 --- a/ethereal/ui/qml_app.go +++ b/ethereal/ui/qml_app.go @@ -22,7 +22,7 @@ func NewQmlApplication(path string, lib *UiLib) *QmlApplication { func (app *QmlApplication) Create() error { component, err := app.engine.LoadFile(app.path) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Warnln(err) } app.win = component.CreateWindow(nil) -- 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/debugger.go | 26 +++++++++++++++----------- ethereal/ui/gui.go | 4 ---- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 9d60c7587..f49741e09 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -26,7 +26,7 @@ func NewDebuggerWindow(lib *UiLib) *DebuggerWindow { } win := component.CreateWindow(nil) - db := &Debugger{win, make(chan bool), make(chan bool), true, false} + db := &Debugger{win, make(chan bool), make(chan bool), true, false, true} return &DebuggerWindow{engine: engine, win: win, lib: lib, Db: db} } @@ -59,6 +59,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data if !self.Db.done { self.Db.Q <- true } + self.Db.breakOnInstr = self.win.Root().ObjectByName("breakEachLine").Bool("checked") defer func() { if r := recover(); r != nil { @@ -164,6 +165,7 @@ type Debugger struct { N chan bool Q chan bool done, interrupt bool + breakOnInstr bool } type storeVal struct { @@ -190,16 +192,18 @@ func (d *Debugger) halting(pc int, op ethchain.OpCode, mem *ethchain.Memory, sta d.win.Root().Call("setStorage", storeVal{fmt.Sprintf("% x", key), fmt.Sprintf("% x", node.Str())}) }) -out: - for { - select { - case <-d.N: - break out - case <-d.Q: - d.interrupt = true - d.clearBuffers() - - return false + if d.breakOnInstr { + out: + for { + select { + case <-d.N: + break out + case <-d.Q: + d.interrupt = true + d.clearBuffers() + + return false + } } } 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 b89076faa2748a41031c4bc33bbdeba3e2effd01 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Jun 2014 12:10:11 +0200 Subject: Added amount to contract during debugging --- ethereal/ui/debugger.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index f49741e09..85dd45563 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -96,16 +96,20 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data self.win.Root().Call("setAsm", str) } - gas := ethutil.Big(gasStr) - gasPrice := ethutil.Big(gasPriceStr) - // Contract addr as test address - keyPair := ethutil.GetKeyRing().Get(0) - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script) + var ( + gas = ethutil.Big(gasStr) + gasPrice = ethutil.Big(gasPriceStr) + value = ethutil.Big(valueStr) + // Contract addr as test address + keyPair = ethutil.GetKeyRing().Get(0) + callerTx = ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script) + ) callerTx.Sign(keyPair.PrivateKey) state := self.lib.eth.BlockChain().CurrentBlock.State() account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address()) contract := ethchain.MakeContract(callerTx, state) + contract.Amount = value callerClosure := ethchain.NewClosure(account, contract, script, state, gas, gasPrice) block := self.lib.eth.BlockChain().CurrentBlock -- 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') 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') 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') 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') 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 29cc1af2bc8d4a516e30abba9155584d7df8dd83 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 20:34:07 +0100 Subject: remove ui/library; instead expose gui itself for initial window --- ethereal/ui/library.go | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 ethereal/ui/library.go (limited to 'ethereal/ui') diff --git a/ethereal/ui/library.go b/ethereal/ui/library.go deleted file mode 100644 index 267108195..000000000 --- a/ethereal/ui/library.go +++ /dev/null @@ -1,46 +0,0 @@ -package ethui - -import ( - "fmt" - "github.com/ethereum/eth-go/ethchain" - "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/go-ethereum/utils" - "github.com/obscuren/secp256k1-go" - "strings" -) - -type EthLib struct { - stateManager *ethchain.StateManager - blockChain *ethchain.BlockChain - txPool *ethchain.TxPool - Db *Debugger -} - -func (lib *EthLib) ImportAndSetPrivKey(privKey string) bool { - fmt.Println(privKey) - mnemonic := strings.Split(privKey, " ") - if len(mnemonic) == 24 { - fmt.Println("Got mnemonic key, importing.") - key := ethutil.MnemonicDecode(mnemonic) - utils.ImportPrivateKey(key) - } else if len(mnemonic) == 1 { - fmt.Println("Got hex key, importing.") - utils.ImportPrivateKey(privKey) - } else { - fmt.Println("Did not recognise format, exiting.") - return false - } - return true -} - -func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) { - _, prv := secp256k1.GenerateKeyPair() - keyPair, err := ethutil.GetKeyRing().NewKeyPair(prv) - if err != nil { - panic(err) - } - - mne := ethutil.MnemonicEncode(ethutil.Hex(keyPair.PrivateKey)) - mnemonicString := strings.Join(mne, " ") - return mnemonicString, fmt.Sprintf("%x", keyPair.Address()), ethutil.Hex(keyPair.PrivateKey), ethutil.Hex(keyPair.PublicKey) -} -- 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') 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 From 098f7f23ce62d3f0c60d30d325576de93795cc4b Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 20:39:45 +0100 Subject: changed name for ethutil hex functions; and access to keyring via keyManager --- ethereal/ui/debugger.go | 4 ++-- ethereal/ui/ext_app.go | 4 ++-- ethereal/ui/html_container.go | 2 +- ethereal/ui/qml_app.go | 2 +- ethereal/ui/ui_lib.go | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'ethereal/ui') diff --git a/ethereal/ui/debugger.go b/ethereal/ui/debugger.go index 85dd45563..5ad1b4a2c 100644 --- a/ethereal/ui/debugger.go +++ b/ethereal/ui/debugger.go @@ -49,7 +49,7 @@ func (self *DebuggerWindow) SetData(data string) { self.win.Set("dataText", data) } func (self *DebuggerWindow) SetAsm(data string) { - dis := ethchain.Disassemble(ethutil.FromHex(data)) + dis := ethchain.Disassemble(ethutil.Hex2Bytes(data)) for _, str := range dis { self.win.Root().Call("setAsm", str) } @@ -101,7 +101,7 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data gasPrice = ethutil.Big(gasPriceStr) value = ethutil.Big(valueStr) // Contract addr as test address - keyPair = ethutil.GetKeyRing().Get(0) + keyPair = self.lib.eth.KeyManager().KeyPair() callerTx = ethchain.NewContractCreationTx(ethutil.Big(valueStr), gas, gasPrice, script) ) callerTx.Sign(keyPair.PrivateKey) diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index d1a256cdb..0230c46ab 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -121,10 +121,10 @@ out: func (app *ExtApplication) Watch(addr, storageAddr string) { var event string if len(storageAddr) == 0 { - event = "object:" + string(ethutil.FromHex(addr)) + event = "object:" + string(ethutil.Hex2Bytes(addr)) app.lib.eth.Reactor().Subscribe(event, app.changeChan) } else { - event = "storage:" + string(ethutil.FromHex(addr)) + ":" + string(ethutil.FromHex(storageAddr)) + event = "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr)) app.lib.eth.Reactor().Subscribe(event, app.changeChan) } diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index d7dc80af7..f2ebd840c 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -116,7 +116,7 @@ func (app *HtmlApplication) Window() *qml.Window { } func (app *HtmlApplication) NewBlock(block *ethchain.Block) { - b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())} app.webView.Call("onNewBlockCb", b) } diff --git a/ethereal/ui/qml_app.go b/ethereal/ui/qml_app.go index 39ab7f922..d23fdd110 100644 --- a/ethereal/ui/qml_app.go +++ b/ethereal/ui/qml_app.go @@ -38,7 +38,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) { // Events func (app *QmlApplication) NewBlock(block *ethchain.Block) { - pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + pblock := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())} app.win.Call("onNewBlockCb", pblock) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index ddc955176..892c1f065 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -77,9 +77,9 @@ func (ui *UiLib) AssetPath(p string) string { func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { dbWindow := NewDebuggerWindow(self) - object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.FromHex(contractHash)) + object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash)) if len(object.Script()) > 0 { - dbWindow.SetCode("0x" + ethutil.Hex(object.Script())) + dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Script())) } dbWindow.SetData("0x" + data) -- cgit v1.2.3