Fix merge conflict

This commit is contained in:
Maran
2014-04-01 13:18:42 +02:00
9 changed files with 116 additions and 40 deletions

View File

@@ -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)

View File

@@ -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(gasStr)
gasPrice := ethutil.Big(gasPriceStr)
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.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)

View File

@@ -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
// assume a debug build and use the source directory as
@@ -71,5 +79,5 @@ func AssetPath(p string) string {
}
}
return path.Join(base, p)
return base
}