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/config.go | 2 ++ ethereal/ethereum.go | 4 ++-- ethereal/ui/gui.go | 11 +++++++---- ethereal/ui/ui_lib.go | 14 +++++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) (limited to 'ethereal') diff --git a/ethereal/config.go b/ethereal/config.go index a534bb182..ac4484d0b 100644 --- a/ethereal/config.go +++ b/ethereal/config.go @@ -16,6 +16,7 @@ var UseSeed bool var ImportKey string var ExportKey bool var DataDir string +var AssetPath string func Init() { flag.BoolVar(&StartConsole, "c", false, "debug and testing console") @@ -29,6 +30,7 @@ func Init() { flag.StringVar(&DataDir, "dir", ".ethereal", "ethereum data directory") flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers") + flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory") flag.Parse() } diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go index 618d2b00f..99f3b0b52 100644 --- a/ethereal/ethereum.go +++ b/ethereal/ethereum.go @@ -100,11 +100,11 @@ func main() { os.Exit(0) } - log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver) + log.Printf("Starting Ethereum GUI v%s\n", ethutil.Config.Ver) // Set the max peers ethereum.MaxPeers = MaxPeer gui := ethui.New(ethereum) - gui.Start() + gui.Start(AssetPath) } 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/assets/qml/wallet.qml | 29 +++++++++++++++++++------ ethereal/ui/library.go | 48 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 7 deletions(-) (limited to 'ethereal') diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index 7fc7f5447..f6b31f0fd 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -158,20 +158,35 @@ ApplicationWindow { anchors.leftMargin: 5 anchors.topMargin: 5 TextField { - id: txAmount + id: txRecipient + placeholderText: "Recipient address (or empty for contract)" + Layout.fillWidth: true + } + + TextField { + id: txValue width: 200 placeholderText: "Amount" } - TextField { - id: txReceiver - placeholderText: "Receiver Address (or empty for contract)" - Layout.fillWidth: true + id: txGas + width: 200 + placeholderText: "Gas" + anchors.left: txValue + anchors.leftMargin: 5 + } + TextField { + id: txGasPrice + width: 200 + placeholderText: "Gas price" + anchors.left: txGas + anchors.leftMargin: 5 } Label { text: "Transaction data" } + TextArea { id: codeView anchors.topMargin: 5 @@ -180,9 +195,11 @@ ApplicationWindow { } Button { + id: txButton text: "Send" onClicked: { - console.log(eth.createTx(txReceiver.text, txAmount.text, codeView.text)) + this.enabled = false + console.log(eth.createTx(txRecipient.text, txValue.text, txGas.text, txGasPrice.text, codeView.text)) } } } 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') 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/assets/qml/wallet.qml | 2 +- ethereal/ui/library.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'ethereal') diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index f6b31f0fd..9093e3ca8 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -198,7 +198,7 @@ ApplicationWindow { id: txButton text: "Send" onClicked: { - this.enabled = false + //this.enabled = false console.log(eth.createTx(txRecipient.text, txValue.text, txGas.text, txGasPrice.text, codeView.text)) } } 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