aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-03-28 02:41:42 +0800
committerobscuren <geffobscura@gmail.com>2014-03-28 02:41:42 +0800
commitc5215fd4fb9de7594fdb812f8f9e4c471ee8d003 (patch)
tree4d301432a63fee2049c12caebb04d18a3480545a
parent1257e8b4b30293784d24011ab6f9d8b4498ecfa4 (diff)
downloadgo-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar.gz
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar.bz2
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar.lz
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar.xz
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.tar.zst
go-tangerine-c5215fd4fb9de7594fdb812f8f9e4c471ee8d003.zip
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
-rw-r--r--ethereal/assets/qml/wallet.qml29
-rw-r--r--ethereal/ui/library.go48
-rw-r--r--ethereum/dev_console.go6
3 files changed, 75 insertions, 8 deletions
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)
diff --git a/ethereum/dev_console.go b/ethereum/dev_console.go
index 5452b9a61..5fdf90509 100644
--- a/ethereum/dev_console.go
+++ b/ethereum/dev_console.go
@@ -190,7 +190,11 @@ func (i *Console) ParseInput(input string) bool {
}
case "contract":
fmt.Println("Contract editor (Ctrl-D = done)")
- asm := mutan.NewCompiler().Compile(strings.NewReader(i.Editor()))
+ asm, err := mutan.NewCompiler().Compile(strings.NewReader(i.Editor()))
+ if err != nil {
+ fmt.Println(err)
+ break
+ }
code := ethutil.Assemble(asm)