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
pull/32/head
obscuren 11 years ago
parent 1257e8b4b3
commit c5215fd4fb
  1. 29
      ethereal/assets/qml/wallet.qml
  2. 48
      ethereal/ui/library.go
  3. 6
      ethereum/dev_console.go

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

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

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

Loading…
Cancel
Save