Merge branch 'develop' into feature/rpc

This commit is contained in:
Maran 2014-05-02 13:35:44 +02:00
commit 60f9966cd8
16 changed files with 352 additions and 253 deletions

View File

@ -12,7 +12,15 @@ For the development package please see the [eth-go package](https://github.com/e
Build Build
======= =======
For build instruction please see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)) To build Ethereal (GUI):
`go get github.com/ethereum/go-ethereum/ethereal`
To build the node (CLI):
`go get github.com/ethereum/go-ethereum/ethereum`
For further, detailed, build instruction please see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go))
General command line options General command line options
==================== ====================

View File

@ -19,8 +19,7 @@ window.eth = {
// Create transaction // Create transaction
// //
// Creates a transaction with the current account // Transact between two state objects
// If no recipient is set, the Ethereum API will see it as a contract creation
transact: function(sec, recipient, value, gas, gasPrice, data, cb) { transact: function(sec, recipient, value, gas, gasPrice, data, cb) {
postData({call: "transact", args: [sec, recipient, value, gas, gasPrice, data]}, cb); postData({call: "transact", args: [sec, recipient, value, gas, gasPrice, data]}, cb);
}, },
@ -71,6 +70,10 @@ window.eth = {
postData({call: "disconnect", args: [address, storageAddrOrCb]}); postData({call: "disconnect", args: [address, storageAddrOrCb]});
}, },
set: function(props) {
postData({call: "set", args: props});
},
on: function(event, cb) { on: function(event, cb) {
if(eth._onCallbacks[event] === undefined) { if(eth._onCallbacks[event] === undefined) {
eth._onCallbacks[event] = []; eth._onCallbacks[event] = [];
@ -110,7 +113,7 @@ function debug(/**/) {
var args = arguments; var args = arguments;
var msg = "" var msg = ""
for(var i = 0; i < args.length; i++){ for(var i = 0; i < args.length; i++){
if(typeof args[i] == "object") { if(typeof args[i] === "object") {
msg += " " + JSON.stringify(args[i]) msg += " " + JSON.stringify(args[i])
} else { } else {
msg += args[i] msg += args[i]
@ -151,3 +154,60 @@ navigator.qt.onmessage = function(ev) {
} }
} }
} }
window.eth._0 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
String.prototype.pad = function(len) {
var bin = this.bin();
var l = bin.length;
if(l < 32) {
return eth._0.substr(0, 32 - bin.length) + bin;
}
return bin;
}
String.prototype.unpad = function() {
var i, l;
for(i = 0, l = this.length; i < l; i++) {
if(this[i] != "\0") {
return this.substr(i, this.length);
}
}
return this.substr(i, this.length);
}
String.prototype.bin = function() {
if(this.substr(0, 2) == "0x") {
return this.hex2bin();
} else if(/^\d+$/.test(this)) {
return this.num2bin()
}
// Otherwise we'll return the "String" object instead of an actual string
return this.substr(0, this.length)
}
String.prototype.unbin = function() {
var i, l, o = '';
for(i = 0, l = this.length; i < l; i++) {
var n = this.charCodeAt(i).toString(16);
o += n.length < 2 ? '0' + n : n;
}
return "0x" + o;
}
String.prototype.hex2bin = function() {
bytes = []
for(var i=2; i< this.length-1; i+=2) {
bytes.push(parseInt(this.substr(i, 2), 16));
}
return String.fromCharCode.apply(String, bytes);
}
String.prototype.num2bin = function() {
return ("0x"+parseInt(this).toString(16)).bin()
}

View File

@ -60,6 +60,7 @@ ApplicationWindow {
var tx = eth.transact(data.args[0], data.args[1], data.args[2],data.args[3],data.args[4],data.args[5]) var tx = eth.transact(data.args[0], data.args[1], data.args[2],data.args[3],data.args[4],data.args[5])
postData(data._seed, tx) postData(data._seed, tx)
break break
case "create": case "create":
postData(data._seed, null) postData(data._seed, null)
@ -91,6 +92,12 @@ ApplicationWindow {
require(1) require(1)
postData(data._seed, null) postData(data._seed, null)
break; break;
case "set":
for(var key in data.args) {
if(webview.hasOwnProperty(key)) {
window[key] = data.args[key];
}
}
} }
} catch(e) { } catch(e) {
console.log(data.call + ": " + e) console.log(data.call + ": " + e)
@ -117,6 +124,8 @@ ApplicationWindow {
function onObjectChangeCb(stateObject) { function onObjectChangeCb(stateObject) {
postEvent("object:"+stateObject.address(), stateObject) postEvent("object:"+stateObject.address(), stateObject)
} }
function onStorageChangeCb() {
}
} }
Rectangle { Rectangle {

View File

@ -1,69 +0,0 @@
<html>
<head>
<title>jeffcoin</title>
<script type="text/javascript">
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d"
function createTransaction() {
var addr = document.querySelector("#addr").value;
var amount = document.querySelector("#amount").value;
var data = "0x" + addr + "\n" + amount
eth.transact("", jefcoinAddr, 0, "10000000", "250", data, function(tx) {
debug("received tx hash:", tx)
})
}
// Any test related actions here please
function tests() {
eth.getKey(function(keys) {
debug(keys)
})
}
function init() {
eth.getKey(function(key) {
eth.getStorageAt(jefcoinAddr, key, function(storage) {
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage;
});
eth.watch(jefcoinAddr, function(stateObject) {
eth.getStorageAt(jefcoinAddr, key, function(storage) {
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage;
});
});
eth.getBalanceAt(key, function(balance) {
debug("balance", balance);
})
});
}
</script>
<style type="text/css">
input[type="text"] {
width: 300px;
}
</style>
</head>
<body onload="init();">
<h1>Jeff Coin</h1>
<img src="icon.png">
<div id="currentAmount"></div>
<div id="transactions">
<input id="addr" type="text" placeholder="Receiver address"></input><br>
<input id="amount" type="text" placeholder="Amount"></input><br>
<button onclick="createTransaction();">Send Tx</button>
</div>
<div><button onclick="tests();">Tests</button></div>
<div id="debug" style="border: 1px solid block"></div>
</body>
</html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 85 KiB

View File

@ -0,0 +1,34 @@
/* Space out content a bit */
body {
padding-top: 20px;
padding-bottom: 20px;
}
/* Everything but the jumbotron gets side spacing for mobile first
* views */
.header,
.marketing,
.footer {
padding-right: 15px;
padding-left: 15px;
}
/* Custom page header */
.header {
border-bottom: 1px solid #e5e5e5;
}
/* Make the masthead heading the same height as the navigation */
.header h3 {
padding-bottom: 19px;
margin-top: 0;
margin-bottom: 0;
line-height: 40px;
}
.jumbotron {
text-align: center;
border-bottom: 1px solid #e5e5e5;
margin: 0 auto;
width: 300px;
}

View File

@ -0,0 +1,70 @@
<html>
<head>
<title>jeffcoin</title>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-theme.min.css">
<link rel="stylesheet" href="samplecoin.css">
<meta name="viewport" content="minimum-scale=1; maximum-scale=1; initial-scale=1;">
<script type="text/javascript">
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d"
var mAddr = ""
function createTransaction() {
var addr = document.querySelector("#addr").value;
var amount = document.querySelector("#amount").value;
var data = (("0x"+addr).pad(32) + amount.pad(32)).unbin()
eth.transact(mAddr, jefcoinAddr, 0, "10000000", "250", data, function(tx) {
debug("received tx hash:", tx)
})
}
function init() {
eth.set({width: 500})
eth.getKey(function(keyPair) {
mAddr = keyPair.privateKey;
eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
document.querySelector("#current-amount").innerHTML = storage;
});
eth.watch(jefcoinAddr, function(stateObject) {
eth.getStorageAt(jefcoinAddr, keyPair.address, function(storage) {
document.querySelector("#current-amount").innerHTML = storage;
});
});
});
}
</script>
</head>
<body onload="init();">
<div class="container">
<div class="header">
<h3 class="text-muted">JeffCoin</h3>
</div>
<div class="jumbotron ">
<img src="icon.png">
<div>Amount: <strong id="current-amount"></strong></div>
<div id="transactions">
<div class="form-group">
<input id="addr" class="form-control" type="text" placeholder="Receiver address"></input><br>
<input id="amount" class="form-control" type="text" placeholder="Amount"></input><br>
</div>
<button class="btn btn-default" onclick="createTransaction();">Send Tx</button>
</div>
</div>
</div>
<div id="debug" style="border: 1px solid black; min-height: 30px;"></div>
</body>
</html>

View File

@ -1,55 +0,0 @@
<html>
<head>
<title>jeffcoin</title>
<script type="text/javascript">
var jefcoinAddr = "3dff537f51350239abc95c76a5864aa605259e7d"
function createTransaction() {
var addr = document.querySelector("#addr").value;
var amount = document.querySelector("#amount").value;
var data = "0x" + addr + "\n" + amount
eth.createTx(jefcoinAddr, 0, "10000000", "250", data, function(tx) {
debug("received tx hash:", tx)
})
}
function init() {
eth.getKey(function(key) {
eth.getStorage(jefcoinAddr, key, function(storage) {
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage;
});
eth.on("block:new", function() {
eth.getStorage(jefcoinAddr, key, function(storage) {
document.querySelector("#currentAmount").innerHTML = "Amount: " + storage;
});
});
});
}
</script>
<style type="text/css">
input[type="text"] {
width: 300px;
}
</style>
</head>
<body onload="init();">
<h1>Jeff Coin</h1>
<img src="icon.png">
<div id="currentAmount"></div>
<div id="transactions">
<input id="addr" type="text" placeholder="Receiver address"></input><br>
<input id="amount" type="text" placeholder="Amount"></input><br>
<button onclick="createTransaction();">Send Tx</button>
</div>
<div id="debug" style="border: 1px solid block"></div>
</body>
</html>

View File

@ -2,13 +2,11 @@ package ethui
import ( import (
"fmt" "fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils" "github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml" "github.com/go-qml/qml"
"math/big" "math/big"
"strings"
) )
type AppContainer interface { type AppContainer interface {
@ -24,7 +22,7 @@ type AppContainer interface {
} }
type ExtApplication struct { type ExtApplication struct {
*QEthereum *utils.PEthereum
blockChan chan ethutil.React blockChan chan ethutil.React
changeChan chan ethutil.React changeChan chan ethutil.React
@ -37,7 +35,7 @@ type ExtApplication struct {
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
app := &ExtApplication{ app := &ExtApplication{
NewQEthereum(lib.eth), utils.NewPEthereum(lib.eth),
make(chan ethutil.React, 1), make(chan ethutil.React, 1),
make(chan ethutil.React, 1), make(chan ethutil.React, 1),
make(chan bool), make(chan bool),
@ -127,93 +125,3 @@ func (app *ExtApplication) Watch(addr, storageAddr string) {
app.registeredEvents = append(app.registeredEvents, event) 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
}

View File

@ -7,6 +7,7 @@ import (
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml" "github.com/go-qml/qml"
"math/big" "math/big"
"strings" "strings"
@ -56,9 +57,9 @@ func (ui *Gui) Start(assetPath string) {
// Register ethereum functions // Register ethereum functions
qml.RegisterTypes("Ethereum", 1, 0, []qml.TypeSpec{{ 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")) ethutil.Config.SetClientString(fmt.Sprintf("/Ethereal v%s", "0.2"))
@ -129,13 +130,13 @@ func (ui *Gui) readPreviousTransactions() {
for it.Next() { for it.Next() {
tx := ethchain.NewTransactionFromBytes(it.Value()) tx := ethchain.NewTransactionFromBytes(it.Value())
ui.win.Root().Call("addTx", NewQTx(tx)) ui.win.Root().Call("addTx", utils.NewPTx(tx))
} }
it.Release() it.Release()
} }
func (ui *Gui) ProcessBlock(block *ethchain.Block) { 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 // 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 txMsg.Type == ethchain.TxPre {
if bytes.Compare(tx.Sender(), ui.addr) == 0 && addrState.Nonce <= tx.Nonce { 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()) ui.txDb.Put(tx.Hash(), tx.RlpEncode())
addrState.Nonce += 1 addrState.Nonce += 1
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) unconfirmedFunds.Sub(unconfirmedFunds, tx.Value)
} else if bytes.Compare(tx.Recipient, ui.addr) == 0 { } 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()) ui.txDb.Put(tx.Hash(), tx.RlpEncode())
unconfirmedFunds.Add(unconfirmedFunds, tx.Value) unconfirmedFunds.Add(unconfirmedFunds, tx.Value)

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/go-qml/qml" "github.com/go-qml/qml"
"math/big" "math/big"
"path/filepath" "path/filepath"
@ -56,12 +57,12 @@ func (app *HtmlApplication) Window() *qml.Window {
} }
func (app *HtmlApplication) NewBlock(block *ethchain.Block) { 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) app.webView.Call("onNewBlockCb", b)
} }
func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) { 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) { func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) {

View File

@ -47,14 +47,14 @@ func (lib *EthLib) GetKey() string {
return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address()) 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)) stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address))
if stateObject != nil { if stateObject != nil {
return NewQStateObject(stateObject) return utils.NewPStateObject(stateObject)
} }
// See GetStorage for explanation on "nil" // See GetStorage for explanation on "nil"
return NewQStateObject(nil) return utils.NewPStateObject(nil)
} }
func (lib *EthLib) Watch(addr, storageAddr string) { 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 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) hash, err := hex.DecodeString(hexHash)
if err != nil { if err != nil {
return nil return nil
@ -123,5 +123,5 @@ func (lib *EthLib) GetBlock(hexHash string) *QBlock {
block := lib.blockChain.GetBlock(hash) 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())}
} }

110
utils/ethereum.go Normal file
View File

@ -0,0 +1,110 @@
package utils
import (
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
)
type PEthereum struct {
stateManager *ethchain.StateManager
blockChain *ethchain.BlockChain
txPool *ethchain.TxPool
}
func NewPEthereum(eth *eth.Ethereum) *PEthereum {
return &PEthereum{
eth.StateManager(),
eth.BlockChain(),
eth.TxPool(),
}
}
func (lib *PEthereum) GetBlock(hexHash string) *PBlock {
hash := ethutil.FromHex(hexHash)
block := lib.blockChain.GetBlock(hash)
return &PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
}
func (lib *PEthereum) GetKey() *PKey {
keyPair, err := ethchain.NewKeyPairFromSec(ethutil.Config.Db.GetKeys()[0].PrivateKey)
if err != nil {
return nil
}
return NewPKey(keyPair)
}
func (lib *PEthereum) GetStateObject(address string) *PStateObject {
stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address))
if stateObject != nil {
return NewPStateObject(stateObject)
}
// See GetStorage for explanation on "nil"
return NewPStateObject(nil)
}
func (lib *PEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
return lib.createTx(key, recipient, valueStr, gasStr, gasPriceStr, dataStr, "")
}
func (lib *PEthereum) Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr string) (string, error) {
return lib.createTx(key, "", valueStr, gasStr, gasPriceStr, initStr, bodyStr)
}
func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, initStr, scriptStr string) (string, error) {
var hash []byte
var contractCreation bool
if len(recipient) == 0 {
contractCreation = true
} else {
hash = ethutil.FromHex(recipient)
}
keyPair, err := ethchain.NewKeyPairFromSec([]byte(ethutil.FromHex(key)))
if err != nil {
return "", err
}
value := ethutil.Big(valueStr)
gas := ethutil.Big(gasStr)
gasPrice := ethutil.Big(gasPriceStr)
var tx *ethchain.Transaction
// Compile and assemble the given data
if contractCreation {
initScript, err := Compile(initStr)
if err != nil {
return "", err
}
mainScript, err := Compile(scriptStr)
if err != nil {
return "", err
}
tx = ethchain.NewContractCreationTx(value, gas, gasPrice, mainScript, initScript)
} else {
// Just in case it was submitted as a 0x prefixed string
if initStr[0:2] == "0x" {
initStr = initStr[2:len(initStr)]
}
fmt.Println("DATA:", initStr)
tx = ethchain.NewTransactionMessage(hash, value, gas, gasPrice, ethutil.FromHex(initStr))
}
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
}

View File

@ -1,4 +1,4 @@
package ethui package utils
import ( import (
"encoding/hex" "encoding/hex"
@ -7,53 +7,61 @@ import (
) )
// Block interface exposed to QML // Block interface exposed to QML
type QBlock struct { type PBlock struct {
Number int Number int
Hash string Hash string
} }
// Creates a new QML Block from a chain block // Creates a new QML Block from a chain block
func NewQBlock(block *ethchain.Block) *QBlock { func NewPBlock(block *ethchain.Block) *PBlock {
info := block.BlockInfo() info := block.BlockInfo()
hash := hex.EncodeToString(block.Hash()) hash := hex.EncodeToString(block.Hash())
return &QBlock{Number: int(info.Number), Hash: hash} return &PBlock{Number: int(info.Number), Hash: hash}
} }
type QTx struct { type PTx struct {
Value, Hash, Address string Value, Hash, Address string
Contract bool Contract bool
} }
func NewQTx(tx *ethchain.Transaction) *QTx { func NewPTx(tx *ethchain.Transaction) *PTx {
hash := hex.EncodeToString(tx.Hash()) hash := hex.EncodeToString(tx.Hash())
sender := hex.EncodeToString(tx.Recipient) sender := hex.EncodeToString(tx.Recipient)
isContract := len(tx.Data) > 0 isContract := len(tx.Data) > 0
return &QTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract} return &PTx{Hash: hash, Value: ethutil.CurrencyToString(tx.Value), Address: sender, Contract: isContract}
} }
type QKey struct { type PKey struct {
Address string Address string
PrivateKey string
PublicKey string
} }
type QKeyRing struct { func NewPKey(key *ethchain.KeyPair) *PKey {
return &PKey{ethutil.Hex(key.Address()), ethutil.Hex(key.PrivateKey), ethutil.Hex(key.PublicKey)}
}
/*
type PKeyRing struct {
Keys []interface{} Keys []interface{}
} }
func NewQKeyRing(keys []interface{}) *QKeyRing { func NewPKeyRing(keys []interface{}) *PKeyRing {
return &QKeyRing{Keys: keys} return &PKeyRing{Keys: keys}
} }
*/
type QStateObject struct { type PStateObject struct {
object *ethchain.StateObject object *ethchain.StateObject
} }
func NewQStateObject(object *ethchain.StateObject) *QStateObject { func NewPStateObject(object *ethchain.StateObject) *PStateObject {
return &QStateObject{object: object} return &PStateObject{object: object}
} }
func (c *QStateObject) GetStorage(address string) string { func (c *PStateObject) GetStorage(address string) string {
// Because somehow, even if you return nil to QML it // Because somehow, even if you return nil to QML it
// still has some magical object so we can't rely on // still has some magical object so we can't rely on
// undefined or null at the QML side // undefined or null at the QML side
@ -66,7 +74,7 @@ func (c *QStateObject) GetStorage(address string) string {
return "" return ""
} }
func (c *QStateObject) Value() string { func (c *PStateObject) Value() string {
if c.object != nil { if c.object != nil {
return c.object.Amount.String() return c.object.Amount.String()
} }
@ -74,7 +82,7 @@ func (c *QStateObject) Value() string {
return "" return ""
} }
func (c *QStateObject) Address() string { func (c *PStateObject) Address() string {
if c.object != nil { if c.object != nil {
return ethutil.Hex(c.object.Address()) return ethutil.Hex(c.object.Address())
} }